Slow RSI of J M Wilder’s Version

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #252365 quote
    ma77art
    Participant
    New

    Hi I have this code from Ninjatrader 8  for Slow RSI Wilder’s version,  I am wondering if you could please translate into Prorealtime:

    #region Using declarations
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Xml.Serialization;
    using NinjaTrader.Cbi;
    using NinjaTrader.Gui;
    using NinjaTrader.Gui.Chart;
    using NinjaTrader.Gui.SuperDom;
    using NinjaTrader.Gui.Tools;
    using NinjaTrader.Data;
    using NinjaTrader.NinjaScript;
    using NinjaTrader.Core.FloatingPoint;
    using NinjaTrader.NinjaScript.DrawingTools;
    #endregion

    //This namespace holds Indicators in this folder and is required. Do not change it.
    namespace NinjaTrader.NinjaScript.Indicators
    {

    [Gui.CategoryOrder(“Parameters”, 1)]

    public class srsi : Indicator
    {

    #region Variables
    // Wizard generated variables
    private int period = 14; // Default setting for Period
    private int emaperiod = 6; // Default setting for Emaperiod
    // User defined variables (add any user defined variables below)
    private Series<double> SRSI; //The SRSI measures the strength of a security relative to a sixday EMA
    private Series<double> srs;
    private Series<double> Averagepositivedifference;
    private Series<double> Averagenegativedifference;
    private Series<double> positivedifference;
    private Series<double> negativedifference;
    private Series<double> wEMA;
    #endregion

    protected override void OnStateChange()
    {
    /// <summary>
    /// J. Welles Wilder’s classic relative strength index has enjoyed a large following of technical analysts over the years. Here’s a slow version of it.
    /// </summary>

    if (State == State.SetDefaults)
    {
    Description = @”J. Welles Wilder’s classic relative strength index has enjoyed a large following of technical analysts over the years. Here’s a slow version of it.”;
    Name = “srsi”;
    Calculate = Calculate.OnBarClose;
    IsOverlay = false;
    DisplayInDataBox = true;
    DrawOnPricePanel = true;
    DrawHorizontalGridLines = true;
    DrawVerticalGridLines = true;
    PaintPriceMarkers = true;
    ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
    //Disable this property if your indicator requires custom values that cumulate with each new market data event.
    //See Help Guide for additional information.
    IsSuspendedWhileInactive = true;
    }
    else if (State == State.Configure)
    {

    SRSI = new Series<double>(this); //The SRSI measures the strength of a security relative to a sixday EMA
    srs = new Series<double>(this);
    Averagepositivedifference = new Series<double>(this, MaximumBarsLookBack.Infinite);
    Averagenegativedifference = new Series<double>(this, MaximumBarsLookBack.Infinite);
    positivedifference = new Series<double>(this, MaximumBarsLookBack.Infinite);
    negativedifference = new Series<double>(this, MaximumBarsLookBack.Infinite);
    wEMA = new Series<double>(this, MaximumBarsLookBack.Infinite);

    AddPlot(Brushes.Orange, “SRSIPlot0”);
    AddPlot(Brushes.Green, “EmaSRSI”);

    }
    }

    protected override void OnBarUpdate()
    {
    //Add your custom indicator logic here.

    // Use this method for calculating your indicator values. Assign a value to each
    // plot below by replacing ‘Close[0]’ with your own formula.

    /*
    WEMA formula= price today * K + EMA yesterday * (1-K) where K = 2 / (N+1)

    Wilder EMA formula = price today * K + EMA yesterday (1-K) where K =1/N

    Where N = the number of periods.
    */

    double k=2/(emaperiod +1);

    wEMA[0] = Close[0]*k+EMA(Close,emaperiod-1)[0]*(1-k);
    //float positive_diff=(Close[0]-wEMA[0]);
    //float negative_diff=(wEMA[0]+Close[0]);
    if(Close[0]>EMA(Close,emaperiod)[0])
    positivedifference[0] = Close[0]-EMA(Close,2*(emaperiod)-1)[0];
    else
    negativedifference[0] = EMA(Close,2*(emaperiod)-1)[0]-Close[0];

    //if(positivedifference[0]>=0)
    Averagepositivedifference[0] = EMA(positivedifference,2*period-1)[0];

    //if(negativedifference[0]>=0)
    Averagenegativedifference[0] = EMA(negativedifference,2*period-1)[0];

    if(Averagenegativedifference[0]!=0)
    {
    srs[0] = Averagepositivedifference[0]/Averagenegativedifference[0];

    SRSI[0] = 100 – (100/(1+srs[0]));
    }
    else
    {
    SRSI[0] = SRSI.GetValueAt(1);
    }

    SRSIPlot0[0] = SRSI[0];

    EmaSRSI[0] = EMA(SRSI,2)[0];
    }

    #region Properties
    [Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
    [XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
    public Series<double> SRSIPlot0
    {
    get { return Values[0]; }
    }

    [Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
    [XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
    public Series<double> EmaSRSI
    {
    get { return Values[1]; }
    }

    [NinjaScriptProperty]
    [RefreshProperties(RefreshProperties.All)]
    [Display(Name=”Period”, Description=”srsi period”, Order=1, GroupName=”Parameters”)]
    public int Period
    {
    get { return period; }
    set { period = Math.Max(2, value); }
    }

    [NinjaScriptProperty]
    [RefreshProperties(RefreshProperties.All)]
    [Display(Name=”Emaperiod”, Description=”ema period”, Order=2, GroupName=”Parameters”)]
    public int Emaperiod
    {
    get { return emaperiod; }
    set { emaperiod = Math.Max(1, value); }
    }
    #endregion

    }
    }

    #region NinjaScript generated code. Neither change nor remove.

    namespace NinjaTrader.NinjaScript.Indicators
    {
    public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
    {
    private srsi[] cachesrsi;
    public srsi srsi(int period, int emaperiod)
    {
    return srsi(Input, period, emaperiod);
    }

    public srsi srsi(ISeries<double> input, int period, int emaperiod)
    {
    if (cachesrsi != null)
    for (int idx = 0; idx < cachesrsi.Length; idx++)
    if (cachesrsi[idx] != null && cachesrsi[idx].Period == period && cachesrsi[idx].Emaperiod == emaperiod && cachesrsi[idx].EqualsInput(input))
    return cachesrsi[idx];
    return CacheIndicator<srsi>(new srsi(){ Period = period, Emaperiod = emaperiod }, input, ref cachesrsi);
    }
    }
    }

    namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
    {
    public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
    {
    public Indicators.srsi srsi(int period, int emaperiod)
    {
    return indicator.srsi(Input, period, emaperiod);
    }

    public Indicators.srsi srsi(ISeries<double> input , int period, int emaperiod)
    {
    return indicator.srsi(input, period, emaperiod);
    }
    }
    }

    namespace NinjaTrader.NinjaScript.Strategies
    {
    public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
    {
    public Indicators.srsi srsi(int period, int emaperiod)
    {
    return indicator.srsi(Input, period, emaperiod);
    }

    public Indicators.srsi srsi(ISeries<double> input , int period, int emaperiod)
    {
    return indicator.srsi(input, period, emaperiod);
    }
    }
    }

    #endregion

    SRSI.jpg SRSI.jpg
    #252457 quote
    Iván González
    Moderator
    Master

    here you have

    // ============================================================
    // PRC_Slow Relative Strength Index (srsi)
    // version = 1
    // 10.10.2025
    // Iván González @ www.prorealcode.com
    // Sharing ProRealTime knowledge
    // ============================================================
    // ==================== PARÁMETROS DE USUARIO =================
    period = 14       // Período del RSI lento
    emaPeriod = 6     // Período de la EMA de referencia
    signalPeriod = 2  // Período de la EMA del SRSI (línea de señal)
    // ==================== CÁLCULOS DEL INDICADOR ================
    // 1. Determinar las diferencias positivas y negativas
    emaRef = ExponentialAverage[emaPeriod](close)
    emaDiff = ExponentialAverage[2 * emaPeriod - 1](close)
    
    IF close > emaRef THEN
       positiveDifference = close - emaDiff
       negativeDifference = 0
    ELSE
       positiveDifference = 0
       negativeDifference = emaDiff - close
    ENDIF
    // 2. Suavizar las diferencias con una EMA (similar al método de Wilder)
    avgPositiveDifference = ExponentialAverage[2 * period - 1](positiveDifference)
    avgNegativeDifference = ExponentialAverage[2 * period - 1](negativeDifference)
    // 3. Calcular el srs (Slow Relative Strength) y el SRSI
    srs = 0
    IF avgNegativeDifference <> 0 THEN
       srs = avgPositiveDifference / avgNegativeDifference
    ENDIF
    
    SRSI = 100 - (100 / (1 + srs))
    
    // 4. Calcular una línea de señal para el SRSI
    emaSRSI = ExponentialAverage[signalPeriod](SRSI)
    
    // ================================================
    RETURN SRSI COLOURED(255,165,0) AS "SRSI", emaSRSI COLOURED(0,255,0) AS "EmaSRSI"
    
    ma77art thanked this post
Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.

Slow RSI of J M Wilder’s Version


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
ma77art @ma77art Participant
Summary

This topic contains 1 reply,
has 2 voices, and was last updated by Iván González
4 months, 3 weeks ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 10/08/2025
Status: Active
Attachments: 1 files
Logo Logo
Loading...