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

Pairs trading.. RSI of ATR

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Pairs trading.. RSI of ATR

    there is an explanation of this particular indicator in this link ...



    but what it is .. is basically the relative strength of the average true range.. of course ATR is a measure of volatility and RSI everyone knows.. such that you can measure the trend of volatility of one constituent to another in a pairs trade.. does anyone know of this indicator already programmed in ninja trader.. or how easy is it to translate from the code on the tradestation page to NT

    #2
    Hello,

    I'm not aware of an existing programmed indicator, but we will leave this thread open for other users to comment.

    Good luck!
    MatthewNinjaTrader Product Management

    Comment


      #3
      Well I'm gonna program it myself if I don't hear anything

      Comment


        #4
        this is how far i've gotton..

        i keep getting these two errors
        The type of 'NinjaTrader.Indicator.RSIofATR' already contains a definition of 'RSIPeriod'
        and
        The type of 'NinjaTrader.Indicator.RSIofATR' already contains a definition of 'ATRPeriod'

        who idea here would enable the user to change imputs to RSI and the ATR periods.. heres the code

        #region Using declarations
        using System;
        using System.ComponentModel;
        using System.Diagnostics;
        using System.Drawing;
        using System.Drawing.Drawing2D;
        using System.Xml.Serialization;
        using NinjaTrader.Cbi;
        using NinjaTrader.Data;
        using NinjaTrader.Gui.Chart;
        #endregion

        // This namespace holds all indicators and is required. Do not change it.
        namespace NinjaTrader.Indicator
        {
        /// <summary>
        /// RSI of ATR
        /// </summary>
        [Description("RSI of ATR")]
        public class RSIofATR : Indicator
        {
        #region Variables
        // Wizard generated variables
        private string firstInstrument = @"HOT"; // Default setting for FirstInstrument
        private string secondInstrument = @"HST"; // Default setting for SecondInstrument
        private int RSIPeriod = 14; // Default setting for RSIPeriod
        private int ATRPeriod = 14; // Default setting for ATRPeriod
        // User defined variables (add any user defined variables below)
        #endregion

        /// <summary>
        /// This method is used to configure the indicator and is called once before any bar data is loaded.
        /// </summary>
        protected override void Initialize()
        {
        Add(new Plot(Color.FromKnownColor(KnownColor.Black), PlotStyle.Line, "AvgSpreadDiff"));
        Overlay = false;
        }

        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        { try
        {
        double FirstValue = (Closes[1][0] * Instruments[1].MasterInstrument.PointValue);
        double SecondValue = (Closes[2][0] * Instruments[2].MasterInstrument.PointValue);
        double AverageSpreadDiff = ((RSI(ATR(FirstValue,ATRPeriod),RSIPeriod)) / (RSI(ATR(SecondValue,ATRPeriod),RSIPeriod))*100);
        Spread.Set(AverageSpreadDiff);
        SMA.Set(Close[0]);
        }
        catch (Exception ex)
        {
        Print(ex.ToString());
        }
        }

        #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 DataSeries AvgSpreadDiff
        {
        get { return Values[0]; }
        }

        [Description("1st Constituent")]
        [GridCategory("Parameters")]
        public string FirstInstrument
        {
        get { return firstInstrument; }
        set { firstInstrument = value; }
        }

        [Description("2nd Constituent")]
        [GridCategory("Parameters")]
        public string SecondInstrument
        {
        get { return secondInstrument; }
        set { secondInstrument = value; }
        }

        [Description("Period to calculate RSI upon")]
        [GridCategory("Parameters")]
        public int RSIPeriod
        {
        get { return RSIPeriod; }
        set { RSIPeriod = Math.Max(1, value); }
        }

        [Description("Period to calculate ATR upon")]
        [GridCategory("Parameters")]
        public int ATRPeriod
        {
        get { return ATRPeriod; }
        set { ATRPeriod = Math.Max(1, value); }
        }
        #endregion
        }
        }

        #region NinjaScript generated code. Neither change nor remove.
        // This namespace holds all indicators and is required. Do not change it.
        namespace NinjaTrader.Indicator
        {
        public partial class Indicator : IndicatorBase
        {
        private RSIofATR[] cacheRSIofATR = null;

        private static RSIofATR checkRSIofATR = new RSIofATR();

        /// <summary>
        /// RSI of ATR
        /// </summary>
        /// <returns></returns>
        public RSIofATR RSIofATR(int aTRPeriod, string firstInstrument, int rSIPeriod, string secondInstrument)
        {
        return RSIofATR(Input, aTRPeriod, firstInstrument, rSIPeriod, secondInstrument);
        }

        /// <summary>
        /// RSI of ATR
        /// </summary>
        /// <returns></returns>
        public RSIofATR RSIofATR(Data.IDataSeries input, int aTRPeriod, string firstInstrument, int rSIPeriod, string secondInstrument)
        {
        if (cacheRSIofATR != null)
        for (int idx = 0; idx < cacheRSIofATR.Length; idx++)
        if (cacheRSIofATR[idx].ATRPeriod == aTRPeriod && cacheRSIofATR[idx].FirstInstrument == firstInstrument && cacheRSIofATR[idx].RSIPeriod == rSIPeriod && cacheRSIofATR[idx].SecondInstrument == secondInstrument && cacheRSIofATR[idx].EqualsInput(input))
        return cacheRSIofATR[idx];

        lock (checkRSIofATR)
        {
        checkRSIofATR.ATRPeriod = aTRPeriod;
        aTRPeriod = checkRSIofATR.ATRPeriod;
        checkRSIofATR.FirstInstrument = firstInstrument;
        firstInstrument = checkRSIofATR.FirstInstrument;
        checkRSIofATR.RSIPeriod = rSIPeriod;
        rSIPeriod = checkRSIofATR.RSIPeriod;
        checkRSIofATR.SecondInstrument = secondInstrument;
        secondInstrument = checkRSIofATR.SecondInstrument;

        if (cacheRSIofATR != null)
        for (int idx = 0; idx < cacheRSIofATR.Length; idx++)
        if (cacheRSIofATR[idx].ATRPeriod == aTRPeriod && cacheRSIofATR[idx].FirstInstrument == firstInstrument && cacheRSIofATR[idx].RSIPeriod == rSIPeriod && cacheRSIofATR[idx].SecondInstrument == secondInstrument && cacheRSIofATR[idx].EqualsInput(input))
        return cacheRSIofATR[idx];

        RSIofATR indicator = new RSIofATR();
        indicator.BarsRequired = BarsRequired;
        indicator.CalculateOnBarClose = CalculateOnBarClose;
        #if NT7
        indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256;
        indicator.MaximumBarsLookBack = MaximumBarsLookBack;
        #endif
        indicator.Input = input;
        indicator.ATRPeriod = aTRPeriod;
        indicator.FirstInstrument = firstInstrument;
        indicator.RSIPeriod = rSIPeriod;
        indicator.SecondInstrument = secondInstrument;
        Indicators.Add(indicator);
        indicator.SetUp();

        RSIofATR[] tmp = new RSIofATR[cacheRSIofATR == null ? 1 : cacheRSIofATR.Length + 1];
        if (cacheRSIofATR != null)
        cacheRSIofATR.CopyTo(tmp, 0);
        tmp[tmp.Length - 1] = indicator;
        cacheRSIofATR = tmp;
        return indicator;
        }
        }
        }
        }

        // This namespace holds all market analyzer column definitions and is required. Do not change it.
        namespace NinjaTrader.MarketAnalyzer
        {
        public partial class Column : ColumnBase
        {
        /// <summary>
        /// RSI of ATR
        /// </summary>
        /// <returns></returns>
        [Gui.Design.WizardCondition("Indicator")]
        public Indicator.RSIofATR RSIofATR(int aTRPeriod, string firstInstrument, int rSIPeriod, string secondInstrument)
        {
        return _indicator.RSIofATR(Input, aTRPeriod, firstInstrument, rSIPeriod, secondInstrument);
        }

        /// <summary>
        /// RSI of ATR
        /// </summary>
        /// <returns></returns>
        public Indicator.RSIofATR RSIofATR(Data.IDataSeries input, int aTRPeriod, string firstInstrument, int rSIPeriod, string secondInstrument)
        {
        return _indicator.RSIofATR(input, aTRPeriod, firstInstrument, rSIPeriod, secondInstrument);
        }
        }
        }

        // This namespace holds all strategies and is required. Do not change it.
        namespace NinjaTrader.Strategy
        {
        public partial class Strategy : StrategyBase
        {
        /// <summary>
        /// RSI of ATR
        /// </summary>
        /// <returns></returns>
        [Gui.Design.WizardCondition("Indicator")]
        public Indicator.RSIofATR RSIofATR(int aTRPeriod, string firstInstrument, int rSIPeriod, string secondInstrument)
        {
        return _indicator.RSIofATR(Input, aTRPeriod, firstInstrument, rSIPeriod, secondInstrument);
        }

        /// <summary>
        /// RSI of ATR
        /// </summary>
        /// <returns></returns>
        public Indicator.RSIofATR RSIofATR(Data.IDataSeries input, int aTRPeriod, string firstInstrument, int rSIPeriod, string secondInstrument)
        {
        if (InInitialize && input == null)
        throw new ArgumentException("You only can access an indicator with the default input/bar series from within the 'Initialize()' method");

        return _indicator.RSIofATR(input, aTRPeriod, firstInstrument, rSIPeriod, secondInstrument);
        }
        }
        }
        #endregion

        Comment


          #5
          Hello cdcaveman,
          You have used same name in the property and the private field for ATRPeriod and RSIPeriod. Please change it as shown below.
          Code:
          private int [B]a[/B]TRPeriod = 14; // Default setting for ATRPeriod
          private int [B]r[/B]SIPeriod = 14; // Default setting for RSIPeriod
          
          [Description("Period to calculate RSI upon")]
          [GridCategory("Parameters")]
          public int RSIPeriod
          {
          get { return rSIPeriod; }
          set { rSIPeriod = Math.Max(1, value); }
          }
          
          [Description("Period to calculate ATR upon")]
          [GridCategory("Parameters")]
          public int ATRPeriod
          {
          get { return aTRPeriod; }
          set { aTRPeriod = Math.Max(1, value); }
          }
          There are several errors in the OnBarUpdate section too (of missing plots etc). You need to check on those too.
          Last edited by NinjaTrader_Joydeep; 08-30-2012, 04:30 AM.
          JoydeepNinjaTrader Customer Service

          Comment


            #6
            "missing Plots"??? not sure what you mean.. i'm so new to this... i'm gonna try not using the private ATRPeriod/RSIPeriod at all.. and just use the default

            (RSI(ATR(FirstInstrument)) /(RSI(ATR(SecondInstrument))


            Originally posted by NinjaTrader_Joydeep View Post
            Hello cdcaveman,
            You have used same name in the property and the private field for ATRPeriod and RSIPeriod. Please change it as shown below.
            Code:
            private int [B]a[/B]TRPeriod = 14; // Default setting for ATRPeriod
            private int [B]r[/B]SIPeriod = 14; // Default setting for RSIPeriod
            
            [Description("Period to calculate RSI upon")]
            [GridCategory("Parameters")]
            public int RSIPeriod
            {
            get { return rSIPeriod; }
            set { rSIPeriod = Math.Max(1, value); }
            }
            
            [Description("Period to calculate ATR upon")]
            [GridCategory("Parameters")]
            public int ATRPeriod
            {
            get { return aTRPeriod; }
            set { aTRPeriod = Math.Max(1, value); }
            }
            There are several errors in the OnBarUpdate section too (of missing plots etc). You need to check on those too.

            Comment


              #7
              i'm back to trying to translate this indicator i found at tradestation into ninja trader.. i'll give some updates... there are two instriments in the chart.. firstinstriment, secondinstriment and i'm taking the relative strength of the average true range of the first instriment and dividing it by the rsi of atr of the secondinstriment... i thought this would be simple .. but obviously not for me.. if anyone has dealt with any kind of pairs kind of indicators let me know .. thanks..

              Comment


                #8
                Hello cdcaveman,
                You have to build a multi-series indicator to do it. Please refer to our help guide to know more about it.
                JoydeepNinjaTrader Customer Service

                Comment


                  #9
                  thanks for your reply.. i've been reading... i'll regroup.. and see if i can give it another go..

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by bortz, 11-06-2023, 08:04 AM
                  47 responses
                  1,606 views
                  0 likes
                  Last Post aligator  
                  Started by jaybedreamin, Today, 05:56 PM
                  0 responses
                  8 views
                  0 likes
                  Last Post jaybedreamin  
                  Started by DJ888, 04-16-2024, 06:09 PM
                  6 responses
                  18 views
                  0 likes
                  Last Post DJ888
                  by DJ888
                   
                  Started by Jon17, Today, 04:33 PM
                  0 responses
                  4 views
                  0 likes
                  Last Post Jon17
                  by Jon17
                   
                  Started by Javierw.ok, Today, 04:12 PM
                  0 responses
                  13 views
                  0 likes
                  Last Post Javierw.ok  
                  Working...
                  X