下载MetaTrader 5
要添加评论,请登录注册
加入MQL5 Cloud Network。数百万交易者们正在等候于此!
LBJ
6
LBJ 2010.12.06 10:27 

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

//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int start()
{
double MA, MA15, MAH4, MAD1;
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) ;
MAD1=iCustom(NULL,PERIOD_D1,"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 ))
{
ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,Ask+TakeProfit*Point,"macd sample",16384,0,Green);
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY order opened : ",OrderOpenPrice());
}
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++)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
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);
}

/
要添加评论,请登录注册