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 value versus what is show on screen.

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

    ATR value versus what is show on screen.

    I am developing an indicator to compare the candle size with the ATR, Surprisingly I found that the number that appears in the ATR indicator is not the same shown in the ATR indicator.

    for example, certain candle has a High-Low= 0.75 (Candle size), I look at the ATR and it 0.80 but the printout of the ATR is 0.0089.

    I tried to find a correlation between those values but could not find it, to consecutive ATR values may be 0.160714285714286 and 1.10714285714286 with no significant difference on the candle size.

    thie portion of the code was extracted from ATR indicator

    double trueRange = Math.Max(Math.Abs(low0 - close1), Math.Max(high0 - low0, Math.Abs(high0 - close1)));
    atr = ((Math.Min(CurrentBar + 1, Period) - 1 ) * Value[1] + trueRange) / Math.Min(CurrentBar + 1, Period);

    Output for debugging.

    22/8/2019 12:58:00 p. m. CandleSize: 1.25 ATR Calcation: 0.0892857142857143
    22/8/2019 1:00:00 p. m. CandleSize: 1.25 ATR Calcation: 0.0892857142857143
    22/8/2019 1:02:00 p. m. CandleSize: 1.25 ATR Calculation: 0.0892857142857143

    22/8/2019 12:30:00 p. m. CandleSize: 2.25 ATR Calculation: 0.160714285714286
    22/8/2019 12:31:00 p. m. CandleSize: 2.5 ATR Calculation: 1.10714285714286

    Any clue??
    Thanks in advance, Marcelo

    protected override void OnBarUpdate()
    {
    double high0 = High[0];
    double low0 = Low[0];
    double CandleSize=high0-low0;
    double atr=0;

    if (CurrentBar == 0)
    atr = high0 - low0;
    else
    {
    double close1 = Close[1];
    double trueRange = Math.Max(Math.Abs(low0 - close1), Math.Max(high0 - low0, Math.Abs(high0 - close1)));
    atr = ((Math.Min(CurrentBar + 1, Period) - 1 ) * Value[1] + trueRange) / Math.Min(CurrentBar + 1, Period);
    }
    if(CandleSize > atr * Multiplier)
    {
    Print(Time[0] + " CandleSize: " + CandleSize + " ATR Calculation: " + atr);
    Value[0]=1;
    }
    else
    {
    Value[0]=0;
    }
    }

    #2
    Hi lordvader34, thanks for your post.

    It seems like the code running in your script is not the same as the code running in the ATR indicator. I attached a test script, this initializes an ATR object and prints out the value bar by bar. If you are copy/pasting the ATR code into your indicator, you should instead make an indicator object and use the object as I do in the example.

    Please let me know if I can assist any further with this item.
    Attached Files
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      Thanks a lot Chris, it make sense now!

      Comment


        #4
        Chris another question, how do I convert ATR to Double format? I tried Convert.ToDouble(myATR) but I got an error. thanks!!

        Comment


          #5
          this is the error I get

          Indicator 'SENALATR': Error on calling 'OnBarUpdate' method on bar 1: Unable to cast object of type 'NinjaTrader.NinjaScript.Indicators.ATR' to type 'System.IConvertible'.

          Comment


            #6
            Hello,

            If you want the most recent value of the myATR you must specify a barsago index like so: Convert.ToDouble(myATR[0])

            That would not be needed though since myATR[0] is already a double.
            Chris L.NinjaTrader Customer Service

            Comment


              #7
              My bad Chris, that was the problem. Thanks again!

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by sidlercom80, 10-28-2023, 08:49 AM
              171 responses
              2,273 views
              0 likes
              Last Post QuantKey_Bruce  
              Started by Irukandji, Yesterday, 02:53 AM
              2 responses
              17 views
              0 likes
              Last Post Irukandji  
              Started by adeelshahzad, Today, 03:54 AM
              0 responses
              3 views
              0 likes
              Last Post adeelshahzad  
              Started by CortexZenUSA, Today, 12:53 AM
              0 responses
              3 views
              0 likes
              Last Post CortexZenUSA  
              Started by CortexZenUSA, Today, 12:46 AM
              0 responses
              1 view
              0 likes
              Last Post CortexZenUSA  
              Working...
              X