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

Calculating the average of previous bars.

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

    Calculating the average of previous bars.

    Is there an easy way to calculate the average of N previous bars in a series?

    Say I want the average closing price of the last 20 bars, is there any easier way to do it than (Close[0] + Close[1] + ... + Close[19]) / 20?

    #2
    Hello rcloutier, thanks for your post.

    The SMA indicator will give you the moving average of the price over a set period. See the SampleMACrossover strategy as an example of how to initialize and use an SMA object in a strategy.

    Please let me know if I can assist any further.
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      Okay sure but what about the median instead of the average? Regarding the average, I was hoping for something like Average(Close, 20) but if the way to do that in a strategy is to use SMA(Close, 20), I'm guessing there isn't a "Simple Moving Median" indicator? Is there?

      Comment


        #4
        Hi rcloutier, thanks for your reply.

        There is not an indicator but there is a Median price series that you can reference:

        https://ninjatrader.com/support/help...t8/?median.htm

        You will access this series just like you would the Close, Open, High, Low series e.g. Median[0]

        Please let me know if I can assist any further.
        Chris L.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by sidlercom80, 10-28-2023, 08:49 AM
        172 responses
        2,278 views
        0 likes
        Last Post sidlercom80  
        Started by Irukandji, Yesterday, 02:53 AM
        2 responses
        17 views
        0 likes
        Last Post Irukandji  
        Started by adeelshahzad, Today, 03:54 AM
        0 responses
        3 views
        0 likes
        Last Post adeelshahzad  
        Started by CortexZenUSA, Today, 12:53 AM
        0 responses
        3 views
        0 likes
        Last Post CortexZenUSA  
        Started by CortexZenUSA, Today, 12:46 AM
        0 responses
        1 view
        0 likes
        Last Post CortexZenUSA  
        Working...
        X