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

New help to get the average size of the candles in a lookback period

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

    New help to get the average size of the candles in a lookback period

    I am trying to program a Extreme Reversal Candle Stick indicator. And I need to calculate the average size of the candles in a look back period.

    In Thinkorswim, I wrote the script like:
    input length = 50;
    def AverageCandle = Average(Candlesize, length);

    The script will calculate an average Candlesize in a 50 bars look back period from current bar. And then I can use AverageCandle to compare with the current Candle size.

    How can I do that in Ninjas? I can not find a function like "Candlesize" in Ninjas and do not know how to write it.

    Any help will be greatly appreciated.

    #2
    Hello hughred22,
    Thanks for writing in and I am happy to assist you.
    Unfortunately there are no predefined functions in NinjaScript for calculating average candle size. However you can calculate it easily via custom code. A basic code will be like,

    Code:
    double avgCandleSize = (SMA(High, 50)[0] + SMA(Low, 50)[0]) / 2;
    
    double currentCandleSize = (High[0] + Low[0]) / 2;
    Please let me know if I can assist you any further.
    JoydeepNinjaTrader Customer Service

    Comment


      #3
      Thank you for the quick reply. So I see you are using Simple Moving Average to get the 50 period high and 50 period low. But I am not really sure the logic here. Is your code simply like

      Code:
      double avgCandleSize = SMA(High, 50)[0] - SMA(Low, 50)[0];
      double currentCandleSize = High[0] - Low[0];
      Why you have to add them up and divided it by 2?

      Comment


        #4
        Hello hughred22,
        My apologies, the division is redundant.

        You code should fulfill your purpose.

        Please let me know if I can assist you any further.
        JoydeepNinjaTrader Customer Service

        Comment


          #5
          Could you just not use the SMA of Range?

          Comment


            #6
            Hello stocktraderbmp,
            Thanks for your input.

            Yes that is also possible.
            JoydeepNinjaTrader Customer Service

            Comment


              #7
              I am looking for the same exact thing....did you find or develop anything?

              Comment


                #8
                Originally posted by rob3965 View Post
                I am looking for the same exact thing....did you find or develop anything?
                Sorry I don't understand - what exact same thing are you looking for? If its a moving average of range please read the whole post?

                Ben

                Comment


                  #9
                  I may have missed somthing also but I would have thought a 50 ATR would give what you are looking for.

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by f.saeidi, Today, 11:02 AM
                  1 response
                  2 views
                  0 likes
                  Last Post NinjaTrader_BrandonH  
                  Started by geotrades1, Today, 10:02 AM
                  4 responses
                  12 views
                  0 likes
                  Last Post geotrades1  
                  Started by rajendrasubedi2023, Today, 09:50 AM
                  3 responses
                  16 views
                  0 likes
                  Last Post NinjaTrader_BrandonH  
                  Started by lorem, Today, 09:18 AM
                  2 responses
                  11 views
                  0 likes
                  Last Post NinjaTrader_ChelseaB  
                  Started by geddyisodin, Today, 05:20 AM
                  4 responses
                  30 views
                  0 likes
                  Last Post geddyisodin  
                  Working...
                  X