Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Issue with my indicator not updating/refreshing properly.
Collapse
X
-
Issue with my indicator not updating/refreshing properly.
I have an indicator that I wrote where the candles change colors when an MA is crossed. However, when the criteria is no longer met, it doesn't change back to the original color preset by the chart settings. I have to refresh the chart to get the candles update. Is there a piece of code I can add to my indicator so that it auto refreshes when the criteria is no longer met? Example. Price is below the 9 sma. It's crosses up above it and turns green. However, before the candle closes, it drops back below the 9 sma, it closes below the 9 sma, but stays green. It doesn't go back to the color it was originally. How do I fix it so that it changes on the fly?Tags: None
-
Hello jamestrader21x,
Thank you for your post.
I note that you had posted a similar thread in the NT7 forum as well - just to confirm, is this script for NinjaTrader 7, NinjaTrader 8 or both?
Is the indicator updating OnBarClose, OnPriceChange, or OnEachTick?
Would you be able to provide a snippet of your current logic for changing the color?
Thanks in advance; I look forward to assisting you further.
-
ninja trader 8
f (State == State.SetDefaults)
{
Description = @"A visual representation of CCI in colored bars.";
Name = "BACABarsEV";
Calculate = Calculate.OnPriceChange;
IsOverlay = true;
DisplayInDataBox = true;
DrawOnPricePanel = true;
DrawHorizontalGridLines = true;
DrawVerticalGridLines = true;
PaintPriceMarkers = true;
ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
//Disable this property if your indicator requires custom values that cumulate with each new market data event.
//See Help Guide for additional information.
IsSuspendedWhileInactive = true;
SMA_Period = 9;
AddPlot(new Stroke(Brushes.Lime, 2), PlotStyle.Bar, "Up_Color");
AddPlot(new Stroke(Brushes.Red, 2), PlotStyle.Bar, "Dn_Color");
}
else if (State == State.Configure)
{
}
}
@
protected override void OnBarUpdate()
{
if (CurrentBar < 1)
return;
if(Close[1] <= SMA(SMA_Period)[1] && Close[0] > SMA(SMA_Period)[0])
{
BarBrush = Brushes.Lime;
}
else if(Close[1] >= SMA(SMA_Period)[1] && Close[0] < SMA(SMA_Period)[0])
{
BarBrush = Brushes.Red;
}
}
Comment
-
-
Hello jamestrader21x,
Thank you for your reply.
Your logic is currently set up so that if the conditions are true, the color of the bar changes, but I'm not seeing any logic for changing back when the conditions are false - this doesn't happen automatically. You'd want to revise your logic so that when the condition is reversed you repaint the bar its original color.
Please let us know if we may be of further assistance to you.
Comment
-
Is there a way to repaint the bar without coding the Close > Open BarBrush = Brushes.White;, Close < Open BarBrush = Brushes.Black, etc? Like if(x < y) {BarBrush = Brushes.default;}
I looked through color list and didn't find anything as far as default color.
Comment
-
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
648 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
369 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
108 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
572 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
574 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment