protected override void OnBarUpdate() { if (BarsInProgress != 0 || CurrentBar < 1) return; // Plot cumulative strategy PnL cumProfit = SystemPerformance.AllTrades.TradesPerformance.Currency.CumProfit; if (IncludeUnrealizedPnL) PnL[0] = cumProfit + Position.GetUnrealizedProfitLoss(PerformanceUnit.Currency); else PnL[0] = cumProfit; if (PnL[0] > 0) PlotBrushes[0][0] = Brushes.Green; else if (PnL[0] < 0) PlotBrushes[0][0] = Brushes.Red; else PlotBrushes[0][0] = Brushes.Gray; Draw.TextFixed(this, "PnL", cumProfit.ToString("C"), TextPosition.Center, ChartControl.Properties.ChartText, pnlFont, Brushes.Transparent, Brushes.Transparent, 0); ...
Announcement
Collapse
Looking for a User App or Add-On built by the NinjaTrader community?
Visit NinjaTrader EcoSystem and our free User App Share!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less
Partner 728x90
Collapse
NinjaTrader
Sporadic Draw.TextFixed() Refresh
Collapse
X
-
Sporadic Draw.TextFixed() Refresh
I have the following code in a strategy to plot PnL and display the current dollar amount centered over the plot:
Code:Last edited by caveat_lector; 08-26-2021, 11:24 AM.Tags: None
-
I initially wrote the code using the data series PnL[0] as shown below and had the sporadic dollar-value display problem. I thought that might have been due someway to converting a data series array value to a string and so changed the code to use cumProfit.ToString("C") as posted above.
Code:Draw.TextFixed(this, "PnL", PnL[0].ToString("C"), TextPosition.Center, ChartControl.Properties.ChartText, pnlFont, Brushes.Transparent, Brushes.Transparent, 0)
Both methods have exactly the same sporadic updating end-result.
Comment
-
Hello caveat_lector,
Thanks for your reply.
So the cumProfit variable is only updated when a trade completes. Does that match your observtion?
If not I would suggest adding a print statement and print out the value of cumProfit on each OnBarUpdate() and compare to what is displayed.
Paul H.NinjaTrader Customer Service
Comment
-
The cumProfit variable updates as each trade completes unless IncludeUnrealizedPnL is set true, in which case it updates each time OnBarUpdate() runs with new primary data series data. There is nothing wrong with those aspects, because correct values are plotted and the plot updates on each bar as it should. The cumProfit value is correct. The problem is that Draw.TextFixed only updates the value it displays sporadically.
Comment
-
Hello caveat_lector,
Thanks for your reply.
Your code will not update cumProfit with UnrealizedPNL when selected. Only the series PnL[0] is updated when unrealizedPNL added.
In short the Draw.Text with cumProfit as currently shown will only update as each trade completes.
To verify, please add a print statement that outputs the bar time, cumprofit and Pnl[0].
Paul H.NinjaTrader Customer Service
- Likes 1
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by Tin34, Today, 03:30 AM
|
2 responses
20 views
0 likes
|
Last Post
by Tin34
Today, 04:11 AM
|
||
Started by sastrades, Yesterday, 09:59 AM
|
2 responses
33 views
0 likes
|
Last Post Today, 04:06 AM | ||
Started by ETFVoyageur, Today, 12:52 AM
|
1 response
17 views
0 likes
|
Last Post Today, 03:36 AM | ||
Started by lollers, Today, 03:26 AM
|
0 responses
12 views
0 likes
|
Last Post
by lollers
Today, 03:26 AM
|
||
Started by aliyahany, Today, 03:16 AM
|
0 responses
4 views
0 likes
|
Last Post
by aliyahany
Today, 03:16 AM
|
Comment