Is Magic# only constant value when doing sequence of partial take profits via OrderClose() ?

 
at 'How do I close only some lots of an open position, when reaching some pip targets?'
2006.10.10 19:05
You will need to keep track of your order. If you have only 1 trade open you are fine, but generally the only thing that keeps constant when closing parital lot is magic number. What mt does it closes your whole position of 1.0 lot and open a new order for 0.9 lot at the same price so ticket number changes but magic number is copied from old ticket. You don't need to keep track of remaining position since it is in the order itself.
Actually this could be quite simple - just close 0.1 lot whenever profit reaches 20 pips and keep track of your order by magic number.
I was always using ticket# - but now developed function to do sequence of partial take profit closes by taking off for example: oneThird, oneThird, remainderLots, at which time order totally OrderClose()'d.

1. Over one year with new Terminal updates... does above comment about magic# still apply now ?

2. Is this how you would keep track of order(s) in one EA ?

if not... please educate me!

Thanks
 
ukt:

at 'How do I close only some lots of an open position, when reaching some pip targets?'
2006.10.10 19:05
You will need to keep track of your order. If you have only 1 trade open you are fine, but generally the only thing that keeps constant when closing parital lot is magic number. What mt does it closes your whole position of 1.0 lot and open a new order for 0.9 lot at the same price so ticket number changes but magic number is copied from old ticket. You don't need to keep track of remaining position since it is in the order itself.
Actually this could be quite simple - just close 0.1 lot whenever profit reaches 20 pips and keep track of your order by magic number.
I was always using ticket# - but now developed function to do sequence of partial take profit closes by taking off for example: oneThird, oneThird, remainderLots, at which time order totally OrderClose()'d.

1. Over one year with new Terminal updates... does above comment about magic# still apply now ?

2. Is this how you would keep track of order(s) in one EA ?

if not... please educate me!

Thanks

ukt:

Yes, the Magic number still does not change when you modify the order. It can be used to keep track of orders from one EA if you choose it can also be used to differentiate between orders in the same EA, what I mean is if you use two different algorithms or more in the same EA you can assign each algorithm’s trades a different magic number that is an easy way to differentiate between them.

Magic number one way to keep track of orders from the same EA, another way is to keep track of the ticket numbers for the current EA, it’s probably easier to use the magic number though.

Hope this helps.

Hazem Lotfy

 

Thanking you kindly Hazem.

I have taken your comments onboard and following tests - magic is only reliable way and can always do search in tradePool to pickup the ticket number if needed.

What I have actually done is make function: int getTicketNumber( int magic ); which just does OrderSelect() on each TradePool entry until magic==OrderMagicNumber(), at which time returns OrderTicket() to caller. (of course IF unlucky enough to not make match - the function returns EMPTY, and perhaps is better at this stage to abort EA because should not really get this but... caution rules OK, yes?)

I do this immediately following each partial take profit event. Seems that although ticket number is not persistent from original order to final order close (in certain cases), it is required for many of the Terminal's TradingFunctions, so simpler this way and can then just continue using my code base that just loves ticket number!

Since my aim (hahaaa...) is to do minimum of 3 partial take profit OrderClose() calls I finally took time to 'see' that Terminal assigns new ticket number each time to resulting order with volume remainder.

Your reply appreciated Hazem.

Tim

my batting average for getting replies is low - so... is cool to sometimes actually get one!!!

Reason: