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
No announcement yet.
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:
The plot works reliably, but the dollar amount only updates sporadically, sometimes on every bar, but often not for hours. Is there a way to force Draw.TextFixed() to refresh?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
-
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].
- Likes 1
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by NullPointStrategies, Yesterday, 05:17 AM
|
0 responses
54 views
0 likes
|
Last Post
|
||
|
Started by argusthome, 03-08-2026, 10:06 AM
|
0 responses
131 views
0 likes
|
Last Post
by argusthome
03-08-2026, 10:06 AM
|
||
|
Started by NabilKhattabi, 03-06-2026, 11:18 AM
|
0 responses
73 views
0 likes
|
Last Post
|
||
|
Started by Deep42, 03-06-2026, 12:28 AM
|
0 responses
44 views
0 likes
|
Last Post
by Deep42
03-06-2026, 12:28 AM
|
||
|
Started by TheRealMorford, 03-05-2026, 06:15 PM
|
0 responses
49 views
0 likes
|
Last Post
|

Comment