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

Daily ATR plot on 30 Min Chart

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

    Daily ATR plot on 30 Min Chart

    I've seen this posted a couple times but haven't found an answer that has worked to solve my issue. I'm trying to plot the daily ATR range on a 30 minute NQ 12-20 chart. To keep it simple, if the NQ 12-20 was trading at 10,000 on a 30 minute chart but had a daily ATR of 300 then I would want lines plotted at 10,300 and 9,700.

    The current code I'm using is attached. If I use else if (BarsinProgress == 0) then I get the upper and lower ATR ranges just for the 30 minute chart only which makes sense. However if I change that to (BarsinProgress == 1) in order to get the daily series then nothing shows up in the chart except for the original price series.

    I'm using the @ATR math that comes with NT8. I've also commented out Print statements that I was trying to use as checks with the code.

    Thanks in advance for any/all help.
    Attached Files

    #2
    Hello Jschmelz,

    Thank you for your post.

    It seems that you might be using values that are outside of your BarsInProgress check. This means that the values you are using could be for either BarsInProgress 0 or BarsInProgress 1.

    Something you could do would be to calculate values based on the secondary series in a BarsInProgress 1 check, assign that value to a variable, followed by assigning the variable to plot in BarsInProgress 0.

    For example, first we could create a variable titled 'closeOfAddedDataSeries'. In OnBarUdate we check if BarsInProgress == 1 and assign a value to our variable. Then, we assign the variable to plot in BarsInProgress 0.

    The attached example strategy, PlotCalculatedFromSecondarySeries, demonstrates how this could be accomplished.

    Please keep in mind that when using a daily series you will not get an accurate value until you have enough historical data. For example, you would need at least 14 days of historical data for a 14-period ATR indicator.

    Additionally, you may refer to the help guide linked below for more information.

    BarsInProgress - https://ninjatrader.com/support/help...inprogress.htm

    Multi-TimeFrame and Instruments - https://ninjatrader.com/support/help...nstruments.htm

    Please let us know if we may assist further.
    Attached Files
    Brandon H.NinjaTrader Customer Service

    Comment


      #3
      Brandon - thank you so much! I used your example and finally got it to plot the daily ranges along with the previous day's close. A follow up question with some insight first:

      - I called on ATR(14)[0] within the BarsinProgress == 1 condition and when used on a MES 12-20 chart I'm getting a print value of 81.12. However when I pull up a daily chart and plot ATR from the standard NT indicator list it's giving me a value of 71.6. According to the standard NT8 ATR indicator the last time MES printed in the 80s on a daily chart was back around June/July 2020.

      - When I use Close[0] within the BarsinProgress == 1 condition I get a print value of 3344.75. However when it's plotted on a chart it's actually giving me 3346.

      Any insights into why the two ATR and Close prints may be different?

      I'm attaching my code here for reference along with the print output which includes the current time, ATR, and Close.

      Thanks again!
      Jim
      Attached Files
      Last edited by Jschmelz; 09-29-2020, 09:54 AM.

      Comment


        #4
        Hello Jschmelz,

        Thank you for your note.

        When testing the ATRAttempt2 indicator you attached on a Daily MES 12-20 chart, the ATR prints from your indicator matched when comparing them to the default NinjaTrader ATR indicator values. Additionally, the Close prints also matched the Close values seen in a Data Box window.

        Please see the attached video demonstrating how I tested the ATRAttempt2 indicator. Are you doing anything differently that may cause you to see different results?



        Thanks in advance, I look forward to your reply.

        Brandon H.NinjaTrader Customer Service

        Comment


          #5
          Hey Brandon,

          Thanks for the video - definitely helped me see what you're seeing. When I change the chart to a daily chart as you had in the video then I agree that the numbers do look correct. However, when I change the chart back to the 30 minute then I start to get different values again.

          Attached is a screenshot of my view when I change it back to a 30 minute chart. What's interesting now is that the ATR of 81 that I posted before is now a 74. Much closer to the desired value of 71.6 but still off a touch and not sure why.

          The difference also impacts the ATR ranges for the day. For example, in the attached screenshot, I would have expected the blue line (ATR High) to be 3346 + 71.6 = 3417.60. Instead it's plotting at the +74 value (provided in the screenshot) at 3420.83..

          I think the difference in close results was because I was printing the 30 minute bars initially so we can skip that one.

          Thanks again for your help!
          Jim



          Attached Files

          Comment


            #6
            Hello Jschmelz,

            Thank you for that information.

            In the indicator script you previously attached, I see that you are checking if the added Daily series is being processed using a BarsInProgress check followed by printing the ATR indicator value for that Daily series. This is why the ATR values being printed match the ATR values on a Daily chart but not on a 30-minute chart.

            If you move that section of code to your primary series BarsInProgress check, the ATR value printed in your Output Window will match the default NinjaTrader ATR indicator value. You may see how this is done in the screenshot I have attached below.

            Please let us know if we may further assist.
            Attached Files
            Brandon H.NinjaTrader Customer Service

            Comment


              #7
              Hey Brandon,

              I would think that moving the code down to the CurrentBar == 0 condition would change the daily ATR numbers to 30 minute ATR numbers. I gave your example a go and that's exactly what happened. Main goal was to get the daily ATR ranges on a 30 minute chart to match what the NT ATR indicator would provide on a daily chart.

              Please let me know if I'm missing something here or if you have any other suggestions. Otherwise I'll continue to work on it here on my end.

              Thanks again,
              Jim

              Comment


                #8
                Hello Jscmelz,

                Thank you for your note.

                When you have an added daily series used as the input series for your ATR indicator, the indicator will print values that would match an ATR indicator applied to a chart that uses the same data. What this means is that you could use a daily input series for the ATR indicator on a 30-minute chart and its print values would match values with the same data type and amount and with the same indicator settings.

                We have already confirmed having that section of code in the BarsInProgress == 1 check prints values for the added daily series and matched the NinjaTrader ATR indicator when it is added to a daily chart. This can be seen in the previously posted video link that demonstrates how I tested the ATRAttempt2 indicator.

                When the primary series (BarsInProgress 0) is supplied as the input series to an indicator and the chart is changed to a 30-minute chart the prints from your indicator with a daily input series will not match the values of the NinjaTrader ATR indicator that is applied to a 30-minute chart.

                Additionally, you could directly add indicators to a chart using a hidden data series. Please see the publicly available NinjaTrader video linked below to see how this could be accomplished.

                How to Plot Indicators on Hidden Data Series in NinjaTrader - https://youtu.be/XRGxiO3XW-k

                Please let us know if we may further assist.

                Brandon H.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Perr0Grande, Today, 08:16 PM
                0 responses
                2 views
                0 likes
                Last Post Perr0Grande  
                Started by elderan, Today, 08:03 PM
                0 responses
                5 views
                0 likes
                Last Post elderan
                by elderan
                 
                Started by algospoke, Today, 06:40 PM
                0 responses
                10 views
                0 likes
                Last Post algospoke  
                Started by maybeimnotrader, Today, 05:46 PM
                0 responses
                12 views
                0 likes
                Last Post maybeimnotrader  
                Started by quantismo, Today, 05:13 PM
                0 responses
                7 views
                0 likes
                Last Post quantismo  
                Working...
                X