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

Working with ADX

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

    Working with ADX

    I'm trying to build an indicator using ADX and am having trouble figuring out the value that is getting populated into my variable. The issue is ADX(14)[0] isn't giving me the same value as the value that is plotted when I call the ADX indicator that comes packaged with NT.

    I have:
    if (CurrentBar < 22) return;
    at the top of OnBarUpdate

    I have tried:
    double ADXvariable = 0; (in variables)

    and:
    ADXvariable = ADX(14)[0]; (in OnBarUpdate)

    I also tried creating a DataSeries to hold the values:

    private DataSeries ADXvalue; (variable)
    ADXvalue.Set(ADX(14)[0]); (OnBarUpdate)

    both of calculations return a value of 24.30 for IWM for today with CalculateOnBarClose = false (daily)

    But, when I add the packaged ADX indicator onto my chart, period 14, with CalculateOnBarClose = false, the indicator says the value is 31.14.

    Thoughts?




    #2
    Hi Grasul, from where do you run your custom study? From another chart or the Market Analyzer? Usually those differences stem from not having enough bars / data loaded (50 bars default for MA), so calculations haven't yet fully caught up.
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Thank you for the reply.

      I am just in the first step of creating a new indicator. I can't copy and paste my code from here, but all the indicator does at the moment is if ADX < 20, it turns a flag to yes and starts drawing a dot, and then when ADX goes above 25 it swaps the flag and stops drawing the dots. This is all internal to a single indicator on a single time frame.

      All I want is an ADX value I can trust is correct to use in if statements for the flag swapping above.

      Should I set

      if (CurrentBar < 22) return;

      to a higher value maybe?

      Comment


        #4
        Thanks Grasul, I would ignore the current bars check for now and focus on how much days you give your indicator to load. It would be good to know from which chart it is exactly run to comment further. The CurrentBar check would be trimmed to the highest index back you try to access, as otherwise you would run into issues on the first bars of the chart, where a reference to the left simply would not exist then.
        BertrandNinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_Bertrand View Post
          It would be good to know from which chart it is exactly run to comment further.
          I don't understand the question; I'm sorry. I am writing a custom indicator. I declare a variable and then as the first action after the CurrentBar check I am setting the value of the variable:

          double ADXvariable =0; (in variables)
          ADXvariable = ADX(14)[0]; (in OnBarUpdate)

          When I DrawText the value of ADXvariable and compare it to the value of ADX when I just add the packaged ADX indicator to the chart, I have different values. (Both my custom indicator and the packaged ADX indicator have CalculateOnBarClose set to false because I am working with daily values in the evening.)

          Comment


            #6
            Thanks for clarifying, so you run this from the exact same chart the default NT ADX is on as well? I gave it a run on your IWM on Kinetick daily bars and cannot reproduce any issue, the simply test script is attached, all I'm doing is plotting your ADX value from the method call. Would this script also return a different output for the 2 ADX's for you?
            Attached Files
            BertrandNinjaTrader Customer Service

            Comment


              #7
              I won't be able to check what you sent until this evening Bertrand, but thanks for your help. I will compare what you sent to my code this evening.

              Comment


                #8
                Ok, sounds good, please let us know what your outcome in later testing is.
                BertrandNinjaTrader Customer Service

                Comment


                  #9
                  I can't seem to replicate the issue I was having last night either. Thank you very much for your help; the sample works perfectly. My apologies for the wild goose chase.

                  Comment


                    #10
                    No worries, thanks for providing the update.
                    BertrandNinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by usazencort, Today, 01:16 AM
                    0 responses
                    1 view
                    0 likes
                    Last Post usazencort  
                    Started by kaywai, 09-01-2023, 08:44 PM
                    5 responses
                    603 views
                    0 likes
                    Last Post NinjaTrader_Jason  
                    Started by xiinteractive, 04-09-2024, 08:08 AM
                    6 responses
                    22 views
                    0 likes
                    Last Post xiinteractive  
                    Started by Pattontje, Yesterday, 02:10 PM
                    2 responses
                    21 views
                    0 likes
                    Last Post Pattontje  
                    Started by flybuzz, 04-21-2024, 04:07 PM
                    17 responses
                    230 views
                    0 likes
                    Last Post TradingLoss  
                    Working...
                    X