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 andrewtrades, Today, 04:57 PM
        1 response
        9 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Started by chbruno, Today, 04:10 PM
        0 responses
        6 views
        0 likes
        Last Post chbruno
        by chbruno
         
        Started by josh18955, 03-25-2023, 11:16 AM
        6 responses
        436 views
        0 likes
        Last Post Delerium  
        Started by FAQtrader, Today, 03:35 PM
        0 responses
        8 views
        0 likes
        Last Post FAQtrader  
        Started by rocketman7, Today, 09:41 AM
        5 responses
        19 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Working...
        X