Plot0(
if (Position.MarketPosition != MarketPosition.Flat)
Print("Open PnL: " + Position.GetProfitLoss(Close[0], PerformanceUnit.Points)));
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Plotting unrealized P&L
Collapse
X
-
Plotting unrealized P&L
doesn't plot. How else can I plot unrealized P&L on chart as an indicator? I tried making an indicator, still no luck. I also tried close[0] avg.position price. still no luckCode:Tags: None
-
Hello,
Thank you for the question.
For doing this from an indicator there is no supported way as this is a strategy base variable. the only way to use the code you have provided would be from a strategy.
This would not be able to be plotted directly from the strategy though as the plots are an indicator base item.
Although this is not supported, you can take a look at the code from the @UnrealizedProfitLoss.cs which is in the Documents\NinjaTrader 7\bin\Custom\MarketAnalyzer folder.
This shows the syntax needed to accomplish what you are after.
What needs to happen in an indicator would be you have to loop through the accounts to get the values you are after, this market analyzer column, although laid out slightly different holds the code you would need to use to get this working from an indicator.
I look forward to being of further assistance.
-
guys there has to be an easier way to plot the unrealized P&L. the above is an indicator that plots the dollar move of two instruments... minute by minute. isn't there a way to input Position.AvgPrice in the above code?? How can I access strategy info in an indicator w/o breaking my back lol??Code:double a,b,c; // Use this method for calculating your indicator values. Assign a value to each // plot below by replacing 'Close[0]' with your own formula. a= (((Closes[1][0]-Opens[1][0])/.25)*5); b= (((Closes[0][0]-Opens[0][0])/.25)*12.5); c= a+b; Plot3.Set(c);
Comment
-
Hello,
Thank you for the question.
There is not currently a supported way to access strategy metrics from an indicator as the indicator base does not support these methods and a strategy is a separate instance from an indicator meaning they can not see each other.
Strategies are like a bubble, they contain all the strategy related information for that running instance but can not be accessed from outside.
you could look into using the Strategy Plots example we have in the references section on the forum http://www.ninjatrader.com/support/f...ead.php?t=6651
This shows how to pass values from a strategy to a template indicator, if the strategy is adding the indicator it would have access to the instance, if you add the indicator manually it would not have access.
Please let me know if I may be of additional assistance.
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by argusthome, 03-08-2026, 10:06 AM
|
0 responses
65 views
0 likes
|
Last Post
by argusthome
03-08-2026, 10:06 AM
|
||
|
Started by NabilKhattabi, 03-06-2026, 11:18 AM
|
0 responses
41 views
0 likes
|
Last Post
|
||
|
Started by Deep42, 03-06-2026, 12:28 AM
|
0 responses
23 views
0 likes
|
Last Post
by Deep42
03-06-2026, 12:28 AM
|
||
|
Started by TheRealMorford, 03-05-2026, 06:15 PM
|
0 responses
26 views
0 likes
|
Last Post
|
||
|
Started by Mindset, 02-28-2026, 06:16 AM
|
0 responses
52 views
0 likes
|
Last Post
by Mindset
02-28-2026, 06:16 AM
|

Comment