currentPnL = Position.GetUnrealizedProfitLoss(PerformanceUnit.Currency, Close[0]); // Get the unrealzied PnL
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Position.GetUnrealizedProfitLoss Lag
Collapse
X
-
Position.GetUnrealizedProfitLoss Lag
I am testing some function of a strategy and I noticed that the result from the Position.GetUnrealizedProfitLoss method is inaccurate and has an extreme lag when compared to the results viable on the chart. I have set up a timer to print the current PnL every 3 seconds. You can see see it is displaying the wrong PnL I originally thought it was because of the stick spread but the tick spread is only 1, I am using the simulated data
Code:
Tags: None
-
Hello cutzpr,
Thanks for your post.
Close[0] references the close price of the bar the script is processing. If you are calculating OnBarClose, this will be up to date with the close value of the bar that had just closed. Close[0] will update with the close price of the developing bar value if you are using Calculate.OnEachTick, or OnPriceChange.
If you are using a timer which then references Close[0], I suggest using TriggerCustomEvent to ensure the BarsAgo reference will be accurate.
TriggerCustomEvent - https://ninjatrader.com/support/help...ustomevent.htm
You could also consider having UnrealizedPnL calculated from the last tick seen in OnMarketData. I've included a snippet below.
We look forward to assisting.Code:protected override void OnMarketData(MarketDataEventArgs marketDataUpdate) { if (marketDataUpdate.MarketDataType == MarketDataType.Last) Print(Position.GetUnrealizedProfitLoss(PerformanceUnit.Currency, marketDataUpdate.Price)); } protected override void OnBarUpdate() { if (State == State.Historical) return; EnterLong(); }
- Likes 1
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Hwop38, 05-04-2026, 07:02 PM
|
0 responses
174 views
0 likes
|
Last Post
by Hwop38
05-04-2026, 07:02 PM
|
||
|
Started by CaptainJack, 04-24-2026, 11:07 PM
|
0 responses
329 views
0 likes
|
Last Post
by CaptainJack
04-24-2026, 11:07 PM
|
||
|
Started by Mindset, 04-21-2026, 06:46 AM
|
0 responses
252 views
0 likes
|
Last Post
by Mindset
04-21-2026, 06:46 AM
|
||
|
Started by M4ndoo, 04-20-2026, 05:21 PM
|
0 responses
356 views
0 likes
|
Last Post
by M4ndoo
04-20-2026, 05:21 PM
|
||
|
Started by M4ndoo, 04-19-2026, 05:54 PM
|
0 responses
183 views
0 likes
|
Last Post
by M4ndoo
04-19-2026, 05:54 PM
|

Comment