#define MAGICMA 20131111 input double Lots =0.1; input double MaximumRisk =0.02; double TakeProfit1; double TakeProfit2; double StopLoss; double Spread; //+------------------------------------------------------------------+ //| Calculate open positions | //+------------------------------------------------------------------+ int CalculateCurrentOrders(string symbol) { int buys=0,sells=0; //--- for(int i=0;i0) return(buys); else return(-sells); } //+------------------------------------------------------------------+ //| Calculate optimal lot size | //+------------------------------------------------------------------+ double LotsOptimized() { double lot=Lots; lot=NormalizeDouble(AccountFreeMargin()*MaximumRisk/1000.0,1); if(lot<0.1) lot=0.1; return(lot); } void OnTick() { //if(IsTradeAllowed()==false || Volume[0]>1) //return; if(CalculateCurrentOrders(Symbol())==0)CheckForOpen(); else ManageOrder(); } void CheckForOpen() { TakeProfit1 = iCustom(NULL,1440,"Harmonic EA Indicator",3,0); TakeProfit2 = iCustom(NULL,1440,"Harmonic EA Indicator",4,0); StopLoss = iCustom(NULL,1440,"Harmonic EA Indicator",5,0); Spread = Ask - Bid; if(TakeProfit1 != 0 && TakeProfit1 < Bid) //Sell { OrderSend(Symbol(),OP_SELL,LotsOptimized(),Bid,3,StopLoss+Spread,TakeProfit1+Spread,"",MAGICMA,0,Red); return; } if(TakeProfit1 != 0 && TakeProfit1 > Ask) //Buy { double position = LotsOptimized(); OrderSend(Symbol(),OP_BUY,position,Ask,3,StopLoss-Spread,TakeProfit2-Spread,"",MAGICMA,0,Blue); return; } } // Move the stop and take partial profit if first target is reached void ManageOrder() { if(OrderType()==OP_BUY) { if(Bid > TakeProfit1-Spread) { OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice(),TakeProfit2-Spread,3,White); OrderClose(OrderTicket(),OrderLots()/2,Bid,3,White); } } if(OrderType()==OP_SELL) { if(Ask < TakeProfit1+Spread) { OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice(),TakeProfit2+Spread,3,White); OrderClose(OrderTicket(),OrderLots()/2,Bid,3,White); } } }