What happens to Position member variable when a position is closed?

Created at 25 Oct 2019, 08:31
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!
FI

firemyst

Joined 26.03.2019

What happens to Position member variable when a position is closed?
25 Oct 2019, 08:31


Hi everyone:

I have a class member variable defined as follows:

private Position _p;

When an order is executed successfully, I do the following:

_p = Positions.Find(_positionLabel, SymbolName);

When the position is closed because of a stoploss being hit, _p isn't set to null.

Isn't _p just a reference to the actual position becaiuse I'm not creating a new object? If so, when the actual position is closed, is that set to null? Or some other value?

I'm asking because elsewhere in my code, I have:

if (_p != null) { //... }

but that is still evaluated to true after the position is closed via stoploss.

So do I need to set _p == null in a positionclosed event handler? Or should _p actually evaulate to null when the associated position is closed via stoploss?

Thank you.


@firemyst
Replies

PanagiotisCharalampous
25 Oct 2019, 08:36

Hi FireMyst,

Yoo should set the position to null after the position is closed.

Best Regards,

Panagiotis


@PanagiotisCharalampous