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
Change Indicator Plot Color in a Strategy
Collapse
X
-
Originally 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
-
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
-
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
-
Originally 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
-
Originally 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 Wessel, 03-23-2024, 02:37 PM
|
3 responses
21 views
0 likes
|
Last Post Today, 04:58 PM | ||
Started by martini, Yesterday, 04:45 PM
|
4 responses
30 views
0 likes
|
Last Post
by martini
Today, 04:48 PM
|
||
Started by catinabag, 04-13-2023, 05:46 AM
|
34 responses
1,460 views
0 likes
|
Last Post
by mcosta72
Today, 04:44 PM
|
||
Started by adeelshahzad, Today, 11:49 AM
|
6 responses
23 views
0 likes
|
Last Post
by mcosta72
Today, 04:35 PM
|
||
Started by sidlercom80, 05-05-2020, 07:20 AM
|
4 responses
304 views
0 likes
|
Last Post
by Bidder
Today, 04:35 PM
|
Comment