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

SMA Indicator on a Custom Value

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

    SMA Indicator on a Custom Value

    Wazzzz Up Dawg'z (the Urbanly correct way of addressing a community)!



    I have a simple question and please excuse my lack of knowledge (not a high school or middle school grad). Programming is a big challenge not knowing proper terms in math!



    There is a formula and it needs to get adjustable to so many bars back by a length input. I get very basic programming concepts. For example how do I add a length to a formula like “High – Low”. For a average true range? Let’s say I wanted to get the average true range for the last five bars? This is what I have now and need to adjust it….

    ///<summary>
    /// Called on each bar update event (incoming tick)
    ///</summary>
    protectedoverridevoid OnBarUpdate()
    {
    // Use this method for calculating your indicator values. Assign a value to each
    // Use this method for calculating your indicator values. Assign a value to each
    double avgrange = (High[0] - Low[0]);


    // plot below by replacing 'Close[0]' with your own formula.
    RangePlot.Set(avgrange);
    }
    What or how do I write a average for this? I already have a length input but don’t know how to apply it.


    Word!

    #2
    Welcome to our forums - the SMA method / indicator expects to get passed in a DataSeries, what you've calculated now is just a double value. So you would need to first create a custom series for your double value and then you could calculate for example the 5 bar SMA value using your Length input.

    There's a full example for your exact case shown here in our helpguide -

    BertrandNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by bortz, 11-06-2023, 08:04 AM
    47 responses
    1,607 views
    0 likes
    Last Post aligator  
    Started by jaybedreamin, Today, 05:56 PM
    0 responses
    9 views
    0 likes
    Last Post jaybedreamin  
    Started by DJ888, 04-16-2024, 06:09 PM
    6 responses
    19 views
    0 likes
    Last Post DJ888
    by DJ888
     
    Started by Jon17, Today, 04:33 PM
    0 responses
    6 views
    0 likes
    Last Post Jon17
    by Jon17
     
    Started by Javierw.ok, Today, 04:12 PM
    0 responses
    15 views
    0 likes
    Last Post Javierw.ok  
    Working...
    X