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,

    I am trying to develop a very simple indicator. I'm trying to plot the close of daily data on an intraday chart. I'm trying to do this using the next code:


    protected override void Initialize()
    {
    Add(new Plot(Color.FromKnownColor(KnownColor.OrangeRed), PlotStyle.Line, "Valor"));
    Add(PeriodType.Day, 1);

    Overlay = true;
    }
    protected override void OnBarUpdate()
    {
    if(CurrentBar < 15) return;

    if (BarsInProgress == 0)
    Valor.Set(Closes[1][0]);
    }

    I have enough bars on the daily chart, however when I try this code I receive the next message:

    Error on calling 'OnBarUpdate' method for indicator 'X' on bar 15: 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.

    Please, could you tell me if there is any mistake on the code?

    Thanks.

    #2
    Don't know about the code but this vid might be helpful to you:

    Comment


      #3
      Hello,

      You may need to check both series and return like the following:
      Code:
      if(CurrentBars[0] < 15 || CurrentBars[1] < 1) return;
      The amount of bars for each series in respect to the data needed.

      Could you try this and see if the outcome is corrected?

      I look forward to being of further assistance.
      JesseNinjaTrader Customer Service

      Comment


        #4
        Thank you Jesse,

        I tried your code, and also tried this one:

        if(CurrentBars[0] < 15 && CurrentBars[1] < 1) return;

        But in both cases I get the same result.

        In adition In Initialize() section I also changed this:

        Add(PeriodType.Day, 1);

        for this:

        Add("ES 12-16", PeriodType.Day, 1);

        But I have the same result.

        As I mentioned I have enough bars on daily data on that symbol (ES 12-16) so that it cannot be the problem.

        Please, could you develop this simple indicator and try it on your data in order to see if everything is correct?

        Thanks.
        Last edited by Plaket; 09-11-2016, 03:20 AM.

        Comment


          #5
          Hello Plaket,

          Thanks for your reply.

          This code works:

          Code:
           protected override void Initialize()
                  {
          			CalculateOnBarClose = false;  
          			Overlay = true;				
          			Add(new Plot(Color.FromKnownColor(KnownColor.OrangeRed), PlotStyle.Line, "Valor"));
          			Add(PeriodType.Day, 1);
                  }
          
          protected override void OnBarUpdate()
                  {
          			if(CurrentBars[0] < 15 || CurrentBars[1] < 1 ) return;
          
          			if (BarsInProgress == 0) 
          			Valor.Set(Closes[1][0]);	
          
          		}
          In the CurrentBars check you must use the "OR" || operator. It is not a question of how many bars you are loading on your chart it is a question of how many bars have loaded when you code does Valor.Set(Closes[1][0]); In this case you would need to have 1 day bar processed by the strategy code. (Note that the counts start at 0 (zero)).

          Also, you might consider the use of the NinjaTrader indicator PriorDayOHLC which will produce the same thing and you have the option to turn off any of the plots not needed.
          Paul H.NinjaTrader Customer Service

          Comment


            #6
            Thank you,

            The problem has been solved.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by mmckinnm, Today, 01:34 PM
            1 response
            4 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by Conceptzx, 10-11-2022, 06:38 AM
            3 responses
            60 views
            0 likes
            Last Post NinjaTrader_SeanH  
            Started by f.saeidi, Today, 01:32 PM
            1 response
            2 views
            0 likes
            Last Post NinjaTrader_Erick  
            Started by traderqz, Today, 12:06 AM
            9 responses
            16 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Started by kevinenergy, 02-17-2023, 12:42 PM
            117 responses
            2,766 views
            1 like
            Last Post jculp
            by jculp
             
            Working...
            X