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() ,

    http://ninjatrader.com/support/helpGuides/nt7/range.htm

    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:
    SMA(Range(), 14)[0]
    I would therefore recommend changing

    Code:
    double myATR = ATR(14)[1];
    to

    Code:
    double myAR = SMA(Range(), 14)[1];
    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,

    http://ninjatrader.com/support/helpG...rawdiamond.htm

    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 rtwave, Today, 01:49 PM
        0 responses
        8 views
        0 likes
        Last Post rtwave
        by rtwave
         
        Started by papaoutai, Today, 08:56 AM
        0 responses
        22 views
        0 likes
        Last Post papaoutai  
        Started by jdspwe, Today, 05:22 AM
        0 responses
        13 views
        0 likes
        Last Post jdspwe
        by jdspwe
         
        Started by JeremuFemstu, Today, 04:49 AM
        0 responses
        16 views
        0 likes
        Last Post JeremuFemstu  
        Started by pjsmith, Today, 04:11 AM
        1 response
        21 views
        0 likes
        Last Post Green Lobster CBD  
        Working...
        X