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

Compare ATR and Range

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

    Compare ATR and Range

    Hello,

    I am trying to have a simple indicator which will highligh bar in chart if the bar´s range is bigger than multiple of ATR.

    I have created this simple code:

    protected override void OnBarUpdate()
    {
    double myATR = ATR (14)[1];
    double myRange = Range () [0];

    if ( myRange > (1.35*myATR))

    {
    DrawDiamond("tag1", true, 0, Low[0] - TickSize, Color.Black);
    }

    else
    {
    }

    However nothing is drawn in the chart. Could you kindly point out where did I make a mistake?

    Thank you.

    #2
    Hello kadan, and thank you for your question.

    The documentation for Range() ,



    does not mention whether this Range is a True Range or not. This would have to be a True Range in order to compare it to an Average True Range. However, the documentation does contain a code example in which an Average Range is generated. That is (modified to fit your use case of a 14-period average),

    Code:
    [FONT=Courier New]SMA(Range(), 14)[0][/FONT]
    I would therefore recommend changing

    Code:
    [FONT=Courier New]double myATR = ATR(14)[1];[/FONT]
    to

    Code:
    [FONT=Courier New]double myAR = SMA(Range(), 14)[1];[/FONT]
    Beyond this, I would highly recommend using the Print() command to display the values of either your ATR or AR alongside your Range output, so that you can see visually what is occurring.

    Finally, if none of the above has helped, I would highly recommend commenting out all conditional logic, and simply calling DrawDiamond unconditionally, then comparing to the help guide documentation here,



    Please let us know if there are any other ways we can help.
    Jessica P.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by kadan View Post
      Hello,

      I am trying to have a simple indicator which will highligh bar in chart if the bar´s range is bigger than multiple of ATR.

      I have created this simple code:

      protected override void OnBarUpdate()
      {
      double myATR = ATR (14)[1];
      double myRange = Range () [0];

      if ( myRange > (1.35*myATR))

      {
      DrawDiamond("tag1", true, 0, Low[0] - TickSize, Color.Black);
      }

      else
      {
      }

      However nothing is drawn in the chart. Could you kindly point out where did I make a mistake?

      Thank you.
      The first place to look is in your log, for logged errors. In your case, it is because that line is trying to access bars that do not yet exist at the time.

      cf: http://ninjatrader.com/support/forum...03&postcount=7

      ref: https://www.google.com/search?q="You...injatrader.com

      Comment


        #4
        Hello Jessica and koganam,

        Thanks for your help. Your replies helped me to get, what I wanted.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by bortz, 11-06-2023, 08:04 AM
        47 responses
        1,610 views
        0 likes
        Last Post aligator  
        Started by jaybedreamin, Today, 05:56 PM
        0 responses
        9 views
        0 likes
        Last Post jaybedreamin  
        Started by DJ888, 04-16-2024, 06:09 PM
        6 responses
        19 views
        0 likes
        Last Post DJ888
        by DJ888
         
        Started by Jon17, Today, 04:33 PM
        0 responses
        6 views
        0 likes
        Last Post Jon17
        by Jon17
         
        Started by Javierw.ok, Today, 04:12 PM
        0 responses
        16 views
        0 likes
        Last Post Javierw.ok  
        Working...
        X