Detecting if an order is selected

 
#define ERR_NO_ORDER_SELECTED 4105
bool OrderIsSelected() {
        GetLastError();
        OrderTicket();
        return (GetLastError()!=ERR_NO_ORDER_SELECTED );
}

after some trial and error, this seems to work.

if you want to write a function for example called OrderCloseIfProfitable(), you need to somehow determine if the caller previously called OrderSelect with a valid ticket/position index. 

this enables you to do that, with minimum fuss. 

 
if (OrderSelect()==true). OrderSelect is a bool, just select the order you want every-time.
 

retracted

 
jon1:

@uzben

 i think you miss the point. firstly,  if (OrderSelect()==true )  does not compile as it requires parameters. 

i understand fully what OrderSelect(...)  does, i am simply trying to VALIDATE that OrderSelect(...) HAS BEEN CALLED.

when you develop an api that other programmers will use, you need to assume that at some point they will make a mistake, and be able to prevent that mistake having undesired consequences.

 hence a validation mechanism to detect if it has been called is needed.

  • Please edit your post and use SRC button when you post code.
  • If you develop an API, you have to use OrderSelect IN your API, otherwise it's bad design. You can do that implicitely, or explicitely by providing a wrapper function to OrderSelect().
 
angevoyageur:
  • Please edit your post and use SRC button when you post code.
  • If you develop an API, you have to use OrderSelect IN your API, otherwise it's bad design. You can do that implicitely, or explicitely by providing a wrapper function to OrderSelect().


the mq4l api internally does what i was requesting. do they internally have wrappers? no.

i will figure it out, and share my findings with you. 

 
jon1:


the mq4l api internally does what i was requesting. do they internally have wrappers? no.

i will figure it out, and not share my findings with you. 

 

LOL
 
jon1:


the mq4l api internally does what i was requesting. do they internally have wrappers? no.

i will figure it out, and not share my findings with you. 

 


      for(int i = OrdersTotal()-1; i >= 0 ; i--)
        {
         if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false)        break;

your problem how to select an order is solved this simple. It is not needed you share it with  angevoyageur, ubzen or with me

we know how to use loops for selecting trades we have made on our account  

we have several ways to check every trade from our account to select the trade we want to check if we have to manage that trade

... For you jon1  there will never be a selected trade with OrderOpenTime() == 0 

Reason: