Having the same problem with trying to code a two step stop loss that scans all open orders every tick and modifies them using these rules
Rules:
start with static sl of 25 pips
Rules:
start with static sl of 25 pips
at 5 pips profit move sl to entry price
at 8 pips profit move 4 pips behind 8 pips profit (current price)
Could somebody help? Thank you
Martin_2017: Could anyone please help me?
marth tanaka: Could somebody help?
Help you with what?
You haven't stated a problem, you stated a want.
Show us your attempt
(using CODE button) and state
the nature of your problem.
marth tanaka: Could somebody help?
No free help
urgent help.
whroeder1:
Help you with what? You haven't stated a problem, you stated a want. Show us your attempt (using CODE button) and state the nature of your problem.
No free help
urgent help.
Help you with what? You haven't stated a problem, you stated a want. Show us your attempt (using CODE button) and state the nature of your problem.
No free help
urgent help.
My bad--I just realized that I didnt. So here is my code so far,
//---- input parameters extern double InitialStop = 25; extern double BreakEven = 20; // Profit Lock in pips extern double StepSize = 5; extern double MinDistance = 10; int k, digit=0; bool BE = false; //+------------------------------------------------------------------+ //| expert initialization function | //+------------------------------------------------------------------+ int init() { //---- return(0); } // ---- Stepped Stops void StepStops() { double BuyStop, SellStop; int total=OrdersTotal(); for (int cnt=0;cnt<total;cnt++) { OrderSelect(cnt, SELECT_BY_POS); int mode=OrderType(); if ( OrderSymbol()==Symbol() ) { if ( mode==OP_BUY ) { BuyStop = OrderStopLoss(); if ( Bid-OrderOpenPrice()>0 || OrderStopLoss()==0) { if ( Bid-OrderOpenPrice()>=Point*BreakEven && !BE) {BuyStop = OrderOpenPrice();BE = true;} if (OrderStopLoss()==0) {BuyStop = OrderOpenPrice() - InitialStop * Point; k=1; BE = false;} if ( Bid-OrderOpenPrice()>= k*StepSize*Point) { BuyStop = OrderStopLoss()+ StepSize*Point; if (Bid - BuyStop >= MinDistance*Point) { BuyStop = BuyStop; k=k+1;} else BuyStop = OrderStopLoss(); } //Print( " k=",k ," del=", k*StepSize*Point, " BuyStop=", BuyStop," digit=", digit); OrderModify(OrderTicket(),OrderOpenPrice(), NormalizeDouble(BuyStop, digit), OrderTakeProfit(),0,LightGreen); return(0); } } if ( mode==OP_SELL ) { SellStop = OrderStopLoss(); if ( OrderOpenPrice()-Ask>0 || OrderStopLoss()==0) { if ( OrderOpenPrice()-Ask>=Point*BreakEven && !BE) {SellStop = OrderOpenPrice(); BE = true;} if ( OrderStopLoss()==0 ) { SellStop = OrderOpenPrice() + InitialStop * Point; k=1; BE = false;} if ( OrderOpenPrice()-Ask>=k*StepSize*Point) { SellStop = OrderStopLoss() - StepSize*Point; if (SellStop - Ask >= MinDistance*Point) { SellStop = SellStop; k=k+1;} else SellStop = OrderStopLoss(); } //Print( " k=",k," del=", k*StepSize*Point, " SellStop=",SellStop," digit=", digit); OrderModify(OrderTicket(),OrderOpenPrice(), NormalizeDouble(SellStop, digit), OrderTakeProfit(),0,Yellow); return(0); } } } } } // ---- Scan Trades int ScanTrades() { int total = OrdersTotal(); int numords = 0; for(int cnt=0; cnt<total; cnt++) { OrderSelect(cnt, SELECT_BY_POS); if(OrderSymbol() == Symbol() && OrderType()<=OP_SELL) numords++; } return(numords); } //+------------------------------------------------------------------+ //| expert deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- //---- return(0); } //+------------------------------------------------------------------+ //| expert start function | //+------------------------------------------------------------------+ int start() { digit = MarketInfo(Symbol(),MODE_DIGITS); if (ScanTrades()<1) return(0); else if (BreakEven>0 || InitialStop>0 || StepSize>0) StepStops(); return(0); }//int start //+------------------------------------------------------------------+
I'm trying to modify this to make it do two steps. Using these following rules:
start with static sl of 25 pips
at 5 pips profit move sl to entry price
at 8 pips profit move 4 pips behind 8 pips profit (current price)
I already coded it in to start with a static stop loss of 25 pips. Now I'm just stuck on the last two parts. Thanks. OG code by igor

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hey guys,
I am struggling with coding a trailing stop loss in my EA in MQL5.
Could anyone please help me?
I would be extremely grateful if anyone would code it in my code or give me an MQL5 EA that already has a working trailing stop loss.
Thanks in advance,
Martin