Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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 llanqui, Today, 03:53 AM
        0 responses
        6 views
        0 likes
        Last Post llanqui
        by llanqui
         
        Started by burtoninlondon, Today, 12:38 AM
        0 responses
        10 views
        0 likes
        Last Post burtoninlondon  
        Started by AaronKoRn, Yesterday, 09:49 PM
        0 responses
        15 views
        0 likes
        Last Post AaronKoRn  
        Started by carnitron, Yesterday, 08:42 PM
        0 responses
        11 views
        0 likes
        Last Post carnitron  
        Started by strategist007, Yesterday, 07:51 PM
        0 responses
        14 views
        0 likes
        Last Post strategist007  
        Working...
        X