Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Change Indicator Plot Color in a Strategy

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    #16
    Originally posted by NinjaTrader_Bertrand View Post
    For that I would look into changing the PlotColors of your placeholder indicator instead of the Pen Color -

    StrategyPlot(0).PlotColors[0][0]
    what is StrategyPlot(0)? I tried PlotColors[0][0] in strategy, but it only for indicators.

    Comment


      #17
      Alexstox,

      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;
      Cal H.NinjaTrader Customer Service

      Comment


        #18
        Originally posted by NinjaTrader_Cal View Post
        Alexstox,
        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;
        I tried to do like that, but get this message
        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


          #19
          Alexstox,

          With the CurrentBars[1] I assume you are adding an additional data series to your script correct?
          Cal H.NinjaTrader Customer Service

          Comment


            #20
            Originally posted by NinjaTrader_Cal View Post
            Alexstox,
            With the CurrentBars[1] I assume you are adding an additional data series to your script correct?
            You are right.
            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


              #21
              alexstox, 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.

              Comment


                #22
                Originally posted by NinjaTrader_Bertrand View Post
                alexstox, 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.
                Changed to .PlotColors[0][0]=Color.Green;
                Color of indicator didn't change

                Comment


                  #23
                  Alexstox,

                  Can you please repost your adjusted script so I can see what you have changed?
                  Cal H.NinjaTrader Customer Service

                  Comment


                    #24
                    Originally posted by NinjaTrader_Cal View Post
                    Alexstox,
                    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


                      #25
                      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


                        #26
                        Originally posted by NinjaTrader_Cal View Post
                        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.
                        I 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


                          #27
                          Originally posted by alexstox View Post
                          I 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.
                          Here is an example. http://www.ninjatrader.com/support/f...97907#poststop

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by sjsj2732, Yesterday, 04:31 AM
                          0 responses
                          31 views
                          0 likes
                          Last Post sjsj2732  
                          Started by NullPointStrategies, 03-13-2026, 05:17 AM
                          0 responses
                          286 views
                          0 likes
                          Last Post NullPointStrategies  
                          Started by argusthome, 03-08-2026, 10:06 AM
                          0 responses
                          283 views
                          0 likes
                          Last Post argusthome  
                          Started by NabilKhattabi, 03-06-2026, 11:18 AM
                          0 responses
                          133 views
                          1 like
                          Last Post NabilKhattabi  
                          Started by Deep42, 03-06-2026, 12:28 AM
                          0 responses
                          91 views
                          0 likes
                          Last Post Deep42
                          by Deep42
                           
                          Working...
                          X