Slow RSI of J M Wilder’s Version

Forums ProRealTime English forum ProBuilder support Slow RSI of J M Wilder’s Version

Viewing 1 post (of 1 total)
  • #252365

    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

     

Viewing 1 post (of 1 total)

Create your free account now and post your request to benefit from the help of the community
Register or Login