//+------------------------------------------------------------------+
//| Designed by OKwh, China |
//| Copyright 2006, OKwh |
//| |
//+------------------------------------------------------------------+
#property copyright "Copyright 2006, OKwh "
#property link ""
#define MAGICMA 200610011231
//+------------------------------------------------------------------+
//| 注意没有指标文件那些property |
//+------------------------------------------------------------------+
extern int whichmethod = 1; //1~4 种下单方式
extern double TakeProfit = 100;
extern double StopLoss = 20;
extern double MaximumRisk = 0.3;
extern double TrailingStop =25;
extern int maxOpen = 3; //最多持仓限制
extern int maxLots = 5; //最多单仓限制
extern int bb = 0; //非零就跟踪止赢
extern double MATrendPeriod=26;//使用26均线
int i, p2, xxx,p1, res;
double Lots;
datetime lasttime;
int init() //初始化
{
Lots = 1;
lasttime = NULL;
return(0);
}
int deinit() { return(0); } //反初始化
//主程序
int start()
{
CheckForOpen();
if (bb>0) CTP(); //跟踪止赢
return(0);
}
//+------下面是各子程序--------------------------------------------+
double LotsOptimized() //确定下单量,开仓调用
{
double lot=Lots;
int orders=HistoryTotal(); // history orders total
int losses=0; // number of losses orders without a break
//MarketInfo(Symbol(),MODE_MINLOT);
//MarketInfo(Symbol(),MODE_MAXLOT);
//MarketInfo(Symbol(),MODE_LOTSTEP);
lot=NormalizeDouble(MaximumRisk * AccountBalance()/AccountLeverage(),1);
if(lot<0.1) lot=0.1;
if(lot>maxLots) lot=maxLots;
return(lot);
}
//平仓持有的买单
void CloseBuy()
{
if (OrdersTotal( ) > 0 )
{
for(i=OrdersTotal()-1;i<0;i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
if(OrderType()==OP_BUY)
{
OrderClose(OrderTicket(),OrderLots(),Bid,3,White);
Sleep(5000);
}
}
}
}
//平仓持有的卖单
void CloseSell()
{
if (OrdersTotal( ) > 0 )
{
for(i=OrdersTotal()-1;i<0;i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
if(OrderType()==OP_SELL)
{
OrderClose(OrderTicket(),OrderLots(),Ask,3,White);
Sleep(5000);
}
}
}
}
//判断是否买或卖或平仓
int buyorsell() //在这个函数计算设置你的交易信号
{
double MacdCurrent, MacdPrevious, SignalCurrent;
double SignalPrevious, MaCurrent, MaPrevious;
MacdCurrent=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,0);
MacdPrevious=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,1);
SignalCurrent=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,0);
SignalPrevious=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,1);
MaCurrent=iMA(NULL,0,MATrendPeriod,0,MODE_EMA,PRICE_CLOSE,0);
MaPrevious=iMA(NULL,0,MATrendPeriod,0,MODE_EMA,PRICE_CLOSE,1);
if(MacdCurrent<0 && MacdCurrent>SignalCurrent && MacdPrevious<SignalPrevious
&& MaCurrent>MaPrevious)
return (1); // 买 Ma在上升,Macd在0线上,并且两线上交叉
if(MacdCurrent>0 && MacdCurrent<SignalCurrent && MacdPrevious>SignalPrevious
&& MaCurrent<MaPrevious)
return (-1); // 卖
return (0); //不交易
}
int nowbuyorsell = 0;
void CheckForOpen()
//| Designed by OKwh, China |
//| Copyright 2006, OKwh |
//| |
//+------------------------------------------------------------------+
#property copyright "Copyright 2006, OKwh "
#property link ""
#define MAGICMA 200610011231
//+------------------------------------------------------------------+
//| 注意没有指标文件那些property |
//+------------------------------------------------------------------+
extern int whichmethod = 1; //1~4 种下单方式
extern double TakeProfit = 100;
extern double StopLoss = 20;
extern double MaximumRisk = 0.3;
extern double TrailingStop =25;
extern int maxOpen = 3; //最多持仓限制
extern int maxLots = 5; //最多单仓限制
extern int bb = 0; //非零就跟踪止赢
extern double MATrendPeriod=26;//使用26均线
int i, p2, xxx,p1, res;
double Lots;
datetime lasttime;
int init() //初始化
{
Lots = 1;
lasttime = NULL;
return(0);
}
int deinit() { return(0); } //反初始化
//主程序
int start()
{
CheckForOpen();
if (bb>0) CTP(); //跟踪止赢
return(0);
}
//+------下面是各子程序--------------------------------------------+
double LotsOptimized() //确定下单量,开仓调用
{
double lot=Lots;
int orders=HistoryTotal(); // history orders total
int losses=0; // number of losses orders without a break
//MarketInfo(Symbol(),MODE_MINLOT);
//MarketInfo(Symbol(),MODE_MAXLOT);
//MarketInfo(Symbol(),MODE_LOTSTEP);
lot=NormalizeDouble(MaximumRisk * AccountBalance()/AccountLeverage(),1);
if(lot<0.1) lot=0.1;
if(lot>maxLots) lot=maxLots;
return(lot);
}
//平仓持有的买单
void CloseBuy()
{
if (OrdersTotal( ) > 0 )
{
for(i=OrdersTotal()-1;i<0;i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
if(OrderType()==OP_BUY)
{
OrderClose(OrderTicket(),OrderLots(),Bid,3,White);
Sleep(5000);
}
}
}
}
//平仓持有的卖单
void CloseSell()
{
if (OrdersTotal( ) > 0 )
{
for(i=OrdersTotal()-1;i<0;i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
if(OrderType()==OP_SELL)
{
OrderClose(OrderTicket(),OrderLots(),Ask,3,White);
Sleep(5000);
}
}
}
}
//判断是否买或卖或平仓
int buyorsell() //在这个函数计算设置你的交易信号
{
double MacdCurrent, MacdPrevious, SignalCurrent;
double SignalPrevious, MaCurrent, MaPrevious;
MacdCurrent=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,0);
MacdPrevious=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,1);
SignalCurrent=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,0);
SignalPrevious=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,1);
MaCurrent=iMA(NULL,0,MATrendPeriod,0,MODE_EMA,PRICE_CLOSE,0);
MaPrevious=iMA(NULL,0,MATrendPeriod,0,MODE_EMA,PRICE_CLOSE,1);
if(MacdCurrent<0 && MacdCurrent>SignalCurrent && MacdPrevious<SignalPrevious
&& MaCurrent>MaPrevious)
return (1); // 买 Ma在上升,Macd在0线上,并且两线上交叉
if(MacdCurrent>0 && MacdCurrent<SignalCurrent && MacdPrevious>SignalPrevious
&& MaCurrent<MaPrevious)
return (-1); // 卖
return (0); //不交易
}
int nowbuyorsell = 0;
void CheckForOpen()
|
[ |










