Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Multi Time Frame Indicator

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

    Multi Time Frame Indicator

    Hi try to code something simple. But it does not work. I try to plot a Sma from an time chart on a range chart.

    protected override void Initialize()
    {
    Add (PeriodType.Minute, 5);
    Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "Plot0"));
    Overlay = true;
    }




    protected override void OnBarUpdate()
    {

    Plot0.Set(SMA(BarsArray[1], 20)[0]);
    }

    But if I lay the indicator on my chart, the indicator plots nothing.

    Thank you

    #2
    Looks like you are trying to plot the plot.

    Try BarsArray[0] instead.


    Originally posted by Ironman9973 View Post
    Hi try to code something simple. But it does not work. I try to plot a Sma from an time chart on a range chart.

    protected override void Initialize()
    {
    Add (PeriodType.Minute, 5);
    Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "Plot0"));
    Overlay = true;
    }




    protected override void OnBarUpdate()
    {

    Plot0.Set(SMA(BarsArray[1], 20)[0]);
    }

    But if I lay the indicator on my chart, the indicator plots nothing.

    Thank you

    Comment


      #3
      If I use BarsArray[0] it takes the data from the range chart. But I want to plot the data from the time chart on the range chart.

      Comment


        #4
        Originally posted by Ironman9973 View Post
        If I use BarsArray[0] it takes the data from the range chart. But I want to plot the data from the time chart on the range chart.
        Hi, I totally missed your Add (PeriodType.Minute, 5) this morning. My fault.

        Anyways, I just did a full test and I think I see your issue.


        In Control Center, goto Tools->Output Window.

        Try to use your strategy again.

        You should see errors like:

        Error on calling 'OnBarUpdate' method for indicator 'plottest1' 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.


        What you need is a CurrentBar check.


        Code:
                protected override void Initialize()
                {
                    Add ( PeriodType.Minute,5);
                    Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "Plot0"));
                    Add(new Plot(Color.FromKnownColor(KnownColor.Green), PlotStyle.Line, "Plot1"));
                    Overlay                = true;
                }
        
                /// <summary>
                /// Called on each bar update event (incoming tick)
                /// </summary>
                protected override void OnBarUpdate()
                {
                    // Use this method for calculating your indicator values. Assign a value to each
                    // plot below by replacing 'Close[0]' with your own formula.
                    [B]if (CurrentBar<50) return;[/B]
                    
                    Plot0.Set(Close[0]);
                    Plot1.Set(SMA(BarsArray[1],20)[0]);
                }
        
                #region Properties
                [Browsable(false)]    // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
                [XmlIgnore()]        // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
                public DataSeries Plot0
                {
                    get { return Values[0]; }
                }
        
                [Browsable(false)]    // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
                [XmlIgnore()]        // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
                public DataSeries Plot1
                {
                    get { return Values[1]; }
                }
        
                [Description("")]
                [GridCategory("Parameters")]
                public int MyInput0
                {
                    get { return myInput0; }
                    set { myInput0 = Math.Max(1, value); }
                }
                #endregion
            }

        Comment


          #5
          Thank you very much, it works. But if have no idea why I need a CurrentBar check.

          Comment


            #6
            Originally posted by Ironman9973 View Post
            Thank you very much, it works. But if have no idea why I need a CurrentBar check.
            It is simply because you don't have enough 5 minute bars to make a SMA of period 20.

            You may have 500 range bars, but only 2 5 minute bars and you won't be able to make an SMA of period 20. (and then the check below won't work either, you'll need a number over 500).

            There is some info in the help section of NT under understanding multitimeframe series.

            You might be able to better see/understand if you build a chart with a RANGE series and add a 5 minute series to it.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            566 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            330 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            101 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            547 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            548 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X