MQL4上如何编写逐步平仓的EA

 

请教个问题,我想写个能逐步平仓的EA,我的EA如下,但是测试后没有办法进行逐步平仓,请问原因在哪里 ,请大家指点

我设置了一个变量 TN,用于选定订单的位置

//+------------------------------------------------------------------+

//| 多空+分批止盈.mq4 |

//| Copyright 2013, MetaQuotes Software Corp. |

//| http://www.metaquotes.net |

//+------------------------------------------------------------------+

#property copyright "Copyright 2013, MetaQuotes Software Corp."

#property link "http://www.metaquotes.net"



//2013-10-17

//指定订单平仓,输入订单编号


extern int TN=1;



//+------------------------------------------------------------------+

//| expert initialization function |

//+------------------------------------------------------------------+

int init()

{

//----

//----

return(0);

}

//+------------------------------------------------------------------+

//| expert deinitialization function |

//+------------------------------------------------------------------+

int deinit()

{

//----

//----

return(0);

}

//+------------------------------------------------------------------+

//| expert start function |

//+------------------------------------------------------------------+

int start()

{

if (OrderSelect(TN,SELECT_BY_POS,MODE_TRADES)==true && OrderType()==OP_BUY && OrderSymbol()==Symbol() && OrderMagicNumber()==10000)

{

if (Bid>=OrderOpenPrice()+490*Point && OrderLots()>=0.9)

{

OrderClose(TN,0.4,Bid,10,CLR_NONE);

}

if(Bid>=OrderOpenPrice()+690*Point && OrderLots()>=0.7)

{

OrderClose(TN,0.2,Bid,10,CLR_NONE);

}

if(Bid>=OrderOpenPrice()+900*Point && OrderLots()>=0.6)//隔20点

{

OrderClose(TN,0.1,Bid,10,CLR_NONE);

}

if(Bid>=OrderOpenPrice()+1390*Point && OrderLots()>=0.5)//隔50点

{

OrderClose(TN,0.1,Bid,10,CLR_NONE);

}

if(Bid>=OrderOpenPrice()+1990*Point && OrderLots()>=0.4)//隔60点

{

OrderClose(TN,0.1,Bid,10,CLR_NONE);

}

if(Bid>=OrderOpenPrice()+2790*Point && OrderLots()>=0.3)//隔80点

{

OrderClose(TN,0.1,Bid,10,CLR_NONE);

}

if(Bid>=OrderOpenPrice()+3790*Point)//隔100点

{

OrderClose(TN,0.1,Bid,10,CLR_NONE);

}

if((TimeCurrent()-OrderOpenTime()>=1000*60*60*24*2) && (Bid-OrderOpenPrice()<=100*Point) && OrderLots()>=0.7)//开单后过两天,平仓手数不超过0.5,价格再次回到开仓价格上方10点

{

OrderClose(TN,0.4,Bid,10,CLR_NONE);

}

}

if (OrderSelect(TN,SELECT_BY_POS,MODE_TRADES)==true && OrderType()==OP_SELL && OrderSymbol()==Symbol() && OrderMagicNumber()==10000)

{

if(Ask<=OrderOpenPrice()-490*Point && OrderLots()>=0.9)

{

OrderClose(TN,0.4,Ask,10,CLR_NONE);

}

if(Ask>=OrderOpenPrice()-690*Point && OrderLots()>=0.7)

{

OrderClose(TN,0.2,Ask,10,CLR_NONE);

}

if(Ask>=OrderOpenPrice()-900*Point && OrderLots()>=0.6)//隔20点

{

OrderClose(TN,0.1,Ask,10,CLR_NONE);

}

if(Ask>=OrderOpenPrice()-1390*Point && OrderLots()>=0.5)//隔50点

{

OrderClose(TN,0.1,Ask,10,CLR_NONE);

}

if(Ask>=OrderOpenPrice()-1990*Point && OrderLots()>=0.4)//隔60点

{

OrderClose(TN,0.1,Ask,10,CLR_NONE);

}

if(Ask>=OrderOpenPrice()-2790*Point && OrderLots()>=0.3)//隔80点

{

OrderClose(TN,0.1,Ask,10,CLR_NONE);

}

if(Ask>=OrderOpenPrice()-3790*Point)//隔100点

{

OrderClose(TN,0.1,Ask,10,CLR_NONE);

}

if((TimeCurrent()-OrderOpenTime()>=1000*60*60*24*2) && (OrderOpenPrice()-Ask<=100*Point) && OrderLots()>=0.7)//开单后过两天,平仓手数不超过0.4,价格再次回到开仓价格上方10点

{

OrderClose(TN,0.4,Ask,10,CLR_NONE);

}

}


return(0);

}

//+------------------------------------------------------------------+

 
现在可以了吗?可以之后告诉我。QQ1109886137