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

ATR Calculation in Strategy and ATR on Daily Chart different

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

    ATR Calculation in Strategy and ATR on Daily Chart different

    I have a intraday strategy that uses the Daily ATR as a factor determining the stop and target.

    I have created a session template that matches the pit session so it runs from 9:00am to 4:15 pm EST.

    It is an intraday strategy so I have added the second period in the Initilize like so:

    protected override void Initialize()

    Add(Period.Type.Day,1);

    Then in the On Bar Update I have added:

    if(Bars in Progress ==1)
    this.curATR=ATR(this.curATRPeriod[0];

    When I set the ATR period to 1 the ATR shown in my Strategy matches the Atr(1) on the ES chart. As soon as I add a value greater than 1 I get values in my strategy different than those expressed on the chart.

    For example. on the ES 06-16 for May 5, 2016 on the chart with a 2 day ATR The chart indicates 22.13.In my strategy it indicates a value of 23.75

    I have attached the chart and data window over the output window where the strategy indicates the ATR Value

    Attached Files

    #2
    Hello,

    Thank you for the question.

    I tried on my end what I could see from the image and description but have been unable to reproduce the non matching results.

    Does this occur while using a standard session template or the default for the instrument? Also have you checked using Prints that the variable for the period is being set correctly to ensure both the chart and strategy share the same values?

    Additionally are you manually adding the ATR to the chart, and then printing the result from the strategy? or is the strategy calling Add() to add the indicator?

    Because using the syntax you had provided I am unable to reproduce the problem, I would suggest to create a new strategy and only add the second series, and a Print for the ATR. You can then check this versus a chart to see if the problem persists. If so I would like to see the syntax used, at we could troubleshoot from there.

    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Jesse View Post
      Hello,

      Thank you for the question.

      I tried on my end what I could see from the image and description but have been unable to reproduce the non matching results.

      Does this occur while using a standard session template or the default for the instrument? Also have you checked using Prints that the variable for the period is being set correctly to ensure both the chart and strategy share the same values?

      Additionally are you manually adding the ATR to the chart, and then printing the result from the strategy? or is the strategy calling Add() to add the indicator?

      Because using the syntax you had provided I am unable to reproduce the problem, I would suggest to create a new strategy and only add the second series, and a Print for the ATR. You can then check this versus a chart to see if the problem persists. If so I would like to see the syntax used, at we could troubleshoot from there.

      I look forward to being of further assistance.
      Thanks for taking the time to look at this. I will not have time to troubleshoot here till later today, but thought I would answer your questions first.

      Does this occur while using a standard session template or the default for the instrument? The chart I posted is using the default template for the ES. The strategy is based on a template that mirrors the pit session 9:30am 4:15 pm. I tried changing the session on the chart and it does not change the values of the ATR.


      Also have you checked using Prints that the variable for the period is being set correctly to ensure both the chart and strategy share the same values? No I have not. I am setting the variable via the strategy window, but will set it to print tonight to be sure, though I suspect it is working correctly as setting it to 1 and changing the chart to ATR(1) the values match.

      Additionally are you manually adding the ATR to the chart, and then printing the result from the strategy? or is the strategy calling Add() to add the indicator? The chart attached to the post was manually loaded and not loaded from the strategy. I would suspect a chart loaded from the strategy would have the value indicated in the strategy. The value in the output window is the value indicated by the strategy.

      If any of that leads you to something I have coded incorectly please let me know. I will troubleshoot using the methods you have suggested above tonight. Thansk again for looking into this!

      Comment


        #4
        Hi there,

        A Couple of things.
        I reviewed the values and the strategy actually does give the correct values going back to Feb 29th. Dates Feb 17-28 are off by 0.01, dates Feb11-17 are off by 0.02, dates feb 7-11 off by 0.03 and then things get worse going back to Jan 14th were it is off by 3.52.

        I added a print to the atr value and it matches inside the strategy. So there are 2 things that I think it might be. maybe you can point me in the right direction.

        First off in this strategy for backtesting purposes, I do not load holidays. I use the code:

        if(isHoliday(Bars.GetSessionDateFromLocal(Bars.Sessi on, Time[0])))
        return;

        then have a list of all previous holidays in a region below. I don't want the system to trade on holidays. Since the print was the same and the values were correct and only started to vary the further back in time I thought this code might be causing the issue.

        So I am thought since the ATR is a system indicator it is being calculated with holiday values included in the daily bars, I disabled the holiday return but I am still getting the same values in ATR.

        The only other thing I can think is perhaps my merge method is causing the issue. I currently have the Mege policy set to MergenonBackAdjusted

        Do either of these items seem like likely reasons for this behaviour?

        Comment


          #5
          Hello,

          I am not seeing anything specifically that may be related but again I am unsure of the logic used so potentially it has something to do with the logic or the settings.

          I believe at this point it may be best to make a control sample for testing as I was not able to see the same problem on my end in my more simple example.

          Could you try the following to see if this can point a direction for finding the answer?
          Create a new empty strategy
          Add the secondary series
          Add the call to the indicator how you are currently and print, please omit any other logic you are using currently.
          add the strategy to a chart and manually add the indicator with the same settings used in the strategy.

          The main point of this test is just to print the ATR from the strategy and compare it to the chart, if the values match up likely this is to do with the logic used in the other script. If the values do not match it may be settings related but I would like to review the sample first to know the exact syntax used.

          I look forward to being of further assistance.
          JesseNinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by inanazsocial, Today, 01:15 AM
          1 response
          5 views
          0 likes
          Last Post NinjaTrader_Jason  
          Started by rocketman7, Today, 02:12 AM
          0 responses
          6 views
          0 likes
          Last Post rocketman7  
          Started by dustydbayer, Today, 01:59 AM
          0 responses
          1 view
          0 likes
          Last Post dustydbayer  
          Started by trilliantrader, 04-18-2024, 08:16 AM
          5 responses
          23 views
          0 likes
          Last Post trilliantrader  
          Started by Davidtowleii, Today, 12:15 AM
          0 responses
          3 views
          0 likes
          Last Post Davidtowleii  
          Working...
          X