Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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 Belfortbucks, Today, 09:29 PM
            0 responses
            6 views
            0 likes
            Last Post Belfortbucks  
            Started by zstheorist, Today, 07:52 PM
            0 responses
            7 views
            0 likes
            Last Post zstheorist  
            Started by pmachiraju, 11-01-2023, 04:46 AM
            8 responses
            151 views
            0 likes
            Last Post rehmans
            by rehmans
             
            Started by mattbsea, Today, 05:44 PM
            0 responses
            6 views
            0 likes
            Last Post mattbsea  
            Started by RideMe, 04-07-2024, 04:54 PM
            6 responses
            33 views
            0 likes
            Last Post RideMe
            by RideMe
             
            Working...
            X