PositionOnClosed

Created at 05 Sep 2017, 02:59
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
lec0456's avatar

lec0456

Joined 14.11.2012

PositionOnClosed
05 Sep 2017, 02:59


I am using the PostionOnClosed event to determine when to make the next trade.

 

THe problem I am having is that if I have 2 positions that are set to close at the same price, The positions.count returns zero for both positions that close.  It seems like the positions close asynchronously and the PositionOnClosed event is behind.

 

When backtesting it works perfectly.  This only occurs when live trading.

 

Here is an example of the log, it executes the closed at .203 and .703 millicseconds but Pos Cnt(position count) is zero for both.  One should say position count 1 and the other zero.

04/09/2017 19:55:07.203 | Master cBot V2.8, EURUSD, m15 | Closed: NYSess:-100 @ 09/04/2017 19:55:07.203 Pips: 0.3 MaxPips: 13.5 Profit: 0.48 TradeStart: 1300 Pos Cnt: 0
04/09/2017 19:55:07.703 | Master cBot V2.8, EURUSD, m15 | Closed: HSell1:-102 @ 09/04/2017 19:55:07.703 Pips: 15.7 MaxPips: 0 Profit: 74.88 TradeStart: 1300 Pos Cnt: 0


@lec0456
Replies

lec0456
05 Sep 2017, 03:04

TO duplicate this behavior just put a print statement in the PositionOnclosed Event and set 2 positions to close at the same price. it prints zero for position count for all positions closd at the same price eventhough they are technically closing at different times.


@lec0456

Spotware
05 Sep 2017, 09:12

Dear lec0456,

If you could share your code maybe we could advise of a better way to program the desired functionality. For example, you can maintain your own counter instead of relying on the Positions.Count property.

Best Regards,

cTrader Team


@Spotware

lec0456
07 Sep 2017, 23:54

There is no real code to speak of.  Just a print statment, that shows the counter at zero when positons are closed at the same price. So, you can't have any conditional statements  based on the position.count because it is not accurate.  the PositionOnClosed fires for the first position that is closed and then the second, but not before it is physically closed.  Or so it seems.

I can't count the positions within the PositionsOnClosed event because it will produce the same result.

I guess could add code to maintain my own position count but this seems rather onerous and prone to error.


@lec0456