Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Adding Plots with BarsArray[1]

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

    Adding Plots with BarsArray[1]

    Hello Support,

    After adding a second Bars object.

    I would like to get a plots of my indicator with secondary bars, as follows:

    //Add first plots using primary bars
    Add(Indicator(params1));
    Indicator(params1).PanelUI = 2;

    //Add second plots with secondary bars
    Add(Indicator(BarsArray[1],params2);
    Indicator(BarsArray[1],params2).PanelUI = 3;

    First plot appears but secondary plot does not appear. Is this expected?

    Is there away to do this in NT6.5?

    Thanks.
    Regards.
    EdwardK
    Thanks.

    Regards.

    #2
    Hello Edward,

    Yes, this is possible. The strategy plot sample demonstrates plotting highs from a secondary time frame:
    Plotting from within a NinjaScript Strategy

    The Initialize() method is just used as a placeholder for your plots, and the actual values are set in OnBarUpdate. The indicator you're using shouldn't contain any calculation logic. That's all done within the strategy.

    The snippet below expands the strategy plot sample to include an SMA of the secondary series.

    Code:
     
    protected override void Initialize()
    {
    CalculateOnBarClose = true;
     
    // Create a multi-time frame strategy
    Add(PeriodType.Minute, 30);
     
    /* Add our blank placeholder indicators. The parameter we pass in is used to distinguish the two
    indicators from each other. */
    Add(StrategyPlot(0));
    Add(StrategyPlot(1));
    Add(StrategyPlot(2));
     
    // Set the color for the indicator plots
    StrategyPlot(0).Plots[0].Pen.Color = Color.Blue;
    StrategyPlot(1).Plots[0].Pen.Color = Color.YellowGreen;
     
    // Set the panel which the plots will be placed on. 1 = price panel, 2 = panel under the price panel, etc.
    StrategyPlot(0).PanelUI = 1;
    StrategyPlot(1).PanelUI = 1;
     
    // For more options please see the forum tip titled "Adding Indicators to Strategies"
    // http://www.ninjatrader-support.com/vb/showthread.php?t=3228
    }
    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()
    {
    /* Set the values of our indicators. One of them is set to the High of the primary bar series while the
    other is set to the High of the secondary bar series. This effectively creates a multi-time frame plot. */
    StrategyPlot(0).Value.Set(High[0]);
    StrategyPlot(1).Value.Set(Highs[1][0]);
    StrategyPlot(2).Value.Set(SMA(BarsArray[1], 14)[0]);
    }
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Hello RyanM,

      Ok, I understand now, we need to reflect the values from within the OnBarUpdate. Not exactly what I want but I think it can be worked around. Will try it out.

      Thanks.
      Regards.
      EdwardK.

      Comment


        #4
        Issue

        I have tried this and find its not working in this situation, can you tell why?

        Its Plotting the Close of the primary data series twice for both strategy plot 0 and 1.
        StrategyPlot(0).Value.Set(Closes[0][0]);
        StrategyPlot(1).Value.Set(Closes[1][0]);




        Code:
           protected override void Initialize()
                {
                    Add(PeriodType.Minute,1);
        			CalculateOnBarClose = false;
                Add(StrategyPlot(0));
        		Add(StrategyPlot(1));
        		//Add(StrategyPlot(2));
        		
        		// Add two EMA indicators to be plotted on the primary bar series
        		//Add(EMA(Fast));
        		//Add(EMA(Slow));
        			
        		/* Adjust the color of the EMA plots.
        		For more information on this please see this tip: http://www.ninjatrader-support.com/vb/showthread.php?t=3228 */
        		//	EMA(Fast).Plots[0].Pen.Color = Color.Blue;
        		//EMA(Slow).Plots[0].Pen.Color = Color.Green;
        	
        		// Set the color for the indicator plots
        		StrategyPlot(0).Plots[0].Pen.Color = Color.Blue;
        		StrategyPlot(1).Plots[0].Pen.Color = Color.YellowGreen;
        		
        		// Set the panel which the plots will be placed on. 1 = price panel, 2 = panel under the price panel, etc.
        		StrategyPlot(0).PanelUI = 2;
        		StrategyPlot(1).PanelUI = 2;
        				
        		
        		}
        
                
                protected override void OnBarUpdate()
                {
               /* if (ds1==null) {ds1 = new DataSeries(SMA(BarsArray[1],5));}
        		if (ds2==null) {ds2 = new DataSeries(SMA(BarsArray[1],5));}
        		ds1.Set(Close[0]); 	
        		ds2.Set(EMA(Close,5)[0]);*/ 
        		
        		StrategyPlot(0).Value.Set(Closes[0][0]); 
        		StrategyPlot(1).Value.Set(Closes[1][0]);

        Comment


          #5
          Hi neb1998,

          It's working OK here The sample is available for download here. A real time close of 1 minute series is the same as real time close of 10 minute. Maybe change your add statement to another instrument so you can verify if the values are really the same.

          Add("MSFT", PeriodType.Minute, 3);
          Ryan M.NinjaTrader Customer Service

          Comment


            #6
            If the primary data is 15 and the secondary is 1 the plot will only update every 15 minutes, which makes the lines diverge but isnt accurate.

            I attempted to put one of the StrategyPlots within BIP==1, 1 minute in this example and nothing plots. Neither the primary plot or the secondary. I am guessing this is expected?

            Comment


              #7
              It sounds like you are trying to plot a 1 minute series over 15 minute. This won't really produce meaningful display using StrategyPlot.

              The strategy plot sample doesn't connect with our standard multi series charting model, which forces equidistant bar spacing. Reversing the series may give you more meaningful display here, or you can chart these series independent of your strategy. Attached screenshot uses BOX style 15 minute bars over 1 minute, and provides a nice effect for seeing a smaller time frame within a larger.
              Attached Files
              Ryan M.NinjaTrader Customer Service

              Comment


                #8
                Yeah Ryan thanks, i actually plot the OHLC 15 min bar and then the OHLC 1 min bar on the same panel. It looks rather nice as you can see exactly what the price is doing in 1 min increments between the 15 min bars.

                I am going to built my own DataSeries object that is like myClose...which contains the aggregate high,low, and open so i can better simulate entrances during backtesting.....i have most of the code done now and its working well.

                The flexibility of NT is helping me a lot, This is not possible in MC

                Comment


                  #9
                  Great you found a chart display that works for you. Thank you for the feedback and kind words!
                  Ryan M.NinjaTrader Customer Service

                  Comment


                    #10
                    Yes, this is possible. The strategy plot sample demonstrates plotting highs from a secondary time frame:
                    Plotting from within a NinjaScript Strategy

                    The Initialize() method is just used as a placeholder for your plots, and the actual values are set in OnBarUpdate. The indicator you're using shouldn't contain any calculation logic. That's all done within the strategy.
                    When this will be available for backtesting?

                    Comment


                      #11
                      Unfortunately no time frame on new features is available. Thank you for the suggestion, Baruch.
                      Ryan M.NinjaTrader Customer Service

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                      0 responses
                      649 views
                      0 likes
                      Last Post Geovanny Suaza  
                      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                      0 responses
                      370 views
                      1 like
                      Last Post Geovanny Suaza  
                      Started by Mindset, 02-09-2026, 11:44 AM
                      0 responses
                      109 views
                      0 likes
                      Last Post Mindset
                      by Mindset
                       
                      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                      0 responses
                      574 views
                      1 like
                      Last Post Geovanny Suaza  
                      Started by RFrosty, 01-28-2026, 06:49 PM
                      0 responses
                      576 views
                      1 like
                      Last Post RFrosty
                      by RFrosty
                       
                      Working...
                      X