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 SalmaTrader, 07-07-2026, 10:26 PM
    0 responses
    42 views
    0 likes
    Last Post SalmaTrader  
    Started by CarlTrading, 07-05-2026, 01:16 PM
    0 responses
    20 views
    0 likes
    Last Post CarlTrading  
    Started by CaptainJack, 06-17-2026, 10:32 AM
    0 responses
    14 views
    0 likes
    Last Post CaptainJack  
    Started by kinfxhk, 06-17-2026, 04:15 AM
    0 responses
    20 views
    0 likes
    Last Post kinfxhk
    by kinfxhk
     
    Started by kinfxhk, 06-17-2026, 04:06 AM
    0 responses
    22 views
    0 likes
    Last Post kinfxhk
    by kinfxhk
     
    Working...
    X