Announcement

Collapse
No announcement yet.

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 -

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by CarlTrading, 03-31-2026, 09:41 PM
    1 response
    133 views
    1 like
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 04-01-2026, 02:41 AM
    0 responses
    75 views
    1 like
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    117 views
    2 likes
    Last Post CaptainJack  
    Started by CarlTrading, 03-30-2026, 11:51 AM
    0 responses
    113 views
    1 like
    Last Post CarlTrading  
    Started by CarlTrading, 03-30-2026, 11:48 AM
    0 responses
    90 views
    0 likes
    Last Post CarlTrading  
    Working...
    X