Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Standard indicators and Indicator methods

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

    Standard indicators and Indicator methods

    Can anyone explain why the code for standard indicators like SMA in Ninja do not conform to the equivalent Indicator Method in Ninja.

    For example,

    Indicator method SMA:
    Examples



    // Prints the current value of a 20 period SMA using default price type
    double value = SMA(20)[0];
    Print("The current SMA value is " + value.ToString());

    In Ninja script for SMA however the code does not appear to use the SMA method but has the following code. Why doesn't it just use the SMA Indicator Method?

    {
    if (CurrentBar == 0)
    Value.Set(Input[
    0]);
    else
    {
    double last = Value[1] * Math.Min(CurrentBar, Period);
    if (CurrentBar >= Period)
    Value.Set((last + Input[
    0] - Input[Period]) / Math.Min(CurrentBar, Period));
    else
    Value.Set((last + Input[0]) / (Math.Min(CurrentBar, Period) + 1));
    }
    }

    #2
    The example is a usage of SMA. The code below the example is how the SMA is created.

    Comment


      #3
      Hello skiguy,

      Thank you for your post.

      Tasker is correct here, the method is SMA() and the code for the SMA is needed to actual calculate the SMA() value.

      Comment


        #4
        Thanks guys. I thought that might be the case.

        In summary, the SMA method behind the scenes uses the code shown and this also applies to other indicator methods.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by CarlTrading, 03-31-2026, 09:41 PM
        1 response
        83 views
        1 like
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 04-01-2026, 02:41 AM
        0 responses
        45 views
        0 likes
        Last Post CarlTrading  
        Started by CaptainJack, 03-31-2026, 11:44 PM
        0 responses
        65 views
        2 likes
        Last Post CaptainJack  
        Started by CarlTrading, 03-30-2026, 11:51 AM
        0 responses
        68 views
        0 likes
        Last Post CarlTrading  
        Started by CarlTrading, 03-30-2026, 11:48 AM
        0 responses
        57 views
        0 likes
        Last Post CarlTrading  
        Working...
        X