Position ClosingTime

Created at 21 Apr 2015, 19:06
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

Position ClosingTime
21 Apr 2015, 19:06


Intellisense does not show ClosingTime for the opened.Position or closed.Position objects.  It is available on the history tab of the trade.


@lec0456
Replies

Spotware
24 Jun 2015, 15:55

Dear Trader,

An open position doesn’t have a closing time therefore we do not provide ClosingTime. Once the position is closed it will be removed from the Positions list. In the History tab it is available because it shows the time that a position was closed. The following code snippet shows how to retrieve the closing time of a closed position, which is considered a historical trade:

            ExecuteMarketOrder(TradeType.Buy, Symbol, 10000, "mylabel");

            ClosePosition(Positions.Find("mylabel"));

            HistoricalTrade hist = History.FindLast("mylabel");

            Print("Position closed at: ", hist.ClosingTime.ToString());

We hope this helps you.


@Spotware

c.ostmo
06 Apr 2017, 15:51

RE:

I keep getting this error: Crashed in OnTick with NullReferenceException: Object reference not set to an instance of an object. My question for reference: /forum/cbot-support/11446

Am I missing something? My code is similar to yours and I even replaced it, but I'm getting the same error. What commonly causes this?

 

Spotware said:

Dear Trader,

An open position doesn’t have a closing time therefore we do not provide ClosingTime. Once the position is closed it will be removed from the Positions list. In the History tab it is available because it shows the time that a position was closed. The following code snippet shows how to retrieve the closing time of a closed position, which is considered a historical trade:

            ExecuteMarketOrder(TradeType.Buy, Symbol, 10000, "mylabel");

            ClosePosition(Positions.Find("mylabel"));

            HistoricalTrade hist = History.FindLast("mylabel");

            Print("Position closed at: ", hist.ClosingTime.ToString());

We hope this helps you.

 


@c.ostmo

kricka
07 Apr 2017, 22:34

Rearrange your code

Try to rearrange your code within "OnTick()" if that is where your code is located that causes the specific error. Sometimes by moving a code to another section of the execution script will help to solve a problem like this.


@kricka