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 mattbsea, Today, 05:44 PM
    0 responses
    3 views
    0 likes
    Last Post mattbsea  
    Started by RideMe, 04-07-2024, 04:54 PM
    6 responses
    31 views
    0 likes
    Last Post RideMe
    by RideMe
     
    Started by tkaboris, Today, 05:13 PM
    0 responses
    2 views
    0 likes
    Last Post tkaboris  
    Started by GussJ, 03-04-2020, 03:11 PM
    16 responses
    3,282 views
    0 likes
    Last Post Leafcutter  
    Started by WHICKED, Today, 12:45 PM
    2 responses
    20 views
    0 likes
    Last Post WHICKED
    by WHICKED
     
    Working...
    X