Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Big daily ATR on 1H chart

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

    Big daily ATR on 1H chart

    I looked through a few of these types of questions but none of them seemed to work for me. Here is what I currently have:

    PHP Code:
    protected override void Initialize() {
        BarsRequired = 90;
                
        EntriesPerDirection = 1;
        EntryHandling = EntryHandling.AllEntries;
                
        Add(PeriodType.Day, 1);
                
        CalculateOnBarClose = false;
    }
    
    protected override void OnBarUpdate() {
        if (BarsInProgress == 1) { return; }
                
        if (CurrentBars[0] < 1 || CurrentBars[1] < BarsRequired) {
            Print("No chart bars (" + CurrentBars[0] + ") or not enough daily bars (" + CurrentBars[1] + ")");
        } else {
            double ATRVal = .5 * ATR(BarsArray[1], 90)[0];
            Print("50% of 90-day ATR (currentbars -> " + CurrentBars[1] + "): " + ATRVal);
        }
    } 
    
    Every single tick gives me the following
    No chart bars (104) or not enough daily bars (0)
    I'd like to get the 90 day ATR while on the 1H chart. My UI selections are to load the Minute data type, 60 as the value, load 91 days, and look back indefinitely.

    What am I missing?!

    #2
    lifzgreat, which broker / data provider are you using? The error you get looks more like a native error receiving the needed data - if you open a normaly daily chart of the instrument would you get the same shown?

    Comment


      #3
      Thanks for the reply, Bertrand.

      which broker / data provider are you using?
      I'm using FXCM.


      The error you get looks more like a native error receiving the needed data
      However, it's not an error, per se; it's the intended output when the code in my first post meets the first condition. But I don't understand why it's hitting that condition after I used Add() to get daily bars. Shouldn't CurrentBars[1] have something in it?


      if you open a normaly daily chart of the instrument would you get the same shown?
      I will have to look to be sure inside NinjaTrader but I don't have trouble seeing daily bars inside FXCM.

      Comment


        #4
        Sorry, that I missed that - the 104 must have reminded me of a data provider native error #.

        I would look into loading first of all then more days here on your chart, or using a lower BarsRequired value. As the OnBarUpdate() method would only be called if BarsRequired has been fulfilled for all series, hence the 91 days loaded is not enough in this case.

        Comment


          #5
          No problem.

          Why is 91 not enough when BarsRequired is 90 and only 90 bars are ever used? I load 91 days in the UI strategy editor to make sure I have more than 90. I don't understand why you're saying 91 days is not enough to satisfy the 90 requirement. Please explain!

          Comment


            #6
            ...because it would be using calendar, not trading days. So if you count in a few weekends and potentially holidays then you need to load more data to pass this check.

            Comment


              #7
              Oh my. I was not aware the days variable means calendar days. I do not recall any indication as to the meaning of that variable. I thought 90 days would be 90 days of data, why would I think otherwise?

              Anyway, if that's the case, then that should solve the entire problem. I'll test it out and reply back here. Thanks for the explanation!

              Comment


                #8
                Originally posted by lifzgreat View Post
                No problem.

                Why is 91 not enough when BarsRequired is 90 and only 90 bars are ever used? I load 91 days in the UI strategy editor to make sure I have more than 90. I don't understand why you're saying 91 days is not enough to satisfy the 90 requirement. Please explain!
                You will need to load a minimum of 127 days: probably more. You need 91 trading days. That translates to ((90 * 7 / 5) + 1 ) calendar days.

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                0 responses
                633 views
                0 likes
                Last Post Geovanny Suaza  
                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                0 responses
                364 views
                1 like
                Last Post Geovanny Suaza  
                Started by Mindset, 02-09-2026, 11:44 AM
                0 responses
                105 views
                0 likes
                Last Post Mindset
                by Mindset
                 
                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                0 responses
                567 views
                1 like
                Last Post Geovanny Suaza  
                Started by RFrosty, 01-28-2026, 06:49 PM
                0 responses
                568 views
                1 like
                Last Post RFrosty
                by RFrosty
                 
                Working...
                X