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 PrTester, 12-29-2008, 05:27 PM
            131 responses
            96,704 views
            0 likes
            Last Post diegomezhur  
            Started by knowmad, 05-07-2024, 03:52 AM
            6 responses
            63 views
            0 likes
            Last Post knowmad
            by knowmad
             
            Started by xepher101, 05-10-2024, 12:19 PM
            9 responses
            115 views
            0 likes
            Last Post jeronymite  
            Started by tkaboris, Yesterday, 07:53 PM
            0 responses
            6 views
            0 likes
            Last Post tkaboris  
            Started by JGriff5646, 05-19-2024, 05:47 PM
            2 responses
            24 views
            0 likes
            Last Post JGriff5646  
            Working...
            X