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 cmoran13, 04-16-2026, 01:02 PM
        0 responses
        43 views
        0 likes
        Last Post cmoran13  
        Started by PaulMohn, 04-10-2026, 11:11 AM
        0 responses
        25 views
        0 likes
        Last Post PaulMohn  
        Started by CarlTrading, 03-31-2026, 09:41 PM
        1 response
        163 views
        1 like
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 04-01-2026, 02:41 AM
        0 responses
        98 views
        1 like
        Last Post CarlTrading  
        Started by CaptainJack, 03-31-2026, 11:44 PM
        0 responses
        158 views
        2 likes
        Last Post CaptainJack  
        Working...
        X