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

Using ATR value of different time frame

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

    Using ATR value of different time frame

    Hi!

    I'm quite new at programming in NinjaScript, but I'd like to develop an indicator based on the ATR value of a higher time frame. In particular, I'd like to use the ATR value of the prior day in an intraday chart. I trade only the CAC40 on Euronext and the DAX on Eurex, so I do not have overnight sessions. Say I have a tick chart. In order to plot my indicator, I need to know the Initial Balance of the current day and the value of the ATR for the previous day, either defined as a proper day unit or as day made of 1440 minutes.

    Would you please suggest me how to do that? I would much appreciate your help!

    #2
    Hello Gianpiero,

    Thank you for your post.

    You would want to take a look at Multi-Timeframe and instruments programming with NinjaScript. I am attaching a link below on tips with using this -
    http://www.ninjatrader.com/support/h...nstruments.htm

    Let me know if I can be of further assistance.
    Cal H.NinjaTrader Customer Service

    Comment


      #3
      Thanks a lot Cal!

      Then I shoud add an additional Bars object with this instruction:

      Add(PeriodType.Minute, 1440);

      Then I could refer to the ATR value for the prior day with the following instruction:

      double atrLevel = ATR(BarsArray[1], 20)[1];

      Would you please confirm me that I understood correctly?

      Comment


        #4
        Gianpiero,

        Are you going to be running this with CalculateOnBarClose (COBC) set to true or false?

        If you are running true then you would want to use -
        ATR(BarsArray[1], 20)[0] which will give you the previous day

        While, ATR(BarsArray[1], 20)[1] will give you two days ago, unless this is set with COBC false, then you will get the previous day
        Cal H.NinjaTrader Customer Service

        Comment


          #5
          OK, thank you, but I get an error I cannot understand: "Error on calling 'OnBarUpdate' method for indicator ... on bar 30: You are accessing an index that is invalid since it's out of range. I.E. accessing an series [barsAgo] wiyh a value of 5 when there are only 4 bars on the chart."

          I guess the offending statement is the following:

          double atrLevel = ATR(BarsArray[1], 30)[0];

          and this is the series that I added to my tick chart:

          Add(PeriodType.Minute, 1440);

          From the message I figured that I don't have enough days, but how could that be possible? I tried to check to have enough bars with:

          if (CurrentBar < 30)
          return;

          though I suppose that this instruction refers to the primary series and not to the second. How would I check to have enough bars for the second one?
          Last edited by Gianpiero; 09-03-2014, 01:44 PM.

          Comment


            #6
            Gianpiero,

            Ensure that you have more than 30 days load for the Primary data series for the chart.

            Additionally, you may want to run a CurrentBars check in the OnBarUpdate(). See the sample below for more info -
            http://www.ninjatrader.com/support/f...ead.php?t=3170
            Cal H.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by judysamnt7, 03-13-2023, 09:11 AM
            4 responses
            59 views
            0 likes
            Last Post DynamicTest  
            Started by ScottWalsh, Today, 06:52 PM
            4 responses
            36 views
            0 likes
            Last Post ScottWalsh  
            Started by olisav57, Today, 07:39 PM
            0 responses
            7 views
            0 likes
            Last Post olisav57  
            Started by trilliantrader, Today, 03:01 PM
            2 responses
            21 views
            0 likes
            Last Post helpwanted  
            Started by cre8able, Today, 07:24 PM
            0 responses
            10 views
            0 likes
            Last Post cre8able  
            Working...
            X