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 selu72, Today, 02:01 PM
        1 response
        7 views
        0 likes
        Last Post NinjaTrader_Zachary  
        Started by WHICKED, Today, 02:02 PM
        2 responses
        11 views
        0 likes
        Last Post WHICKED
        by WHICKED
         
        Started by f.saeidi, Today, 12:14 PM
        8 responses
        21 views
        0 likes
        Last Post f.saeidi  
        Started by Mikey_, 03-23-2024, 05:59 PM
        3 responses
        51 views
        0 likes
        Last Post Sam2515
        by Sam2515
         
        Started by Russ Moreland, Today, 12:54 PM
        1 response
        8 views
        0 likes
        Last Post NinjaTrader_Erick  
        Working...
        X