Find current order to stop distance for all open trades in my EA

 

I'm sure this has probably been asked and answered before, but I don't seem to be able to find an answer.  If someone could point me in the right direction I'd be most grateful.

I'm trying to have my EA check the distances between all (up to 5) opening trade levels and current trailing stops for each one, and then simply print a comment in the chart.

What's the little piece of code I need for this?  Please?!

Thanks. 

 
jmb:

I'm sure this has probably been asked and answered before, but I don't seem to be able to find an answer.  If someone could point me in the right direction I'd be most grateful.

I'm trying to have my EA check the distances between all (up to 5) opening trade levels and current trailing stops for each one, and then simply print a comment in the chart.

What's the little piece of code I need for this?  Please?!

Thanks. 

You need a loop to loop through all the orders,  then you select the orders in turn and use OrderOpenPrice() to get the opening price and OrderStopLoss() to get each orders SL.
 

Thanks for the speedy reply.  I'd sort of got that far.  Its just the actual coding!  I'm sure it isn't too difficult, but is beyond me yet - for example, selecting orders in turn!  

Thanks again.  I'll keep searching! 

 

If I have understand you right It should be something like this

 
int distance = 0;
 double pos = 0;


 for(int i=OrdersTotal()-1;i>=0;i--)
 {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES) && OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber)
      {
          if(pos > 0) distance = MathAbs(pos - OrderOpenPrice())/Point; 
          pos = OrderOpenPrice();
          Print("Distance is :"+distance);
      }
 }
 

Fantastic!  Thank you so much!  :)

That pointed me in the right direction, and I've now got things working as I wished.  Great! 

Reason: