//+------------------------------------------------------------------+ //| Grail 9 v03.mq4 | //| Copyright © 2007, MetaQuotes Software Corp. | //| http://www.metaquotes.net | //+------------------------------------------------------------------+ #property copyright "Copyright © 2007, MetaQuotes Software Corp." #property link "http://www.metaquotes.net" double Ma1; double Ma2; double Ma3; double Ma4; double MACDSignal; double MACDMain; double Lots; double Diff; int Ticket; int MaxTickets; int cnt, ticket, total; int TrailingStop = 10; int MagicNumber = 0; //+------------------------------------------------------------------+ //| expert initialization function | //+------------------------------------------------------------------+ int init() { //---- //---- return(0); } //+------------------------------------------------------------------+ //| expert deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- //---- return(0); } //+------------------------------------------------------------------+ //| expert start function | //+------------------------------------------------------------------+ int start() { //---- Ma1 = iMA(NULL, PERIOD_H1, 20, 0, MODE_SMA, PRICE_CLOSE, 0); Ma2 = iMA(NULL, PERIOD_H1, 20, 5, MODE_SMA, PRICE_OPEN, 0); MACDSignal = iMACD(NULL, PERIOD_H1, 12, 26, 9, PRICE_OPEN, MODE_SIGNAL, 0); MACDMain = iMACD(NULL, PERIOD_H1, 12, 26, 9, PRICE_OPEN, MODE_MAIN, 0); Lots = 0.1; MaxTickets = 1; Diff = Lots*Point; //---- //Trail existing Orders int cnt,Total; Total=OrdersTotal(); for(cnt=0;cnt Ma2 && OrderType()==OP_SELL) { OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet); // close position return(0); // exit } } //Entry Conditions if(Ma1>=Ma2 && OrdersTotal()<=MaxTickets && MACDSignal-MACDMain<0 && MACDMain>0) { Strategy(1); } if(Ma1<=Ma2 && OrdersTotal()<=MaxTickets && MACDSignal-MACDMain>0 && MACDMain>0) { Strategy(2); } //---- return(0); } //+------------------------------------------------------------------+ void Strategy(int strat) { if(strat==1) { Ticket = OrderSend(Symbol(),OP_BUY,Lots,Ask,3,10,0,"",0,0,Blue); } if(strat==2) { Ticket = OrderSend(Symbol(),OP_SELL,Lots,Bid,3,10,0,"",0,0,Blue); } } void TrailOrder(int type) { if(TrailingStop>0) { if(OrderMagicNumber() == MagicNumber) { if(type==OP_BUY) { if(Bid-OrderOpenPrice()>Point*TrailingStop) { if(OrderStopLoss()(Point*TrailingStop)) { if((OrderStopLoss()>(Ask+Point*TrailingStop)) || (OrderStopLoss()==0)) { OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,OrderTakeProfit(),0,Red); } } } } } }