• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

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,

    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:

    http://screencast.com/t/5KGDG4AX

    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 Conall, Today, 06:11 AM
            1 response
            9 views
            0 likes
            Last Post NinjaTrader_Kate  
            Started by CaptainAmericaXX, Today, 07:41 AM
            1 response
            3 views
            0 likes
            Last Post NinjaTrader_Jim  
            Started by Longhornmark, Today, 07:06 AM
            2 responses
            7 views
            0 likes
            Last Post Longhornmark  
            Started by 2sureshk, Today, 07:29 AM
            0 responses
            5 views
            0 likes
            Last Post 2sureshk  
            Started by uday12, Yesterday, 10:26 PM
            1 response
            5 views
            0 likes
            Last Post NinjaTrader_PaulH  
            Working...
            X