近期想把一个指标做成EA,看看效果如何,但是运行好好的指标变成EA后,测试智能交易系统时,只开一次buy单,就再也不下单,也不平仓了。找不出原因来,卡壳好些天了。各位老大们给看看错在哪里。
extern double TakeProfit = 50;
extern double Lots = 0.1;
int cnt, ticket, total,lastnumber;
datetime lastopentime=0;
int i=1,Mark=0;
extern int s=20; //ATR指标的周期数
extern double n=4; //ATR指标的系数
double Zhu[],Fu[];
double Mid;
int Limit,Shift;
int start()
{
int counted_bars=IndicatorCounted();
Limit=Bars-counted_bars;
if(i=0;Shift--)
{
if(Mark==0)
{
if(High[Shift]>High[Bars-1])
{
Mark=1;
Zhu[Shift]=High[Shift];
Fu[Shift]=High[Shift]-Mid;
}
if(Low[Shift]Zhu[Shift+1])
{
Zhu[Shift]=High[Shift];
Fu[Shift]=High[Shift]-Mid;
}
else if((Low[Shift])lastopentime)
{
closebuy();
lastnumber=sell(1,0,0,Symbol()+\"sell\",0);
if(lastnumber>0)
{
if(OrderSelect(lastnumber,SELECT_BY_TICKET,MODE_TRADES)==true)
{
lastopentime=OrderOpenTime();
}
}
}
}
else
{
Zhu[Shift]=Zhu[Shift+1];
Fu[Shift]=Zhu[Shift+1]-Mid;
}
}
else if(Mark==-1)
{
if(Low[Shift]Mid)
{
Zhu[Shift]=High[Shift];
Fu[Shift]=High[Shift]-Mid;
Mark=1;
if(iTime(Symbol(),0,Shift)>lastopentime)
{
lastnumber=buy(1,0,0,Symbol()+\"buy\",0);
if(lastnumber>0)
{
closesell();
if(OrderSelect(lastnumber,SELECT_BY_TICKET,MODE_TRADES)==true)
{
lastopentime=OrderOpenTime();
}
}
}
}
else
{
Zhu[Shift]=Zhu[Shift+1];
Fu[Shift]=Zhu[Shift+1]+Mid;
}
}
}
return(0);
}
int buy(double Lots,double sun,double ying,string comment,int magic)
{
int kaiguan=0;
for(int i=0;i0)
{
if(OrderSelect(ticket, SELECT_BY_TICKET)==true)
{
if((sun!=0)&&(ying!=0))
{
OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()-sun*MarketInfo(Symbol(),MODE_POINT),OrderOpenPrice()+ying*MarketInfo(Symbol(),MODE_POINT),0,Red);
}
if((sun==0)&&(ying!=0))
{
OrderModify(OrderTicket(),OrderOpenPrice(),0,OrderOpenPrice()+ying*MarketInfo(Symbol(),MODE_POINT),0,Red);
}
if((sun!=0)&&(ying==0))
{
OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()-sun*MarketInfo(Symbol(),MODE_POINT),0,0,Red);
}
}
}
return(ticket);
}
else
{
return(0);
}
}
int sell(double Lots,double sun,double ying,string comment,int magic)
{
int kaiguan=0;
for(int i=0;i0)
{
if(OrderSelect(ticket, SELECT_BY_TICKET)==true)
{
if((sun!=0)&&(ying!=0))
{
OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()+sun*MarketInfo(Symbol(),MODE_POINT),OrderOpenPrice()-ying*MarketInfo(Symbol(),MODE_POINT),0,Red);
}
if((sun==0)&&(ying!=0))
{
OrderModify(OrderTicket(),OrderOpenPrice(),0,OrderOpenPrice()-ying*MarketInfo(Symbol(),MODE_POINT),0,Red);
}
if((sun!=0)&&(ying==0))
{
OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()+sun*MarketInfo(Symbol(),MODE_POINT),0,0,Red);
}
}
}
return(ticket);
}
else
{
return(0);
}
}
void closebuy()
{
for(int i=0;i |