//------------------------------------------------------------------------------ // mx | //------------------------------------------------------------------------------ extern double SL=10; extern double TP=10; extern double TS=5; int MAGIC=12345; double Lots=1.0,diClose0,sMM,fMM; //------------------------------------------------------------------------------ int init() {return(0);} int deinit(){return(0);} //------------------------------------------------------------------------------ int start(){ // diClose0=iClose(NULL,PERIOD_M15,0); fMM=iMA(NULL,PERIOD_M15,5,0,3,2,0); sMM=iMA(NULL,PERIOD_M15,7,0,3,2,0); // if(OrdersTotal()<1){ if(diClose0<sMM){ OrderSend(Symbol(),OP_BUY,Lots,Ask,2,Ask-Point*SL,Ask+Point*TP,"",MAGIC,0,CLR_NONE); } if(fMM<diClose0){ OrderSend(Symbol(),OP_SELL,Lots,Bid,2,Bid+Point*SL,Bid-Point*TP,"",MAGIC,0,CLR_NONE); } } TrailStop(TS); return(0); } //------------------------------------------------------------------------------ void TrailStop(double TS_){ bool OM; int Ticket; double OOP,OTP; int TotalOrders=OrdersTotal(); for(int n=OrdersTotal()-1;n>=0;n--){ if(OrderSelect(n,SELECT_BY_POS,MODE_TRADES)){ OOP=OrderOpenPrice(); OTP=OrderTakeProfit(); if(0<TS_ && OrderSymbol()==Symbol() && OrderMagicNumber()==MAGIC){ if(OrderType()==OP_BUY){ if(Point*TS_ < Bid-OrderOpenPrice()){ if(OrderStopLoss() < Bid-Point*TS_){ OrderModify(OrderTicket(),OOP,Bid-Point*TS_,OTP,0,CLR_NONE); return(0); } } } if(OrderType()==OP_SELL){ if(Point*TS_ < (OrderOpenPrice()-Ask)){ if((Ask+Point*TS_ < OrderStopLoss()) || (OrderStopLoss()==0)){ OrderModify(OrderTicket(),OOP,Ask+Point*TS_,OTP,0,CLR_NONE); return(0); } } } }else{ Print("Error : ",GetLastError()); } } } } //------------------------------------------------------------------------------
Sample
Analysis
Market Information Used:
Series array that contains close prices for each bar
Indicator Curves created:
Indicators Used:
Moving average indicator
Custom Indicators Used:
Order Management characteristics:
Checks for the total of open orders
It automatically opens orders when conditions are reached
It can change open orders parameters, due to possible stepping strategy
Other Features: