mt4 messes up stops

 
 for(int pos = OrdersTotal() -1; pos >= 0; pos--)
      {//:for 
      OrderSelect(pos,SELECT_BY_POS,MODE_TRADES);
      if(OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber)
         {//:1
         IsTrade++;
      
         if(OrderType() == OP_BUY) 
            {//:2
            
            if(Close[1] > UpperBB || High[1] > UpperBB) BandPierced = true;
            if(BandPierced)
               {
                  if(Low[1] > OrderStopLoss())
                  {
                  ModStop = Low[1];
                  OrderModify(OrderTicket(),OrderOpenPrice(),ModStop,0,0,CLR_NONE);
                  }
                }
                                                                                                                                                           //order 
            }//:2
            
   
            if(OrderType() == OP_SELL)
            {//:1
            
            if(Close[1] < LowerBB || Low[1] < LowerBB) BandPierced = true;
            if(BandPierced)
               {  
                  if(High[1] < OrderStopLoss()) 
                  {
                  ModStop = High[1];
                  OrderModify(OrderTicket(),OrderOpenPrice(),ModStop,0,0,CLR_NONE);
                  }
                }

            
            
         }//:1
         }//: first if statement
      }//:for 
     

Hi everyone - this is the OrderSelect() loop that I am using - the idea behind trade management here is that as soon as the bollinger band has been pierced, the EA moves the stops to the last low, provided it is greater than/less than the current stop.

For some reason, the EA only takes 3 trades(all buys - no sells for some reason), and when it modifies the trade, instead of the low, the journal shows it modified to 1.0000 - any ideas?

 
gulzaar:

Hi everyone - this is the OrderSelect() loop that I am using - the idea behind trade management here is that as soon as the bollinger band has been pierced, the EA moves the stops to the last low, provided it is greater than/less than the current stop.

For some reason, the EA only takes 3 trades(all buys - no sells for some reason), and when it modifies the trade, instead of the low, the journal shows it modified to 1.0000 - any ideas?

Did your OrderSelect work or not ? you MUST test these things . .

Is ModStop an int ?

 
RaptorUK:

Did your OrderSelect work or not ? you MUST test these things . .

Is ModStop an int ?


how do you test if orderselect worked or not?
 
  1. gulzaar:
    how do you test if orderselect worked or not?
        for(int iPos = OrdersTotal()-1; iPos >= 0 ; iPos--) if (
            OrderSelect(iPos, SELECT_BY_POS)                // Only my orders w/
        &&  OrderMagicNumber()  == magic.number             // my magic number
        &&  OrderSymbol()       == Symbol()                 // and my pair.
        ){

  2.             if(Close[1] > UpperBB || High[1] > UpperBB) BandPierced = true;
                if(BandPierced)
    Is BandPierced ever set to false?
                bool BandPierced = Close[1] > UpperBB || High[1] > UpperBB;
                if(BandPierced) ...
    Why are you looking at the close. If the close is above, then so is the high - always.

  3. Always test return codes
    //OrderModify(OrderTicket(),OrderOpenPrice(),ModStop,0,0,CLR_NONE);
    if (!OrderModify(OrderTicket(),OrderOpenPrice(),ModStop,0,0,CLR_NONE))
        Alert("OrderModify failed: ", GetLastError());
 
gulzaar:

how do you test if orderselect worked or not?
It returns a bool . . . if it works it returns true, if it doesn't work it returns false