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

 
You call TSAS which has its own select loop. Once it returns, your modify is now processing a different order.
 
William Roeder:
You call TSAS which has its own select loop. Therefor your modify is now processing a different order.

Ok so how can I tell the EA not to modify orders with a TrailingStop added? And most of all, how can I avoid the EA placing stop losses from a chart to another chart? 

i tried putting this, but will be able to test it on monday: 

{
         if(OrderType() == OP_SELL)
           {
            if(TrailingStopAdvanceSell() == true || OrderStopLoss() < OrderOpenPrice()) break;
            else ...

Here's the list of what have i tried to work-around this error:

- Assigning Ad-Hoc Magic Number to each symbol 

-Counting Orders LIFO instead of FIFO

-Correcting the "Price" parameter in OrderModify functions with "OrderOpenPrice()"

 
You selected an order on the current chart; process it. One loop only.
 
William Roeder:
You selected an order on the current chart; process it. One loop only.

Here's proof of what I'm saying in the log Mr. Roeder, this should make it definitely clear that it might be a source code problem. 


And if I close that position, it will now place the SL on another position like proved in the log. 

 
It definitely is a source code problem; your broken code. What part of "One loop only" was unclear?
   for(int i=OrdersTotal()-1; i>=0; --i)                   One loop
   if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)&& OrderMagicNumber() == MIDBMAGICMA && OrderSymbol() == _Symbol){
      
^^ above you selected an order on the current chart. 

            if(TrailingStopAdvanceSell() == false){        Second loop.

^^ Above function selected other orders.
vv Below tries to test and modify some other order using chart values.

               if(OrderStopLoss() > BBMid .. }
               else{
                  if(!OrderModify(OrderTicket(),Ask
 
William Roeder:
It definitely is a source code problem; your broken code. What part of "One loop only" was unclear?

Ok I had unclear the loop concept, sfortunately I'm kind of new to this. Now i got it precisely.

So to avoid placing the stop loss when the trailing stop is placed i simply called in a simple equation.


This is what the code looks like now. Thanks for your patience Mr. Roeder. 

void CheckForModify()
  {


   double BBHi;
   double BBMid;
   double BBLow;

   BBHi=iBands(Symbol(),Period(),BPeriod,2,0,PRICE_CLOSE,MODE_UPPER,0);
   BBLow=iBands(Symbol(),Period(),BPeriod,2,0,PRICE_CLOSE,MODE_LOWER,0);
   BBMid=iBands(Symbol(),Period(),BPeriod,2,0,PRICE_CLOSE,MODE_MAIN,0);
   int res;







      
   for(int i=OrdersTotal()-1; i>=0; --i) 
   if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES) && (OrderSymbol() == _Symbol && OrderMagicNumber() == MIDBMAGICMA))
      {
         if(OrderStopLoss() != 0 )
            {
               Print("Stop Loss già piazzato a ",OrderStopLoss());
               continue;
            }   
            
         else
            {
               if(OrderType() == OP_SELL)
                  {
                     if(OrderStopLoss() < OrderOpenPrice()) continue;
                     else
                        {
                           if(!OrderModify(OrderTicket(),OrderOpenPrice(),BBMid + StopLevel*PointValue,OrderTakeProfit(),0,clrRed))
                              {
                              
                                 res = OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice() + 20*PointValue + StopLevel*PointValue,OrderTakeProfit(),0,clrRed);
                                 Print("Impossibile piazzare lo stop loss per l'ordine #",OrderTicket(),". Errore #",GetLastError(),". Lo piazzo a ",BBHi,".");
                                 return;
                              
                              }
                           else
                              {
                                 Print("Stop loss piazzato con successo sull'ordine #",OrderTicket(),".");
                                 return;
                              }
                                 
                        }
                  }
               if(OrderType() == OP_BUY)
                  {
                     if(OrderStopLoss() > OrderOpenPrice()) continue;
                     else
                        {
                           if(!OrderModify(OrderTicket(),OrderOpenPrice(),BBMid - StopLevel*PointValue,OrderTakeProfit(),0,clrRed))
                              {
                                 res = OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice() - 20*PointValue - StopLevel*PointValue,OrderTakeProfit(),0,clrRed);
                                 Print("Impossibile piazzare lo stop loss per l'ordine #",OrderTicket(),". Errore #",GetLastError(),". Lo piazzo a ",BBLow,".");
                                 return;
                              }
                           else
                              {
                                 Print("Stop loss piazzato con successo sull'ordine #",OrderTicket(),".");
                                 return;
                              }
                        }
                        
                  }
            }                              
      }
                  
            
  else if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES) && (OrderSymbol() == _Symbol && OrderMagicNumber() == FCMAGICMA))
   
         {
         if(OrderStopLoss() != 0 )
            {
               Print("Stop Loss già piazzato a ",OrderStopLoss());
               
            }   
            
         else
            {
               if(OrderType() == OP_SELL)
                  {
                     if(OrderStopLoss() < OrderOpenPrice()) return;
                     else
                        {
                           if(!OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice() + 20*PointValue + StopLevel*PointValue,OrderTakeProfit(),0,clrRed))
                              {
                              
                                 res = OrderModify(OrderTicket(),OrderOpenPrice(),BBHi + StopLevel*PointValue,OrderTakeProfit(),0,clrRed);
                                 Print("Impossibile piazzare lo stop loss per l'ordine #",OrderTicket(),". Errore #",GetLastError(),". Lo piazzo a ",BBHi,".");
                                 return;
                              
                              }
                           else
                              {
                                 Print("Stop loss piazzato con successo sull'ordine #",OrderTicket(),".");
                                 return;
                              }
                                 
                        }
                  }
               if(OrderType() == OP_BUY)
                  {
                     if(OrderStopLoss() > OrderOpenPrice()) return;
                     else
                        {
                           if(!OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice() - 20*PointValue - StopLevel*PointValue,OrderTakeProfit(),0,clrRed))
                              {
                                 res = OrderModify(OrderTicket(),OrderOpenPrice(),BBLow - StopLevel*PointValue,OrderTakeProfit(),0,clrRed);
                                 Print("Impossibile piazzare lo stop loss per l'ordine #",OrderTicket(),". Errore #",GetLastError(),". Lo piazzo a ",BBLow,".");
                                 return;
                              }
                           else
                              {
                                 Print("Stop loss piazzato con successo sull'ordine #",OrderTicket(),".");
                                 return;
                              }
                        }
                        
                  }
            }                              
      }           
            
}