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 timeframe indicator

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

    Multi timeframe indicator

    Hi all,
    I am trying to code a Multi timeframe indicator where on an intraday chart (say 5 min), I take the intraday low and add the Daily ATR. Have the following code but it does not seem to plot anything. Any help would be highly appreciated.

    protected override void Initialize()
    {

    Add(new Plot(Color.FromKnownColor(KnownColor.Red), PlotStyle.Hash, "DayLow"));
    Add(new Plot(Color.FromKnownColor(KnownColor.Crimson), PlotStyle.Hash, "LowPlusATR"));

    Add(PeriodType.Day,1);

    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.

    DayLow.Set(CurrentDayOHL().CurrentLow[0]);
    LowPlusATR.Set(CurrentDayOHL().CurrentLow[0] + ATR(BarsArray[1], 7)[1]);

    }

    #2
    Hello alfonso,

    Thank you for your note.

    Are you seeing any errors on the log tab of the control center?

    I look forward to your reply.
    Alan P.NinjaTrader Customer Service

    Comment


      #3
      Hi,
      Yes, I see the following error: "Error on calling 'OnBarUpdate' method for indicator 'AFAutoCurrentDayLowPlusATR' on bar 0: Index was outisde the bounds of the array.

      Not really sure what that means. Does that help?
      Thanks for your help.
      Alfonso

      Comment


        #4
        Hello alfonso,

        You should add a current bar check. For example on the 1st bar of the chart, when the strategy is applied, it will try to find the ATR value for 7 bars ago, which does not exist. So you need to prevent the strategy from running until there are greater than 7 bars.

        Please see the following reference sample which explains how to add this to your code.



        Please let us know if you need further assistance.
        Alan P.NinjaTrader Customer Service

        Comment


          #5
          Hi AlanP,
          Thanks for the info. What I dont understand is that I am trying to recall the prior days 7day average ATR. Hence, data should already be available at the start of each day. Thus not sure how the min bar check makes a difference in this case?

          thanks for the help.

          Comment


            #6
            Hello alfonso,

            Lets use a SMA as an example.

            When you apply the strategy to a data series, its applied to the first data point (the most left point in the data series or the oldest point), then moves to the right till its up to current bar.

            So without a current bar check, on Current Bar 1, a SMA(10)[0], would try to average the last 10 bars, which don't exist.

            To demonstrate my point you could add this to the top of OnBarUpdate,

            if(Historical) return;

            Which should prevent the error because calculations will not be made until the current bar.

            Please let us know if you need further assistance.
            Alan P.NinjaTrader Customer Service

            Comment


              #7
              Thank you AlanP,
              Did one with a fixed variable (i.e not calling the higher time frame to get the data but just plugging the number in manually as a user defined variable). That one does work.
              So I know for sure the error is somewhere in getting/assigning the data from the higher time frame. Tried various iterations with your suggestions, but no luck on the indicator working. Not really sure how to solve that but will try playing around with it a bit more.

              thanks for your help anyway.
              Alfonso

              Comment


                #8
                Hello alfonso.

                If you have additional data series, you would need a current bar check for each series.

                For example,

                Code:
                	if (CurrentBars[0] < 10 || CurrentBars[1] < 10 )	return;
                Please let us know if you need further assistance.
                Alan P.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Javierw.ok, Today, 04:12 PM
                0 responses
                4 views
                0 likes
                Last Post Javierw.ok  
                Started by timmbbo, Today, 08:59 AM
                2 responses
                10 views
                0 likes
                Last Post bltdavid  
                Started by alifarahani, Today, 09:40 AM
                6 responses
                40 views
                0 likes
                Last Post alifarahani  
                Started by Waxavi, Today, 02:10 AM
                1 response
                18 views
                0 likes
                Last Post NinjaTrader_LuisH  
                Started by Kaledus, Today, 01:29 PM
                5 responses
                15 views
                0 likes
                Last Post NinjaTrader_Jesse  
                Working...
                X