#define MAGICMA 2 extern double Lots = 0.1; extern double TakeProfit = 8; extern double TrailingStop = 6; extern double Stoploss = 37; extern double risk = 0.1; //+------------------------------------------------------------------+ //| Calculate open positions | //+------------------------------------------------------------------+ int CalculateCurrentOrders(string symbol) { int buys=0,sells=0; //---- for(int i=0;i0) return(buys); else return(-sells); } //+------------------------------------------------------------------+ //| Check for open order conditions | //+------------------------------------------------------------------+ void CheckForOpen() { int res; double sema,lema,sema1,lema1; sema=iMA(Symbol(),0,2,0,MODE_EMA,PRICE_CLOSE,0); lema=iMA(Symbol(),0,40,0,MODE_EMA,PRICE_CLOSE,0); sema1=iMA(Symbol(),0,2,0,MODE_EMA,PRICE_CLOSE,1); lema1=iMA(Symbol(),0,40,0,MODE_EMA,PRICE_CLOSE,1); //---- sell conditions if (sema>lema && sema1sema1 && lema>lema1) { res=OrderSend(Symbol(),OP_SELL,(MathCeil(AccountBalance() * risk / 12000)/10),Bid,3,Bid+Stoploss*Point,Bid-TakeProfit*Point,"",MAGICMA,0,Red); return; } //---- buy conditions if (semalema1 && sema0) { if(Bid-OrderOpenPrice()>Point*TrailingStop) { if(OrderStopLoss()0) { if((OrderOpenPrice()-Ask)>(Point*TrailingStop)) { if((OrderStopLoss()>(Ask+Point*TrailingStop)) || (OrderStopLoss()==0)) { RefreshRates(); OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,OrderTakeProfit(),0,Red); //return(0); } } } } } } return(0); } // the end. //---- //+------------------------------------------------------------------+ //| Start function | //+------------------------------------------------------------------+ void start() { //---- check for history and trading if(Bars<100 || IsTradeAllowed()==false) return; //---- calculate open orders by current symbol if(CalculateCurrentOrders(Symbol())==0) CheckForOpen(); else CheckForClose(); //---- } //+--------------------------------------------------------------