Expert Placing one pair stoploss on other pair. - page 3

 
William Roeder:

Print the chart symbol along with the ticket number, and you will find it's being modified somewhere else.

I tried and it’s correct. Problem is like that for instance AUDUSD places a sl on USDJPY chart 
 
You keep saying that but offer no proof. Your posted code can't do it because you are filtering by symbol.
 
William Roeder:
You keep saying that but offer no proof. Your posted code can't do it because you are filtering by symbol.

I'm sorry Mr. Roeder i didn't mean to disappoint you. Here's proof that this Dow Jones trade inherited stop loss from a previously opened USDJPY position.




 
That images shows nothing but a SL of 107 was set on some order on some symbol. Means nothing; a missing times Point might do that.
 
William Roeder:
That images shows nothing but a SL of 107 was set on some order on some symbol. Means nothing; a missing times Point might do that.
I have specified the point value on an external variable to be sure not coming accross this kind of issue so I guarantee it’s not that. As soon as i’ll open a new position I’ll make a screen record of the expert placing the wrong SL. 
 
Antonio Bartolucci:

William Roeder, you might be my savior, so I edited the code in order to make it counting down. It now looks like this! Thanks for your precious help. 

Your program syntax on OrderModify is incorrect.

Not Ask or Bid, but OrderOpenPrice().

// if(!OrderModify(OrderTicket(),Bid,BBMid-StopLevel*PointValue,OrderTakeProfit(),0,clrGreen)) ???

// MQL4 Reference  /  Trade Functions / OrderModify 
void OnStart() 
  { 
   int TrailingStop=50; 
//--- modifies Stop Loss price for buy order №12345 
   if(TrailingStop>0) 
     { 
      OrderSelect(12345,SELECT_BY_TICKET); 
      if(Bid-OrderOpenPrice()>Point*TrailingStop) 
        { 
         if(OrderStopLoss()<Bid-Point*TrailingStop) 
           { 
            bool res=OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Bid-Point*TrailingStop,Digits),OrderTakeProfit(),0,Blue); 
            if(!res) 
               Print("Error in OrderModify. Error code=",GetLastError()); 
            else 
               Print("Order modified successfully."); 
           } 
        } 
     } 
  }
 
Roberto Jacobs:

Your program syntax on OrderModify is incorrect.

Not Ask or Bid, but OrderOpenPrice().

Tried this one as well, but same result. Thanks anyway for the answer Mr. Roberto. 
 
Antonio Bartolucci:
Tried this one as well, but same result. Thanks anyway for the answer Mr. Roberto. 

Try checking your function TrailingStopAdvanceSell() / TrailingStopAdvanceBuy(), if it is correct.

 
  1. Since the modify used Ask, that line will always fail except for the current chart.
  2.  for(int i=OrdersTotal()-1; i>=0; --i) 
       if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)&& OrderMagicNumber() == MIDBMAGICMA && OrderSymbol() == _Symbol){
                if(TrailingStopAdvanceSell() == false)
    The OrderSelect loop doesn't select a type. TSAS wouldn't have its own OrderSelect in it by chance? Thus modifying the wrong order.
 
William Roeder:
  1. Since the modify used Ask, that line will always fail except for the current chart.
  2. The OrderSelect loop doesn't select a type. TSAS wouldn't have its own OrderSelect in it by chance? Thus modifying the wrong order.
bool TrailingStopAdvanceSell()

  {





   for(int i=0; i<OrdersTotal(); i++)

     {

      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false)

         break;

      if((OrderMagicNumber()!=MIDBMAGICMA || OrderMagicNumber() != FCMAGICMA) || OrderSymbol()!=Symbol())

         continue;



      if(OrderType() == OP_SELL)

        {



         double New_TSL_Sell = Ask + TrailingStart *PointValue;

         if(New_TSL_Sell < MathMin(OrderOpenPrice(), OrderStopLoss() - PointValue))

            if(!OrderModify(OrderTicket(),OrderOpenPrice(),New_TSL_Sell,OrderTakeProfit(),0,clrAliceBlue))

              {

               Print("Unable to modify, error code:", GetLastError());

               return(false);

              }

            else

               return(true);

        }

     }

  }

So this is my trailing stop function (TSAS as you called it). As you can see it has its own OrderSelect() loop. I made this as a bool in order to not let the other modifying functions alter the orders if the TrailingStopFunction has worked. What seems to be happening is that when the EA is unable to place the SL on a chart, it places the same SL on another chart, ignoring the screening conditions by Symbol and Magic Number. 

And this seems happening even if each symbol has its own MAGICNUMBER, edited ad hoc with an extern int. 

Documentation on MQL5: Constants, Enumerations and Structures / Named Constants / Predefined Macro Substitutions
Documentation on MQL5: Constants, Enumerations and Structures / Named Constants / Predefined Macro Substitutions
  • www.mql5.com
//| Expert initialization function                                   | //| Expert deinitialization function                                 | //| Expert tick function                                             | //| test1                                                            |...