breakeven function - page 2

 
//Check position
   bool IsTrade = False;

   for (int i = 0; i < Total; i ++) {
      OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
      if(OrderType() <= OP_SELL &&  OrderSymbol() == Symbol()) {
         IsTrade = True;
         if(OrderType() == OP_BUY) {
            //Close

            //+------------------------------------------------------------------+
            //| Signal Begin(Exit Buy)                                           |
            //+------------------------------------------------------------------+

                     //no exit signal for the moment

            //+------------------------------------------------------------------+
            //| Signal End(Exit Buy)                                             |
            //+------------------------------------------------------------------+

            if (Order == SIGNAL_CLOSEBUY && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {
               OrderClose(OrderTicket(), OrderLots(), Bid, Slippage, MediumSeaGreen);
               if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Bid, Digits) + " Close Buy");
               if (!EachTickMode) BarCount = Bars;
               IsTrade = False;
               continue;
            }
            //Breakeven
            if(BreakEven > 0) {                 
               if ( Bid-OrderOpenPrice()>Point*BreakEven ) 
               {
               double BuyStop = OrderOpenPrice();
               OrderModify(OrderTicket(),OrderOpenPrice(),
                           NormalizeDouble(BuyStop, digit),
                           OrderTakeProfit(),0,Green);
                              return(0);
                              }
                              }
            //the second Stoploss adjustment
            if(SecondSL > 0) {                 
               if ( Bid-OrderOpenPrice()>Point*SecondSL ) 
               {
               int SecondBSLvalue = 20;
               double SBLlvl = OrderOpenPrice()+Point*SecondBSLvalue;
               OrderModify(OrderTicket(),OrderOpenPrice(),
                           NormalizeDouble(SBLlvl, digit),
                           OrderTakeProfit(),0,Green);
                              return(0);
                              }
                              }               
         } else {
            //Close and then follows the same for SELL orders...

After two days of testing around and reading all the tutorials and forum threads there are out there concerning this topic I still haven't found the solution for this problem (the problem being no error msg when compiling or backtesting, breakeven function works but the second SL adjustment doesn't) . I have a few hunches though as to why the second SL modification won't work as I'd like to:

1) the breakeven OrderModify has the same condition as the second SL adjustment (=if (Bid-OrderOpenPrice() > Point*whatever-as-long-as-greater-than-zero)) which means I would have to establish some sort of boolean true-false command that causes the breakeven OrderModify part to be ignored so the second SL adjustment can take place.

2) or it's just a formal thing and I have to add a line that makes sure the new SL is better than the old SL (like here https://www.mql5.com/en/forum/126304) in order to make things work

3) or it's something completely different... and I'm at a loss.

In any case, help would be greately appreciated.

Files:
trainingea.mq4  11 kb
 
Found the solution already :) It was 2) from above, there has to be a check whether the current SL is smaller than the potential new SL before the modifying line. Reinventing the wheel has its pedagogical benefits, I guess.