//+------------------------------------------------------------------+ //| IPADXEMA.mq4 | //| Copyright ? 2006, Jargall | //| | //+------------------------------------------------------------------+ extern double Lots = 0.1; extern double ADXperiod = 14; extern double MATrendPeriod=20; extern double RErate = 2; //REward:risk rate //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ int start() { int cnt, ticket, total; double myADX, MaCurrent, MaLast, Rangecurrent; double HighCurrent, LowCurrent; double Highprevious, Lowprevious, Rangelast, Rangeprevious; double Highlast, Lowlast; double MaHistor; // initial data checks // it is important to make sure that the expert works with a normal // chart and the user did not make any mistakes setting external // variables (Lots, StopLoss, TakeProfit, // TrailingStop) in our case, we check TakeProfit // on a chart of less than 100 bars if(Bars<100) { Print("bars less than 100"); return(0); } if(RErate<1) { Print("Reward to Risk (RErate) less than 1:1"); return(0); // check Reward to Risk } // to simplify the coding and speed up access // data are put into internal variables myADX=iADX(NULL,0,ADXperiod,PRICE_CLOSE,MODE_MAIN,0); MaCurrent=iMA(NULL,0,MATrendPeriod,0,MODE_EMA,PRICE_CLOSE,0); MaLast=iMA(NULL,0,MATrendPeriod,0,MODE_EMA,PRICE_CLOSE,1); Rangelast=High[1]-Low[1]; Rangeprevious=High[2]-Low[2]; Highlast=High[1]; Lowlast=Low[1]; Highprevious=High[2]; Lowprevious=Low[2]; MaHistor=iMA(NULL,0,MATrendPeriod,0,MODE_EMA,PRICE_CLOSE,3); total=OrdersTotal(); if(total<1) { // no opened orders identified if(AccountFreeMargin()<(1000*Lots)) { Print("We have no money. Free Margin = ", AccountFreeMargin()); return(0); } // check for long position (BUY) possibility if(myADX>=20 && MaCurrent>MaLast && MaLast>MaHistor && Rangelast=Lowprevious && Highlast<=Highprevious && Bid>High[1] && Hour()>=7 || Hour()<=19)//For some reason the time filter doesn't change report results. { ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Low[1]-(1*Point),Ask+Rangelast*RErate, "IPADX20EMACHECK LONG",16384,TimeMinute(CurTime())+15,Green); //Expiration should be at the end of the current bar. 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); } // check for short position (SELL) possibility if(myADX>=20 && MaCurrent=Lowprevious && Highlast<=Highprevious && Bid=9 || Hour()<=14) { ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,High[1]+(1*Point),Ask-Rangelast*RErate, "IPADX20EMACHECK SHORT",16384,TimeMinute(CurTime())+15,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); } // it is important to enter the market correctly, // but it is more important to exit it correctly... for(cnt=0;cntMaHistor || myADX<20) { OrderClose(OrderTicket(),OrderLots(),Ask,3,Violet); // close position return(0); // exit } // check for trailing stop } } } return(0); } // the end.