Please Help - How to select order by ticket by using CTrade library

Tanitsak Jirawuttanakit  

I'm trying to get open price from ticket number and I'm using CTrade library to open position. I can open the position with no problem, but I think I cannot select the openned position by the ticket I have. I have tried OrderSelect() function, but it return false with error code 4754 which mean "Order not found". I don't know why.

Below is my code.

#include "cdynamicarray.mqh"

CDynamicArray dynamicArray;

CTrade trade;

int OnInit()
    for(int i=0; i<PositionsTotal(); i++)
         ulong ticket=PositionGetTicket(i);
         double openPrice = OrderGetDouble(ORDER_PRICE_OPEN);
         printf("ticket = " + ticket);
         printf("Open price = " + openPrice);

result in Experts console

From the result, I openned 2 positions manually. You can see that it can get ticket number, but the open price are 0.

Please Help. Appreciate :)

Tanitsak Jirawuttanakit #:
I know the issue already. It was just the misunderstanding of PositionGetTicket() function. When the PositionGetTicket() is execute, it means that the position is automatically selected. There is no need to execute OrderSelect() anymore. I deleted OrderSelect(ticket) from my code and it works. Thank you.

Hi, Jirawuttanakit!

I would like just to thank you. Your doubt, but especially your comment above, helped me a lot to understand what I was doing wrong.

Best regards.