Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Newbie: error in the code

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

    Newbie: error in the code

    Hello,

    I just discover the power of Automated Trading with NT but I have a problem with the following code at Condition set 3 where the condition does not go through the compiler... To be clear I with to use a SMA of the absolute value of an oscillator... What is the correct syntax?
    Thanks in advance

    ...

    Condition set 3
    if (SMA(Math.Abs(PriceOscillator(2, 10, 1)),222)[0] >= 0)
    {
    PlaySound("");
    }


    #2
    Hello,

    Is it because Math.Abs() requires a value, not a series.
    For example this compiles:
    double test = Math.Abs(PriceOscillator(2, 10, 1)[0]);
    But this doesn't:
    double test = Math.Abs(PriceOscillator(2, 10, 1));

    For former refers to a value, and the latter refers to a series.
    DenNinjaTrader Customer Service

    Comment


      #3
      Easier Way?

      OK.
      But if Math.Abs() does not accept a series, how to compute a SMA of absolute values of values of an indicator?
      Do I need to use a loop to compute one by one the values such that

      sum=0;
      for (int k = 1; x <= 222; x++)
      {

      sum = sum + Math.Abs(PriceOscillator(2, 10, 1)[k]);
      }
      sum=sum/222;

      or is there any easier way?

      Comment


        #4
        Hello,

        I don't think so. I would create a dataseries to store the absolute values, then use that dataseries in your SMA. This link shows how to create a dataseries:
        DenNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Mindset, 04-21-2026, 06:46 AM
        0 responses
        102 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by M4ndoo, 04-20-2026, 05:21 PM
        0 responses
        144 views
        0 likes
        Last Post M4ndoo
        by M4ndoo
         
        Started by M4ndoo, 04-19-2026, 05:54 PM
        0 responses
        71 views
        0 likes
        Last Post M4ndoo
        by M4ndoo
         
        Started by cmoran13, 04-16-2026, 01:02 PM
        0 responses
        125 views
        0 likes
        Last Post cmoran13  
        Started by PaulMohn, 04-10-2026, 11:11 AM
        0 responses
        79 views
        0 likes
        Last Post PaulMohn  
        Working...
        X