what is StrategyPlot(0)? I tried PlotColors[0][0] in strategy, but it only for indicators.
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Change Indicator Plot Color in a Strategy
Collapse
X
-
I tried to do like that, but get this messageOriginally posted by NinjaTrader_Cal View PostAlexstox,
Bertrand was using StrategyPlot(0) as an example for the indicator name.
You would need to call the indicator such as SMA and then use the PlotColors
SMA(14).PlotColors[0][0] = Color.Red;
Error on calling 'OnBarUpdate' method for strategy 'MyStrat/9cfac36bb3a0413a8fd7ab22487c0d3c': Index was outside the bounds of the array.
Even when I add this before change plot
if(CurrentBars[1]>300) ....
Comment
-
You are right.Originally posted by NinjaTrader_Cal View PostAlexstox,
With the CurrentBars[1] I assume you are adding an additional data series to your script correct?
Code:protected override void Initialize() { Add(MyInstrum1,PeriodType.Day,1); Add(MyInstrum2,PeriodType.Day,1); Add(SMA(Closes[2],50)); SMA(Closes[2],50).Panel=3; SMA(Closes[2],50).ScaleJustification=ScaleJustification.Right; Add(SMA(Closes[1],50)); SMA(Closes[1],50).Plots[0].Pen.Color=Color.Red; SMA(Closes[1],50).Panel=3; SMA(Closes[1],50).ScaleJustification=ScaleJustification.Right; ............................................ protected override void OnBarUpdate() { // Checks to ensure all Bars objects contain enough bars before beginning if (CurrentBars[0] <= ATR_big_per || CurrentBars[1] <= BarsRequired || CurrentBars[2] <= BarsRequired) return; ...................................... SMA1=SMA(Closes[1],50); SMA2=SMA(Closes[2],50); if (SMA2>0 && SMA2>SMA1) { if(CurrentBars[2]>300) SMA2.PlotColors[2][0]=Color.Green; } else if (SMA1>0 && SMA1>SMA2) { if(CurrentBars[1]>300) SMA1.PlotColors[1][0]=Color.Green; } else return;
Comment
-
Changed to .PlotColors[0][0]=Color.Green;Originally posted by NinjaTrader_Bertrand View Postalexstox, looks to me like you try to access a non present plot index for your PlotColors call, the SMA's would actually only hold one plot per instance, right? So that plot to change would always be at index 0.
Color of indicator didn't change
Comment
-
Originally posted by NinjaTrader_Cal View PostAlexstox,
Can you please repost your adjusted script so I can see what you have changed?Code:protected override void Initialize() { Add(MyInstrum1,PeriodType.Day,1); Add(MyInstrum2,PeriodType.Day,1); Add(SMA(Closes[2],50)); SMA(Closes[2],50).Panel=3; SMA(Closes[2],50).ScaleJustification=ScaleJustification.Right; Add(SMA(Closes[1],50)); SMA(Closes[1],50).Plots[0].Pen.Color=Color.Red; SMA(Closes[1],50).Panel=3; SMA(Closes[1],50).ScaleJustification=ScaleJustification.Right; ............................................ protected override void OnBarUpdate() { // Checks to ensure all Bars objects contain enough bars before beginning if (CurrentBars[0] <= ATR_big_per || CurrentBars[1] <= BarsRequired || CurrentBars[2] <= BarsRequired) return; ...................................... SMA1=SMA(Closes[1],50); SMA2=SMA(Closes[2],50); if (SMA2>0 && SMA2>SMA1) { if(CurrentBars[2]>300) SMA2.PlotColors[0][0]=Color.Green; } else if (SMA1>0 && SMA1>SMA2) { if(CurrentBars[1]>300) SMA1.PlotColors[0][0]=Color.Green; } else return;
Comment
-
Alexstox,
There are couple things here that need clarification.
First, in the Initialize() you are adding SMA's that are accessing other BarArrays. However, this will not work as you expect, this is because you can't access other added data series in the Initialize() as these have not been cached and built yet, and will default to the primary data series.
Second, Is the SMA1 and SMA2 a SMA variable or double variable?
Your calculations are trying compare a Indicator, SMA, to a double value which you cannot do.Cal H.NinjaTrader Customer Service
Comment
-
I agree with First, I just carry plotting from strategy to indicatorOriginally posted by NinjaTrader_Cal View PostAlexstox,
There are couple things here that need clarification.
First, in the Initialize() you are adding SMA's that are accessing other BarArrays. However, this will not work as you expect, this is because you can't access other added data series in the Initialize() as these have not been cached and built yet, and will default to the primary data series.
Second, Is the SMA1 and SMA2 a SMA variable or double variable?
Your calculations are trying compare a Indicator, SMA, to a double value which you cannot do.
About Second. SMA1 and SMA2 are double variables. What variable should I use instead of long code of indicator? I mean how to declare "indicator" variable? To get short SMA1 instead of long code SMA(bla,bla,bla). This is especially useful in own indicators with lots of inputs.
Comment
-
Here is an example. http://www.ninjatrader.com/support/f...97907#poststopOriginally posted by alexstox View PostI agree with First, I just carry plotting from strategy to indicator
About Second. SMA1 and SMA2 are double variables. What variable should I use instead of long code of indicator? I mean how to declare "indicator" variable? To get short SMA1 instead of long code SMA(bla,bla,bla). This is especially useful in own indicators with lots of inputs.
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by sjsj2732, Yesterday, 04:31 AM
|
0 responses
32 views
0 likes
|
Last Post
by sjsj2732
Yesterday, 04:31 AM
|
||
|
Started by NullPointStrategies, 03-13-2026, 05:17 AM
|
0 responses
286 views
0 likes
|
Last Post
|
||
|
Started by argusthome, 03-08-2026, 10:06 AM
|
0 responses
283 views
0 likes
|
Last Post
by argusthome
03-08-2026, 10:06 AM
|
||
|
Started by NabilKhattabi, 03-06-2026, 11:18 AM
|
0 responses
133 views
1 like
|
Last Post
|
||
|
Started by Deep42, 03-06-2026, 12:28 AM
|
0 responses
91 views
0 likes
|
Last Post
by Deep42
03-06-2026, 12:28 AM
|

Comment