OrderSelect function within 60MA EA

 

Gents,

I am having difficulties extracting information using the OrderSelect function. I would like to find out the opening price / lots / sl / tp etc using the functions within MQL and I've been working with the OrderSelect function but just not having any luck...


Could you all give some feedback / advice on my EA?

And I know its not the greatest, but still, got to work with what God gave you and I'm no programmer...

Cheers,

Sebastian

Files:
 
   for (int i=0; i<=OrdersTotal(); i++) {          // for active order get the following innformation
      if (OrderSelect(i, SELECT_BY_POS) == false) {
         Ticket=OrderTicket(); // Number of selected order
         Tip =OrderType(); // Type of selected order
         Price =OrderOpenPrice(); // Price of selected order
         SL =OrderStopLoss(); // SL of selected order
         TP =OrderTakeProfit(); // TP of selected order
         Lot =OrderLots(); // Amount of lots
      }
   }

you are overwriting your vars. So at the end of your for-loop only the last None-FALSE order will be in the vars.


So if there are multiple open orders you should write them to an array.


hth


Russell

--- edit ---

why the while-loop and why are you breaking it without condition? In a quick gasp I'd say you will never reach the code above.

 

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

Why false? The Select has failed in that case.

 

Thanks for the thoughts gents,

The false was a typo, is true normally but I was messing around to see what would happen...

I would really like to only have 1 order open at a time, so then be able to reference using:

if (OrderSelect(0, SELECT_BY_POS) == true) {
Ticket=OrderTicket(); // Number of selected order
Tip =OrderType(); // Type of selected order
Price =OrderOpenPrice(); // Price of selected order
SL =OrderStopLoss(); // SL of selected order
TP =OrderTakeProfit(); // TP of selected order
Lot =OrderLots(); // Amount of lots

If that was active, which I think would work for the first order, but once the next one was open, would it be written to position 0 or 1 (and then so on for 3rd / 4th orders etc)?

Thanks once again!

Sebastian

 

I find using variables to hold ticket values to be redundant and prone to error.

If I want to work with a ticket, I select it.

I then refer to the values in the ticket directly, using OrderStopLoss() OrderTakeProfit() etc as needed.

This preference may change with MQL5's release.

Reason: