If platform Unrealized PnL values are in fact not current liquidation values, I propose a change to make them so.
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Proposed Unrealized PnL Change
Collapse
X
-
Proposed Unrealized PnL Change
I have written "watchdog" code in an unmanaged strategy that compares internal accounting of the quantity long or short, Realized PnL, and Unrealized PnL with values calculated by the NinjaTrader platform to guard against accidentally "winning the lottery" or "losing the farm" if an error causes something wild to happen, such as overfills, unintentional pyramiding, or whatever. That has caused me to realize that platform Unrealized PnL calculations seem to be based on last trading prices rather than current bid or ask prices. Of course, true Unrealized PnL values are current liquidation values, rather values based on previous trading.
If platform Unrealized PnL values are in fact not current liquidation values, I propose a change to make them so.
Tags: None
-
Hello caveat_lector,
Are you using Position.GetUnrealizedProfitLoss(PerformanceUnit unit, [double price])?
Have you supplied the GetCurrentAsk() or GetCurrentBid() to this method and you are finding the last price is used and not the price you have submitted?
https://ninjatrader.com/support/help...profitloss.htm
Position.GetUnrealizedProfitLoss is for the strategy position, not the account.
If you want the account unrealized you will need to use the Account.Get().
Chelsea B.NinjaTrader Customer Service
-
I am using 15-second bars as Primary and the associated tick series as Secondary.
This code is at beginning of OnBarUpdate():
Code:protected override void OnBarUpdate() { if (State == State.Historical) return; if (BarsInProgress == 0) { // Wait until there are enough bars for reliable indicator signals. if (CurrentBars[0] < BarsRequiredToTrade || CurrentBars[1] < BarsRequiredToTrade) return; if (CurrentPosition > 0) UnRealizedPnL = PositionAccount.GetUnrealizedProfitLoss(PerformanceUnit.Currency, GetCurrentBid(1)); else if (CurrentPosition < 0) UnRealizedPnL = PositionAccount.GetUnrealizedProfitLoss(PerformanceUnit.Currency, GetCurrentAsk(1)); else UnRealizedPnL = 0; TotalPnL = RealizedPnL + UnRealizedPnL; if (DisplayCurrentPosition) Draw.TextFixed(this, "CurrentPosition", "CurrentPosition = " + CurrentPosition + " RealizedPnL = " + RealizedPnL.ToString("0.00") + " UnRealizedPnL = " + UnRealizedPnL.ToString("0.00") + " TotalPnL = " + TotalPnL.ToString("0.00"), TextPosition.BottomLeft, ChartControl.Properties.ChartText, ChartControl.Properties.LabelFont, (TotalPnL >= 0)?Brushes.Green:Brushes.Red, Brushes.Transparent, 0);
Code:// This is called whenever the strategy position state changes. protected override void OnPositionUpdate(Cbi.Position position, double averagePrice, int quantity, Cbi.MarketPosition marketPosition) { if (position.MarketPosition == MarketPosition.Long) { CurrentPosition = quantity; } else if (position.MarketPosition == MarketPosition.Short) { CurrentPosition = -quantity; } else { CurrentPosition = 0; UnRealizedPnL = 0; RealizedPnL += SystemPerformance.AllTrades[SystemPerformance.AllTrades.TradesCount-1].ProfitCurrency; } }
Last edited by caveat_lector; 04-09-2020, 10:28 AM.
Comment
-
Hello caveat_lector,
So you are using the ask and bid of the previous bar and not the current snap shot.
Are the ask and bid of the previous bar different than each other?
If yes, does the PositionAccount.GetUnrealizedProfitLoss() return the same value as last for both of these calls?Chelsea B.NinjaTrader Customer Service
Comment
-
The 1 in GetCurrentBid(1) references the Secondary tick series, not the previous bar.
The ask and bid values that I retrieve are different than each other.
Comment
-
No, the dollar values returned by GetUnrealizedProfitLoss() usually differ depending on whether Close[0], GetCurrentBid(1) or GetCurrentAsk(1) is used. Of course, there are occasions where the last 15-second bar close happens to be the same as a current bid or ask price, but usually they are different. If I use Close[0], the UnrealizedPnL value that I display is usually identical to what NinjaTrader shows in its Accounts tab. There are sometimes instantaneous differences that are probably due to processing delay differences, but usually they are identical. However, if I use bid and ask prices the two displayed values are only occasionally identical.
To more specifically answer your question as asked; No, GetUnrealizedProfitLoss() always returns different values if requests based on bid and ask are made consecutively.Last edited by caveat_lector; 04-09-2020, 12:09 PM.
Comment
-
UnrealizedPnL always should be based on bid and ask prices regardless of whether the calculation is for a single custom strategy position or an entire account.
I started this thread in Platform Technical Support, because it looked to me like a platform miscalculation issue, rather than a strategy-related issue.Last edited by caveat_lector; 04-09-2020, 12:32 PM.
Comment
-
Hello caveat_lector,
I was going off post #1 which is specifically mentioning a ninjascript strategy and makes no mention of the control center or the account.
I will move this back to Platform Technical.Last edited by NinjaTrader_ChelseaB; 04-09-2020, 03:09 PM.Chelsea B.NinjaTrader Customer Service
Comment
-
Thanks for checking with the development team and reporting back. That option provides a way to correct the problem. However, it seems to me that the default should be to display PnL values based on current liquidation values with the option being to misleadingly base them on last trade prices. I understand that trading novices may not realize the difference and expect PnL values to be based on last trade prices, but they should be educated rather than provided with a trading system that validates their false assumption.Last edited by caveat_lector; 04-30-2020, 07:46 AM.
Comment
-
Hello caveat_lector,
I've received tracking ID# SFT-4811 for this request have Use last price for PnL unchecked.
As with all feature requests, interest is tracked before implementation is considered, so we cannot offer an ETA or promise of fulfillment. If implemented, it will be noted in the Release Notes page of the Help Guide.
Release Notes — https://ninjatrader.com/support/help...ease_notes.htmChelsea B.NinjaTrader Customer Service
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by algospoke, Today, 06:40 PM
|
0 responses
4 views
0 likes
|
Last Post
by algospoke
Today, 06:40 PM
|
||
Started by maybeimnotrader, Today, 05:46 PM
|
0 responses
7 views
0 likes
|
Last Post Today, 05:46 PM | ||
Started by quantismo, Today, 05:13 PM
|
0 responses
6 views
0 likes
|
Last Post
by quantismo
Today, 05:13 PM
|
||
Started by AttiM, 02-14-2024, 05:20 PM
|
8 responses
168 views
0 likes
|
Last Post
by jeronymite
Today, 05:00 PM
|
||
Started by cre8able, Today, 04:22 PM
|
0 responses
9 views
0 likes
|
Last Post
by cre8able
Today, 04:22 PM
|
Comment