Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Plotting Multiple Timeframes

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

    Plotting Multiple Timeframes

    I can not get the code below to work. I am trying to load it on a 1 minute chart. I get an "Index was outside the bounds of the array" error. If I comment out the line:

    Plot2.Set(dateTime2[0])

    the momentum for the first BarsArray plots correctly. If I then change

    Plot1.Set(dateTime1[0]) to Plot1.Set(dateTime2[0])

    it plots out the second BarsArray.

    Why does Plot2.Set cause an error? I'm sure there is something simple I am missing.... Thanks

    PHP Code:
    public class MutliTimeframePlot : Indicator
    {
      #region Variables
      private DataSeries dataTime1;
      private DataSeries dataTime2;
      #endregion
    protected override void Initialize()
    {
      Add(PeriodType.Minute, 5);
      Add(PeriodType.Minute, 15);
     
      dataTime1 = new DataSeries(this);
      dataTime2 = new DataSeries(this);
     
      CalculateOnBarClose = true;
      Overlay = false;
    }
    protected override void OnBarUpdate()
    {
      if (BarsInProgress == 0)
      {
        if (CurrentBar < 100) return;
        dataTime1[0] = Momentum(BarsArray[1], 14)[0];
        dataTime2[0] = Momentum(BarsArray[2], 14)[0];
        Plot1.Set(dataTime1[0]);
        Plot2.Set(dataTime2[0]);
    }
    if (BarsInProgress == 1)
    {
    }
    if (BarsInProgress == 2)
    {
    }
    }
    #region Properties
    [Browsable(false)]
    [XmlIgnore()] 
    public DataSeries Plot1
    {
      get { return Values[0]; }
    }
     
    [Browsable(false)]
    [XmlIgnore()] 
    public DataSeries Plot2
    {
      get { return Values[1]; }
    }
    #endregion
    } 
    
    The Trading Mantis
    NinjaTrader Ecosystem Vendor - The Trading Mantis

    #2
    Greg, Plot1 would always relate normally to the primary indicator value series...I didn't see you defining any Plots in the Intialize() of your code, please add those for Plot1 and 2 and then retry.

    Comment


      #3
      That was it, thanks Bertrand.

      Just curious, why does Plot1 still plot on the chart without any Plot statements in Initialize()?
      The Trading Mantis
      NinjaTrader Ecosystem Vendor - The Trading Mantis

      Comment


        #4
        Great, this is 'linked' to your Value series, hence this will always be defined per default - http://www.ninjatrader-support.com/H...AndValues.html

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        591 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        342 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        103 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        555 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        552 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X