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 timmbbo, Today, 08:59 AM
        1 response
        2 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by KennyK, 05-29-2017, 02:02 AM
        2 responses
        1,281 views
        0 likes
        Last Post marcus2300  
        Started by fernandobr, Today, 09:11 AM
        0 responses
        3 views
        0 likes
        Last Post fernandobr  
        Started by itrader46, Today, 09:04 AM
        1 response
        6 views
        0 likes
        Last Post NinjaTrader_Clayton  
        Started by bmartz, 03-12-2024, 06:12 AM
        5 responses
        33 views
        0 likes
        Last Post NinjaTrader_Zachary  
        Working...
        X