//+------------------------------------------------------------------+ //| //| //| //+------------------------------------------------------------------+ //---- input parameters extern int shortEmaPeriod=5; extern int longEmaPeriod=10; extern double TakeProfit=5.0; extern double Stop=3.0; extern double TrailingStop=4.0; extern double Lots=1; extern double Gap=2; //+------------------------------------------------------------------+ //| expert initialization function | //+------------------------------------------------------------------+ int init() { //---- return(0); } //+------------------------------------------------------------------+ //| expert deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- //---- return(0); } int Crossed (double line1 , double line2) { double point; point=Point; if(Digits==3||Digits==5)point*=10; static int last_direction = 0; static int current_dirction = 0; if(line1>line2+Gap*point)current_dirction = 1; //up if(line1+Gap*point0) { if(Bid-OrderOpenPrice()>point*TrailingStop) { if(OrderStopLoss()0) { if((OrderOpenPrice()-Ask)>(point*TrailingStop)) { if((OrderStopLoss()>(Ask+point*TrailingStop)) || (OrderStopLoss()==0)) { OrderModify(OrderTicket(),OrderOpenPrice(),Ask+point*TrailingStop,OrderTakeProfit(),0,Red); return(0); } } } } } } total = OrdersTotal(); if(total < 1) { if(isCrossed == 1) { ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,Ask+TakeProfit*point,"EMAcross",12345,0,Green); if(ticket>0) {OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES); stops=0.0; if(Stop>0) stops=OrderOpenPrice()-Stop*point; NormalizeDouble(stops,Digits); if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY order opened : ",OrderOpenPrice()); //if(Stop>0)OrderModify(ticket,OrderOpenPrice(),stops,OrderTakeProfit(),0,Red); if (!OrderModify(ticket,OrderOpenPrice(),stops,OrderTakeProfit(),0,Red)) Alert("OrderModify() error - ", (GetLastError())); } else Print("Error opening BUY order : ",GetLastError()); return(0); } if(isCrossed == 2) { ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,0,Bid-TakeProfit*point,"EMAcross",12345,0,Red); if(ticket>0) {OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES); stops=0.0; if(Stop>0) stops=OrderOpenPrice()+Stop*point; NormalizeDouble(stops,Digits); if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("SELL order opened : ",OrderOpenPrice()); //if(Stop>0)OrderModify(ticket,OrderOpenPrice(),stops,OrderTakeProfit(),0,Red); if (!OrderModify(ticket,OrderOpenPrice(),stops,OrderTakeProfit(),0,Red)) Alert("OrderModify() error - ", (GetLastError())); } else Print("Error opening SELL order : ",GetLastError()); return(0); } return(0); } return(0); } //+------------------------------------------------------------------+