OnTick() gives me penultimate profit/loss

Created at 30 Jul 2024, 16:44
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!
ZO

Zocchi

Joined 30.07.2024

OnTick() gives me penultimate profit/loss
30 Jul 2024, 16:44


protected override void OnTick(){

Print(Positions[0].NetProfit.ToString());

}

 

Why do I always get the profit/loss from the penultimate tick and not from the last one?

 

protected override void OnTick(){

 Print(Symbol.Ask.ToString());

}

This gives me the last ask price, as it should be. But why doesn't it work with “netProfit”?


@Zocchi
Replies

PanagiotisCharalampous
31 Jul 2024, 06:20

Hi there,

I assume that the process of updating the net profit succeeds the OnTick event handler.

Best regards,

Panagiotis


@PanagiotisCharalampous

ncel01
31 Jul 2024, 07:40

Hello,

If this is really the case it should be considered a bug, in my opinion.

As expected, the bid/ask prices are updated on the spot, and the same should apply to all the methods/properties that directly depend on these prices, which is the case of NetProfit, among many other.

It's very unlikely that anyone will ever expect something different here.

@PanagiotisCharalampous

Could you please check this with the development team?

Thank you.


@ncel01

Zocchi
31 Jul 2024, 07:55 ( Updated at: 01 Aug 2024, 06:21 )

RE: OnTick() gives me penultimate profit/loss

PanagiotisCharalampous said: 

Hi there,

I assume that the process of updating the net profit succeeds the OnTick event handler.

Best regards,

Panagiotis

Can you perhaps elaborate on this a little?

On the screenshot you can see that it does not work. 

 

I tried this: (https://help.ctrader.com/ctrader-algo/references/EventArgs/TicksTickEventArgs/)

private void Ticks_Tick(TicksTickEventArgs args){

MessageBox.Show(Positions[0].NetProfit.ToString());

}

 

And this: (https://help.ctrader.com/ctrader-algo/references/EventArgs/SymbolTickEventArgs/?h=symboltickeventargs)

private void Ticks_Tick(SymbolTickEventArgs args){

MessageBox.Show(Positions[0].NetProfit.ToString());

}

 

But I always get the profit of the older price...


@Zocchi

PanagiotisCharalampous
01 Aug 2024, 08:01

Hi there,

This behavior will be fixed in an upcoming update.

Best regards,

Panagiotis


@PanagiotisCharalampous