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 argusthome, 03-08-2026, 10:06 AM
        0 responses
        71 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        42 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        25 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        28 views
        0 likes
        Last Post TheRealMorford  
        Started by Mindset, 02-28-2026, 06:16 AM
        0 responses
        56 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Working...
        X