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 unexpected result

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

    ATR unexpected result

    I have created a dataseries (hCloses) in my multi Series strategy ( 10min (primary) and 1 Tick(secondary)). The dataSeries is the same as Cloeses[0] apart from the Value[0] of the data series that is set to Closes[1]:-
    Code:
    if(BarsInProgress == 0)
    				{
    					hClose.Set(1,Close[1]);
    				}
    				
    				if(BarsInProgress == 1 && CurrentBars[baseBars] > 1)
    				{
    					hClose.Set(Closes[1][0]);
                                    }

    I have verified the that both series are as expected by printing to the output window.

    So the problem I am having is when I call a 20 period ATR on my data-series I dont get the result expected. It is approximately half what it should be,

    When I compair ATR(Closes[0], 20)[0] & ATR(hClose, 20)[0] here is a sample of what I get with the inputs to them:-



    ***********
    ***********
    Current 1 Tick Bar 537582 ATR last 20 Closes 164.32 164.31 164.25 164.21 164.21 164.23 164.2 164.19 164.18 164.2 164.2 164.23 164.22 164.25 164.29 164.35 164.28 164.31 164.3 164.31
    Current 1 Tick Bar 537582 ATR last 20 hClose 164.31 164.31 164.25 164.21 164.21 164.23 164.2 164.19 164.18 164.2 164.2 164.23 164.22 164.25 164.29 164.35 164.28 164.31 164.3 164.31

    ATR 0.0730076458405191
    ATR hCLose 0.0365543132310812
    ***********
    ***********
    Current 1 Tick Bar 537583 ATR last 20 Closes 164.32 164.31 164.25 164.21 164.21 164.23 164.2 164.19 164.18 164.2 164.2 164.23 164.22 164.25 164.29 164.35 164.28 164.31 164.3 164.31
    Current 1 Tick Bar 537583 ATR last 20 hClose 164.32 164.31 164.25 164.21 164.21 164.23 164.2 164.19 164.18 164.2 164.2 164.23 164.22 164.25 164.29 164.35 164.28 164.31 164.3 164.31

    ATR 0.0730076458405191
    ATR hCLose 0.0365543132310812
    ***********
    ***********

    I cant figure out why they would be different ?

    #2
    Originally posted by GKonheiser View Post
    I have created a dataseries (hCloses) in my multi Series strategy ( 10min (primary) and 1 Tick(secondary)). The dataSeries is the same as Cloeses[0] apart from the Value[0] of the data series that is set to Closes[1]:-
    Code:
    if(BarsInProgress == 0)
    				{
    					hClose.Set(1,Close[1]);
    				}
    				
    				if(BarsInProgress == 1 && CurrentBars[baseBars] > 1)
    				{
    					hClose.Set(Closes[1][0]);
                                    }

    I have verified the that both series are as expected by printing to the output window.

    So the problem I am having is when I call a 20 period ATR on my data-series I dont get the result expected. It is approximately half what it should be,

    When I compair ATR(Closes[0], 20)[0] & ATR(hClose, 20)[0] here is a sample of what I get with the inputs to them:-



    ***********
    ***********
    Current 1 Tick Bar 537582 ATR last 20 Closes 164.32 164.31 164.25 164.21 164.21 164.23 164.2 164.19 164.18 164.2 164.2 164.23 164.22 164.25 164.29 164.35 164.28 164.31 164.3 164.31
    Current 1 Tick Bar 537582 ATR last 20 hClose 164.31 164.31 164.25 164.21 164.21 164.23 164.2 164.19 164.18 164.2 164.2 164.23 164.22 164.25 164.29 164.35 164.28 164.31 164.3 164.31

    ATR 0.0730076458405191
    ATR hCLose 0.0365543132310812
    ***********
    ***********
    Current 1 Tick Bar 537583 ATR last 20 Closes 164.32 164.31 164.25 164.21 164.21 164.23 164.2 164.19 164.18 164.2 164.2 164.23 164.22 164.25 164.29 164.35 164.28 164.31 164.3 164.31
    Current 1 Tick Bar 537583 ATR last 20 hClose 164.32 164.31 164.25 164.21 164.21 164.23 164.2 164.19 164.18 164.2 164.2 164.23 164.22 164.25 164.29 164.35 164.28 164.31 164.3 164.31

    ATR 0.0730076458405191
    ATR hCLose 0.0365543132310812
    ***********
    ***********

    I cant figure out why they would be different ?
    You are resetting your hClose, so hClose[0] != Closes[0]. Ergo, things calculated on those series and indexed at zero will usually be different values.

    Comment


      #3
      Hi koganam,

      not sure I follow. I am resetting the value at index 0 when there is an 1 tick series changes but the it is then fixed to the close of the 10min series once it has closed.

      You can see above the outputs from the two series. They are identical apart from index 1 , as I want, but it doesnt explain the massive difference in the 2 ATRs.

      But ive been thinking about it and obviously the ATR uses Highs and Lows for Calculation. If I am basing my ATR on my series , hClose, what high and low is it using?

      Comment


        #4
        Originally posted by GKonheiser View Post
        Hi koganam,

        not sure I follow. I am resetting the value at index 0 when there is an 1 tick series changes but the it is then fixed to the close of the 10min series once it has closed.

        You can see above the outputs from the two series. They are identical apart from index 1 , as I want, but it doesnt explain the massive difference in the 2 ATRs.

        But ive been thinking about it and obviously the ATR uses Highs and Lows for Calculation. If I am basing my ATR on my series , hClose, what high and low is it using?
        If you use a DataSeries as an input to an indicator, all Input is the value of the DataSeries. Therefore, in this particular case, as the NT ATR uses Wilder's Average, you are in effect calculating the Wilder's Average of the Close.
        Last edited by koganam; 02-14-2016, 02:14 PM.

        Comment


          #5
          So if I understand you correctly then when Closes[0] ( just for example) is passed to an indictor that needs also the high and the low, then it uses Hights[0] and Lows[0], is that what you mean ?

          I thought that Highs[0] would be one data series and Lows[0] would be another?

          So when you pass Closes[0] to the ATR say, it is calculating the atr based on the highs and the lows of that data series right ?

          If that is the case how are Closes[0] and Highs[0] and Lows[0] etc.. linked ?
          Last edited by GKonheiser; 02-14-2016, 02:21 PM.

          Comment


            #6
            Originally posted by GKonheiser View Post
            So if I understand you correctly then when Closes[0] ( just for example) is passed to an indictor that needs also the high and the low, then it uses Hights[0] and Lows[0], is that what you mean ?

            I thought that Highs[0] would be one data series and Lows[0] would be another?

            So when you pass Closes[0] to the ATR say, it is calculating the atr based on the highs and the lows of that data series right ?

            If that is the case how are Closes[0] and Highs[0] and Lows[0] etc.. linked ?
            No. A BarsArray is different from a DataSeries. A DataSeries has only one value per bar, so no matter what you use as Input in an indicator, if you pass the indicator a DataSeries for input, then the Input used by the indicator will identically be the value of the DataSeries. So regardless what references the indicator uses: Open, High, Close or Low, the indicator will use the value of the DataSeries for all of them. After all, the DataSeries, does not have any OHCL data, just a single value at any data point.
            Last edited by koganam; 02-14-2016, 06:42 PM.

            Comment


              #7
              OK got it. So the best thing to do is write my own method for this I think. Thanks very much for your help , I have leaned something new.

              Is it possible to create your own Bars Array?

              Comment


                #8
                Originally posted by GKonheiser View Post
                OK got it. So the best thing to do is write my own method for this I think. Thanks very much for your help , I have leaned something new.

                Is it possible to create your own Bars Array?
                Not in NT7. At least not without some serious undocumented stuff. And you should not need to do so for what you are doing. You have a BarsArray simply by declaring one. Your current code has 2 of them: the one associated with the time frame for the chart, and the one that you declared,

                For processing purposes you could always declare any number of DataSeries to hold what you want to process and go from there. After all, a BarSeries does amalgamate 4 DataSeries into one object. You can construct your own object any way that you want to do.

                Comment


                  #9
                  Yes exactly there are many ways to do it. Thanks again for the help, I understand now completely why it wont work as you have outlined the difference between a BarsArray and a Dataseries.

                  Comment


                    #10
                    Thank you for helping out GKonheiser with their questions, koganam.

                    For any one else reading through this thread, koganam is correct in pointing out that the DataSeries used would not include High or Low values as it was not a BarsArray and a BarsArray could not be created in the supported realm of NinjaScript.

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by mgco4you, Today, 09:46 PM
                    1 response
                    3 views
                    0 likes
                    Last Post NinjaTrader_Manfred  
                    Started by wzgy0920, Today, 09:53 PM
                    0 responses
                    4 views
                    0 likes
                    Last Post wzgy0920  
                    Started by Rapine Heihei, Today, 08:19 PM
                    1 response
                    8 views
                    0 likes
                    Last Post NinjaTrader_Manfred  
                    Started by Rapine Heihei, Today, 08:25 PM
                    0 responses
                    6 views
                    0 likes
                    Last Post Rapine Heihei  
                    Started by f.saeidi, Today, 08:01 PM
                    1 response
                    9 views
                    0 likes
                    Last Post NinjaTrader_Manfred  
                    Working...
                    X