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

Average / Summation calculation

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

    Average / Summation calculation

    Hello,

    Is there a more efficient way to calculate an average or summation data?
    Currently I'm using this method:
    Code:
    AverageVOL = ((BarVOL[0]) + (BarVOL[1]) + (BarVOL[2]) + (BarVOL[3]) + (BarVOL[4])) / 5 ;
    If using couple bars it's no big deal, but 25+ bars becomes a project.

    Thank you​

    #2
    Take a look at @SMA.cs for some great ideas on how to do this in a general and fast way.
    Bruce DeVault
    QuantKey Trading Vendor Services
    NinjaTrader Ecosystem Vendor - QuantKey

    Comment


      #3
      Hello nzag555,

      I would suggest calling the SMA indicator with a period of 5 and supply this series.

      Print( SMA(BarVOL, 5)[0] );
      Chelsea B.NinjaTrader Customer Service

      Comment


        #4
        Thank you Chelsea.
        Is there a similar method that give summation value instead of the average ?
        I.e
        Code:
        TotalVOL = ((BarVOL[0]) + (BarVOL[1]) + (BarVOL[2]) + (BarVOL[3]) + (BarVOL[4])) ;

        Comment


          #5
          Yes. The function is SUM instead of SMA.
          Bruce DeVault
          QuantKey Trading Vendor Services
          NinjaTrader Ecosystem Vendor - QuantKey

          Comment


            #6
            Hello nzag555,

            Thanks for your note.

            The Sum() method could be used to get a sum of the values taken over a specified period. For example:

            Print( SUM(BarVol, 5)[0] );

            See this help guide page for more information about SUM() and sample code: https://ninjatrader.com/support/help...mation_sum.htm
            Brandon H.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by ETFVoyageur, Today, 07:55 PM
            0 responses
            4 views
            0 likes
            Last Post ETFVoyageur  
            Started by janio973, Today, 07:24 PM
            1 response
            7 views
            0 likes
            Last Post NinjaTrader_Manfred  
            Started by aligator, 01-06-2022, 12:14 PM
            4 responses
            241 views
            0 likes
            Last Post john_44573  
            Started by reynoldsn, Today, 05:56 PM
            0 responses
            12 views
            0 likes
            Last Post reynoldsn  
            Started by bortz, 11-06-2023, 08:04 AM
            51 responses
            1,995 views
            0 likes
            Last Post aligator  
            Working...
            X