# EA不能测试，请高手修改一下

6
2010.12.06 10:27

extern double Lots = 0.1;
extern double TrailingStop = 21;

//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int start()
{
int cnt, ticket, total;
if(Bars<100)
{
Print("bars less than 100");
return(0);
}
if(TakeProfit<10)
{
Print("TakeProfit less than 10");
return(0);
}
MA=iCustom(NULL,PERIOD_M15,"Moving Average",21,0,0,0,0) ;
MA15=iCustom(NULL,PERIOD_M15,"OsMA",12,26,9,0,0) ;
MAH4=iCustom(NULL,PERIOD_H4,"OsMA",12,26,9,0,0) ;
total=OrdersTotal();
if(total<1)
{
if(AccountFreeMargin()<(1000*Lots))
{
Print("We have no money. Free Margin = ", AccountFreeMargin());
return(0);
}
if((MA15>0 && MAH4>0 &&MAD1>0&& Close[0]<=MA)||(MA15>0 && MAD1>0&& Close[0]<=MA)||(MA15>0 && MAH4>0&& Close[0]<=MA ))
{
if(ticket>0)
{
}
else Print("Error opening BUY order : ",GetLastError());
return(0);
}
if((MA15<0 && MAH4<0 &&MAD1<0&& Close[0]>=MA)||(MA15<0 && MAD1<0&& Close[0]>=MA)||(MA15<0 && MAH4<0&& Close[0]>=MA ))
{
ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,0,Bid-TakeProfit*Point,"macd sample",16384,0,Red);
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("SELL order opened : ",OrderOpenPrice());
}
else Print("Error opening SELL order : ",GetLastError());
return(0);
}
return(0);
}
for(cnt=0;cnt<total;cnt++)
{
if (OrderType() <= OP_SELL && OrderSymbol() == Symbol())
{
if (OrderType() == OP_SELL)
{
if (TrailingStop > 0)
{
if (Bid - MA > Point * TrailingStop)
{
if (OrderStopLoss() < Bid - Point * TrailingStop)
{
OrderModify(OrderTicket(), MA, MA - Point * TrailingStop,OrderTakeProfit(), 0, Green);
return (0);

}
}
}
}
else
{

if (TrailingStop > 0)
{
if ((MA - Ask) > (Point * TrailingStop))
{
if ((OrderStopLoss() > (MA + Point * TrailingStop)))
{
OrderModify(OrderTicket(), MA, MA + Point * TrailingStop,OrderTakeProfit(), 0, Red);
return (0);
}
}
}
}
}
}
return (0);
}