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 argusthome, 03-08-2026, 10:06 AM
|
0 responses
83 views
0 likes
|
Last Post
by argusthome
03-08-2026, 10:06 AM
|
||
|
Started by NabilKhattabi, 03-06-2026, 11:18 AM
|
0 responses
47 views
0 likes
|
Last Post
|
||
|
Started by Deep42, 03-06-2026, 12:28 AM
|
0 responses
29 views
0 likes
|
Last Post
by Deep42
03-06-2026, 12:28 AM
|
||
|
Started by TheRealMorford, 03-05-2026, 06:15 PM
|
0 responses
32 views
0 likes
|
Last Post
|
||
|
Started by Mindset, 02-28-2026, 06:16 AM
|
0 responses
66 views
0 likes
|
Last Post
by Mindset
02-28-2026, 06:16 AM
|

Comment