Position // Order // Deal - Working on deeper understanding - to find out if a pendingorder is deleted od executed

118

Hi

In order to properly find out if my pending order is executed i try to exactly understand how it works:

So i find out I can place a pending order (trade_action_pending) then i get result.deal=0 result.order=12345678

order.result ist the order ticketnumber right? now here comes the first question: will this number  ever change - i asume no.

When i do a deal (trade_action_deal) i get result.deal 87654321 result.order 12345678 this happens because a deal makes

a order first but immediately will be executed to a deal. So the deal-ticket is result.deal right ??

In the History i can see there is status for orders canceled/filed. so i assume this is what i want to know in order to be sure

what happens with my order - is there some OrderGetState() ore something ??

Now there are also Positions with a ticket-number of an order and this is where i lose ground.

and there is also : PositionGetInteger(POSITION_IDENTIFIER)

witch looks like the order-number to me.

So long story short:

1) what are positions

2) is the order-number the Master ID to look up when searching true orders deals and history

thank you :)

118

OK solved the first part of the puzzle:

HistoryOrderSelect(myOrderNr);

Print(HistoryOrderGetInteger(myOrderNr)); //0=Pending 2=Deleted 4=Executed

Now when the Order is executed - how do i get its dealnumber?

PositionSelectByTicket(myOrderNr) and (POSITION_TICKET or POSITION_IDENTIFIER) give me the OrderNumber again

How to get the dealnumber when i know the ordernumber ??

Thanx

6689

The MagicNumber is your reference (the ticket is the reference of the broker). So what if you define specific Magics and search them?
118

Thanks but does not change on my problem:

i place order and i know ordernumber.

OnTrade() i cheque if order is executed, pending or deleted - works fine.

if executed, i would like to fined out if still in market or closed by sl or tp.

i anderstand that i can get order proppertis, but there is no enum for inmarket

ore closed?? and i do not understand how i get access to deals history without

dealnumber witch i do not have at this moment. I do not know where to lookup for.

so the basic question is how to find out if position is still open or closed...

Moderator
31181

Zar88:

Thanks but does not change on my problem:

i place order and i know ordernumber.

OnTrade() i cheque if order is executed, pending or deleted - works fine.

if executed, i would like to fined out if still in market or closed by sl or tp.

i anderstand that i can get order proppertis, but there is no enum for inmarket

ore closed?? and i do not understand how i get access to deals history without

dealnumber witch i do not have at this moment. I do not know where to lookup for.

so the basic question is how to find out if position is still open or closed...

That's 2 different things. You don't need to know about deals if you want to know if a position is still open.

To check if position is still open : you have an order ticket, that will give you a position ticket, then just use PositionSelectByTicket().

To get deals from an order/position, use HistorySelect() or HistorySelectByPosition(), then loop through all deals (from 0 to HistoryDealsTotal()-1) and select the deal(s) you want.