Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Bars Array Period Type

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

    Bars Array Period Type

    Hi Guys. I have this problem with barsarray and Periodtype.Day. I am trying to print a daily ATR to the attached 5 Renko chart set for 10 days. The problem is when I add the following ATR code to the attached chart (set for 10 days) the ATR doesn't print.

    I looked at the log and it says error calling 'onbarupdate' method for bar 3 is out of range. If I substitute the PeriodType.Day to PeriodType.Minute it works ok for minute vut not for day. I think the answer is in the

    {if (CurrentBar <3)
    return;}

    It doesn't matter what I set this to the result is the same, it eh index value is out of range. Any ideas on this one? I have never had problems with this before but when using a PeriodType.Day it doesn't seem to work.

    Thanks
    DJ

    Code:

    protected override void Initialize()
    {
    Add(PeriodType.Day,5);
    }

    protected override void OnBarUpdate()
    {
    {if (CurrentBar <3)
    return;}
    if (BarsInProgress == 1)
    return;

    {
    DrawTextFixed("shortpivot1","ATR %: "+ATR(BarsArray[1], 5)[0].ToString("N1"), tPosition,Color.White,textFontMed, Color.Black, Color.Red, 10);
    }
    Attached Files
    Last edited by djkiwi; 05-21-2011, 10:30 AM.

    #2
    Hello,

    Thanks for the forum post.

    I would need to see full code to further assist here as nothing stands out.

    support at ninjatrader dot com reference this forum post for me to further assist with the programming error.

    I look forward to assisting you further.
    BrettNinjaTrader Product Management

    Comment


      #3
      Code

      Hi Brett. Please find attached code.

      Cheers
      DJ
      Attached Files

      Comment


        #4
        It seems that your ATR() is being calculated on 5 days, but you are only escaping 3 days for initial return

        Comment


          #5
          Bars Issue

          Thanks Koganam, still doesn't work though. The issue I think is the setting of daily ATR in ninja. I'm trying to set daily ATR based on the CME US Index Futures Extended session. The attached chart has the session template set for this. The problem is the the chart is only showing RTH timeframe on the daily. Its showing the low today of 806.8.

          The low was in fact 800.5. The % in top right is should be calculated based on the day move divided by ATR of about 14. So instead of showing 84% it should show 127%(818.4-800.5)/14.

          Anybody know how to make the daily to include the extended session so ATR can be calculated on the ETH session for the daily? Thanks. DJ
          Attached Files

          Comment


            #6
            DJ, what broker / feed are you using? If you use the native daily data it would also using the native session of the provider so the chart session template assigned wouldn't make a difference. You might need to calc the ATR on a 1440 min chart of your ETH needed session.

            Comment


              #7
              Broker data

              Thanks Bertrand for the solution. I'm not really sure about the native issue. I am connected to AMP/zenfire and also IB. I only have this issue on the daily.

              I have set this to 1440 minute and it works as you suggest. A couple of questions/issues on this though:

              1. Does using 1440 using extra resources as I will putting this on 8 daily charts?
              2. The goal is still to get the daily ATR % showing on a smaller timeframe chart without having to put up daily charts for each of the 8 instruments. I am wondering if the reason the code posted above in my first post didn't work because of this native daily issue? Having said that the log says "You are accessing an index with a value that is invalid since it's out of range". At the moment I have this using BarsArray and have 5 renko chart set to 10 days back. If I change the : Add(PeriodType.Day, 5); to Add(PeriodType.Minute, 30) the % shows ok so it's a problem with the Day, 5 part. I've also played around with changing the {if (CurrentBar <5 part but has no effect either.

              Thanks
              DJ

              protected override void Initialize()
              {
              Overlay = true;
              CalculateOnBarClose = false;
              Add(PeriodType.Day, 5);

              }


              protected override void OnBarUpdate()
              {
              {if (CurrentBar <5)
              return;}
              if (BarsInProgress == 1)
              return;

              if (CurrentBars[0] <= BarsRequired || CurrentBars[1] <= BarsRequired)
              return;

              {

              DrawTextFixed("shortpivot1","ATR %: "+ATR(BarsArray[1], 5)[0].ToString("N1"), tPosition,Color.White,textFontMed, Color.Black, Color.Red, 10);
              }



              Thanks
              DJ
              Last edited by djkiwi; 05-25-2011, 12:44 PM.

              Comment


                #8
                Daily/Weekly Data Issues

                Hi, does anybody know how to get the correct highs and lows for weekly and monthly based on a 24 hour/extended session and not retail? For example the attached picture shows the TF daily, weekly and monthly. I have used 1440 minutes to get the correct extended hours daily high and low. The weekly and monthly are still incorrect showing RTH high and low. The daily showing about 801 low and weekly and monthly showing 807 low. All templates are set to a 24 hour session.

                I connected to Kinetick and also shows the weekly high and low being based on RTH and not ETH. Pehaps there is a setting I'm missing?

                Thanks
                DJ
                Attached Files

                Comment


                  #9
                  DJ,

                  Daily charts are built from the session providers definitions, and won't reflect the session template selected. Weekly and monthly charts are built from this daily data so will also use the provider's session definitions.

                  The same approach used to build your own daily bars can be used for weekly and monthly as well, but there will typically be much less intraday history than daily. 10080 Min = Weekly.
                  Ryan M.NinjaTrader Customer Service

                  Comment


                    #10
                    Weekly Daily Monthly bars data Issues

                    Thanks Ryan. Actually I had already tried the 10080 minutes for weekly and 43920 for monthly based on 30.5 days per month The problem with this is it just end ups up plotting daily bars again. Unless I am doing something wrong (Please see attached chart with the 10080 minute and monthly).

                    It would be useful for many ninja users and traders to have the weekly and monthly based on a true 24 hour or ETH session. It is quite important to determine whether the weekly or monthly high low has been taken out on an ETH timeframe and not just RTH. I'm not sure why the data providers are doing this as it does not make much sense.

                    Any other way of rectifying this important issue would be appreciated.

                    Thanks
                    DJ
                    Attached Files

                    Comment


                      #11
                      Hello,

                      This is occurring due to the session template. When the session template goes into the next day it will start a new bar unfortunately. Therefor you could create a custom session template that spans a week in length however this would be the maximum length unfortunately and would include 24 hours / all data. There is not a way to do this in NinjaTrader with minute data above weekly charts.

                      Unfortunately your only option at this point is to get your data from another data feed provider if you need 24 hour data on monthly charts. If you need this let me know what instruments your trading and I can check a few data feeds to see who provides daily data in 25 hour format instead of regular trading hours format.

                      I look forward to assisting you further.
                      BrettNinjaTrader Product Management

                      Comment


                        #12
                        Thanks Brett. The instruments are:

                        ES, NQ, TF, CL, 6E, GC, ZB and FDAX

                        Comment


                          #13
                          Hello,

                          Thanks for that information.

                          I did some research an unfortunately only one broker has ETH templates on their daily data and that is MBT. There are no data feed providers that provide there daily bars in ETH unfortunately.
                          BrettNinjaTrader Product Management

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                          0 responses
                          580 views
                          0 likes
                          Last Post Geovanny Suaza  
                          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                          0 responses
                          335 views
                          1 like
                          Last Post Geovanny Suaza  
                          Started by Mindset, 02-09-2026, 11:44 AM
                          0 responses
                          102 views
                          0 likes
                          Last Post Mindset
                          by Mindset
                           
                          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                          0 responses
                          554 views
                          1 like
                          Last Post Geovanny Suaza  
                          Started by RFrosty, 01-28-2026, 06:49 PM
                          0 responses
                          552 views
                          1 like
                          Last Post RFrosty
                          by RFrosty
                           
                          Working...
                          X