Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Help to understand errors from SUM function.

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

    Help to understand errors from SUM function.

    Hello,

    I am trying to convert a TradingView indicator into NinjaScript so I can use it in a NinjaTrader strategy, this is the indicator https://www.tradingview.com/script/h...o-OPEN-SOURCE/.

    I am having trouble converting this particular section of code...
    Code:
    math.sum(avpch * avpch, blength)
    blength is an integer and avpch is the value of the Arnaud Legoux Moving Average (ALMA) indicator (which I've got a NinjaScript version from here https://forum.ninjatrader.com/forum/...rom-nt7-to-nt8). This line of code is essentially summing the 'avpch * avpch' ALMA indicator values for each candle within the blength look back period.

    math.sum is not available to use in NinjaScript therefore I think the NinjaScript conversion of this code is
    Code:
    SUM(avpch * avpch, blength)[0]
    but this is an indicator, not a math function.

    I am bringing in the ALMA indicator values by inserting this into (State == State.DataLoaded)
    Code:
    ALMA1 = ALMA(Close);
    and assigning the value to a new variable
    Code:
    double avpch = ALMA1[0];
    When I try to compile the code I receive two errors:
    • The best overloaded method match for 'NinjaTrader.NinjaScript.Indicators.Indicator.SUM( NinjaTrader.NinjaScript.ISeries<double>, int)' has some invalid arguments; and
    • Argument 1: cannot convert from 'double' to 'NinjaTrader.NinjaScript.ISeries<double>'
    Can you shed​ any light on the suitability of my code and how I can resolve the errors or is there another way to convert this code into NinjaScript?

    Thanks in advance.

    Neil

    #2
    Hello burtoninlondon,

    Math.Sum() would be a C# method used to sum an array of values. This is available in NinjaScript which is written in C#.

    Below is a link to the Microsoft documentation.
    https://learn.microsoft.com/en-us/do...ramework-4.8.1

    SUM() is a NinjaTrader indicator that sums a Series<double> (like a plot).

    Below is a link to the help guide.
    https://ninjatrader.com/support/help...mation_sum.htm

    You would need to put the values in a series to use this with the SUM() indicator.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thanks NinjaTrader_ChelseaB...but unfortunately I can't use Math.Sum() as I receive an error stating that ''System Math' does not contain a definition for 'Sum'' and there isn't an option for 'Sum' in the selection window when I type Math...

      Hopefully this image will help...

      ​​Click image for larger version

Name:	image.png
Views:	228
Size:	112.0 KB
ID:	1257933

      Comment


        #4
        Hello burtoninlondon,

        Apologies that would be <Enumerable>.Sum, such as from an array or list.

        MyArrayVariableName.Sum()
        Chelsea B.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        587 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        341 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
        555 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        552 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X