Announcement

Collapse
No announcement yet.

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
            <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            601 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            347 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            103 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            559 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            558 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X