• 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 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.

        https://ninjatrader.com/support/foru...ead.php?t=3170

        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 rickyblah12, Today, 06:19 PM
                0 responses
                2 views
                0 likes
                Last Post rickyblah12  
                Started by ballboy11, Today, 05:22 PM
                0 responses
                2 views
                0 likes
                Last Post ballboy11  
                Started by ballboy11, Today, 04:33 PM
                2 responses
                3 views
                0 likes
                Last Post ballboy11  
                Started by dedouglas, Today, 03:16 PM
                1 response
                7 views
                0 likes
                Last Post NinjaTrader_ChelseaB  
                Started by TradeMyth, Today, 02:45 PM
                3 responses
                19 views
                0 likes
                Last Post NinjaTrader_ChelseaB  
                Working...
                X