Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Multi-timeframe Indicator

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

    Multi-timeframe Indicator

    Hey guys can't seem to get this to work, I know its something stupid....Works fine if I take the time frames away. I've tried TH.Set(BarsArray[1].GetClose(0)); high low etc in it's place still no luck....





    public class TDT : Indicator
    {
    #region Variables
    // Wizard generated variables
    public int t1 = 1; // Default setting for T1
    public int t2 = 1; // Default setting for T2
    public int t3 = 1; // Default setting for T3
    public int t4 = 1; // Default setting for T4

    // User defined variables (add any user defined variables below)
    #endregion

    /// <summary>
    /// This method is used to configure the indicator and is called once before any bar data is loaded.
    /// </summary>
    protected override void Initialize()
    {
    Add(PeriodType.Minute, t1); // ON CHART
    Add(PeriodType.Minute, t2); // ON CHART
    Add(PeriodType.Minute, t3); // ON CHART
    Add(PeriodType.Minute, t4); // USED TO CALC TIME DILATION
    Add(new Plot(Color.FromKnownColor(KnownColor.SeaGreen), PlotStyle.Line, "TD"));
    Overlay = false;
    }

    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()
    {
    #region TDT
    TH.Set(Close[0]);
    TL.Set(High[0]);
    TD.Set(Low[0]);
    #endregion

    }

    #2
    I just cant seem to get the indicator to plot if I have more then 1 time frame, take the time frames away it's fine. Not sure if its the variables Im passing from the properties or just not working.

    Comment


      #3
      Happyhappy,

      Thank you for your post.

      Do you receive any errors in the Log Tab of the Control Center after adding the indicator to the chart?
      Cal H.NinjaTrader Customer Service

      Comment


        #4
        Error on calling 'OnBarUpdate' method for indicator 'TDT' on bar 0: You are accessing an index with a value that is invalid since its out of range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.

        Seems to occur when I have more then 1 time frame. I've resolved with a try{CODE}catch{}. This error appears in output, can i suggest for the new version that it pop up when creating on adding a new indicator.

        Comment


          #5
          TH.Set(Close[0]);
          TL.Set(High[0]);
          TD.Set(Low[0]);

          Also I can't use 0 it is a flat value for some reason I think its the first bar in the series. I had to use CurrentBar.

          Comment


            #6
            Happyhappy,

            You will need to use a CurrentBars check for all the timeframes you are adding.

            if(CurrentBars[0] < 1 || CurrentBars[1] < 1 || ...etc...)
            return;
            Cal H.NinjaTrader Customer Service

            Comment


              #7
              Originally posted by happypappy View Post
              Hey guys can't seem to get this to work, I know its something stupid....Works fine if I take the time frames away. I've tried TH.Set(BarsArray[1].GetClose(0)); high low etc in it's place still no luck....





              public class TDT : Indicator
              {
              #region Variables
              // Wizard generated variables
              public int t1 = 1; // Default setting for T1
              public int t2 = 1; // Default setting for T2
              public int t3 = 1; // Default setting for T3
              public int t4 = 1; // Default setting for T4

              // User defined variables (add any user defined variables below)
              #endregion

              /// <summary>
              /// This method is used to configure the indicator and is called once before any bar data is loaded.
              /// </summary>
              protected override void Initialize()
              {
              Add(PeriodType.Minute, t1); // ON CHART
              Add(PeriodType.Minute, t2); // ON CHART
              Add(PeriodType.Minute, t3); // ON CHART
              Add(PeriodType.Minute, t4); // USED TO CALC TIME DILATION
              Add(new Plot(Color.FromKnownColor(KnownColor.SeaGreen), PlotStyle.Line, "TD"));
              Overlay = false;
              }

              /// <summary>
              /// Called on each bar update event (incoming tick)
              /// </summary>
              protected override void OnBarUpdate()
              {
              #region TDT
              TH.Set(Close[0]);
              TL.Set(High[0]);
              TD.Set(Low[0]);
              #endregion

              }
              I do not see any declarations for TH or TL. What are they supposed to be?

              Comment


                #8
                Originally posted by NinjaTrader_Cal View Post
                Happyhappy,

                You will need to use a CurrentBars check for all the timeframes you are adding.

                if(CurrentBars[0] < 1 || CurrentBars[1] < 1 || ...etc...)
                return;
                NinjaTrader_Cal,

                Thank you this resolved my issue.

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                0 responses
                666 views
                0 likes
                Last Post Geovanny Suaza  
                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                0 responses
                376 views
                1 like
                Last Post Geovanny Suaza  
                Started by Mindset, 02-09-2026, 11:44 AM
                0 responses
                110 views
                0 likes
                Last Post Mindset
                by Mindset
                 
                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                0 responses
                575 views
                1 like
                Last Post Geovanny Suaza  
                Started by RFrosty, 01-28-2026, 06:49 PM
                0 responses
                580 views
                1 like
                Last Post RFrosty
                by RFrosty
                 
                Working...
                X