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 Torontobluejays, Today, 08:43 AM
            0 responses
            1 view
            0 likes
            Last Post Torontobluejays  
            Started by sastrades, 01-31-2024, 10:19 PM
            12 responses
            190 views
            0 likes
            Last Post sastrades  
            Started by Jimmyk, 01-26-2018, 05:19 AM
            8 responses
            864 views
            0 likes
            Last Post emuns
            by emuns
             
            Started by giulyko00, 04-24-2024, 12:03 PM
            6 responses
            29 views
            0 likes
            Last Post giulyko00  
            Started by 00nevest, 04-27-2024, 02:27 PM
            3 responses
            27 views
            0 likes
            Last Post 00nevest  
            Working...
            X