protected override void Initialize()
{
Add(new Plot(Color.Green, PlotStyle.Line, "LTUp")); // Plot0
Add(new Plot(Color.Magenta, PlotStyle.Line, "LTDn")); // Plot1
Add(new Plot(Color.Magenta, PlotStyle.Line, "LTAvgUp")); // Plot2
Add(new Plot(Color.Green, PlotStyle.Line, "LTAvgDn")); // Plot3
Add(new Plot(Color.Green, PlotStyle.Line, "STUp")); // Plot4
Add(new Plot(Color.Magenta, PlotStyle.Line, "STDn")); // Plot5
Add(new Plot(Color.Magenta, PlotStyle.Line, "STAvgUp")); // Plot6
Add(new Plot(Color.Green, PlotStyle.Line, "STAvgDn")); // Plot7
CalculateOnBarClose = true;
Overlay = true;
PriceTypeSupported = false;
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
if (CurrentBar < 80) return;
Values[0].Set(TSF(0,80)[0]); // LT Up
Values[1].Set(TSF(0,80)[0]); // LT Dn
Values[2].Set(EMA(Values[0],20)[0]); // LT Avg Up
Values[3].Set(EMA(Values[0],20)[0]); // LT Avg Dn
Values[4].Set(TSF(0,20)[0]); // ST Up
Values[5].Set(TSF(0,20)[0]); // ST Dn
Values[6].Set(EMA(Values[4],5)[0]); // ST Avg Up
Values[7].Set(EMA(Values[4],5)[0]); // ST Avg Dn
Plots[0].Min = EMA(Values[0],20)[0]; // Green when above EMA20
Plots[1].Max = EMA(Values[0],20)[0]; // Magenta when below EMA20
Plots[2].Min = TSF(0,80)[0]; // Green when below TSF80
Plots[3].Max = TSF(0,80)[0]; // Magenta when above TSF80
Plots[4].Min = EMA(Values[4],5)[0]; // Green when above EMA5
Plots[5].Max = EMA(Values[4],5)[0]; // Magenta when below EMA5
Plots[6].Min = TSF(0,20)[0]; // Magenta when below TSF20
Plots[7].Max = TSF(0,20)[0]; // Green when above TSF20
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Dynamically changing the plot color
Collapse
X
-
Dynamically changing the plot color
I have 4 plots that I would like to overlay on prices. Two plots are TSFs (one over a 20 period, the other over an 80 period) and the other two are averages of the first two (over a 5 period for the shorter TSF, over a 20 period for the longer TSF). If the TSF is greater than its average, both the TSF and the average should be green, otherwise they should be magenta. As there is apparently no way to determine the plot color for each bar, I have chose an implementation via .Min and .Max of the Plot objects (which required the creation of 8 plots instead of 4). But I can't make it work. Any advice would be appreciated (open to other ways of implementing this as well).
Code:Tags: None
-
trader2be,
You seem like you are trying to do multi-colored plots. Please see this reference sample for how to do them: http://www.ninjatrader-support2.com/...ead.php?t=3227Josh P.NinjaTrader Customer Service
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
603 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
349 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
104 views
0 likes
|
Last Post
by Mindset
02-09-2026, 11:44 AM
|
||
|
Started by Geovanny Suaza, 02-02-2026, 12:30 PM
|
0 responses
560 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
560 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment