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

Spread Pairs Trading Indicator/Ratio/Chart

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

    Spread Pairs Trading Indicator/Ratio/Chart

    I have been looking around and don’t see an indicator for pairs or spread trading. Does anyone know where I can download a spread or pairs ratio indicator?


    If not, Ninja Trader needs to build and add one as a standard indicator to the platform. It is a simple formula of Data1 – Data2. Anyone trading future or stock spreads needs this ration and this is what most professional traders use and only allow their people to trade off of. It would also be nice if it can plot a bar chart of the spread difference between the two symbols.


    Anyone?

    #2
    Hello DZ954,

    Thank you for your note.

    You can find such an indicator at the following link: http://www.ninjatrader.com/support/f...d=4&linkid=512

    Comment


      #3
      That indicator is good but how can you then do a standard deviation on that spread. I tried doing a stdv using that spread indicator as the instrument, but would not work. any help would be nice.

      Comment


        #4
        Hello nathanneal7,

        Thank you for your post and welcome to the NinjaTrader Support Forum!

        What was the syntax you used? Please provide the full syntax used when calling the StdDev().

        Comment


          #5
          Thank you for responding. I was using an existing "spread candlestick" indicator

          so when I tried to do a standard deviation it read on the chart as: StdDev (spreadcandlesticks(TF 12-14(1 min),1,-1,ES 12-14),spreadopen,4)

          My goal is to create a spread or ratio of 2 futures (TF & ES for example) by either taking the price of each and multiplying it by the amount of $ movement. for example: TF 1165 price times $100 per point movement = $116,500 and ES 2010 times $50 per point = $100,500. Divide 116,500/100,500 to = ratio.

          OR, just use the spread difference like the indicator mentioned above: 1165 TF price - price of ES 2018 = .851.

          Then take a standard deviation of that ratio or spread for a set time period ( like 10 or 30 periods). I want to then be able to chart that ratio/spread and the standard deviation of that ratio/spread so that when it was greater than +/- 2 deviations I would want to trade that pair.

          I would like be able to use tick barks to measure the time periods but can also just use minute bars as well.

          Thank you for any help.
          Last edited by nathanneal7; 11-05-2014, 08:55 PM.

          Comment


            #6
            Hello nathanneal7,

            Thank you for your response.

            If I understand your idea correctly, the following code would work without the need for the spread indicator:
            Code:
                    #region Variables
                    private DataSeries ratio;
            		private int period = 10;
                    #endregion
            		
                    protected override void Initialize()
                    {
                        ratio = new DataSeries(this);
            			Add(new Plot(Color.Red, "Ratio"));
            			Add(new Plot(Color.Blue, "StdDev"));
            			
            			Add("TF 12-14", PeriodType.Tick, 1); // apply the indicator to an ES 12-14 1 Tick
                    }
            		
                    protected override void OnBarUpdate()
                    {
            			double esPrice = Closes[0][0] * Instruments[0].MasterInstrument.PointValue;
            			double tfPrice = Closes[1][0] * Instruments[1].MasterInstrument.PointValue;
            			
            			ratio.Set(esPrice/tfPrice);
            			
            			Values[0].Set(ratio[0]);
            			Values[1].Set(StdDev(ratio, period)[0]);
                    }
            You can find information on multiple instruments in your code at the following link: http://www.ninjatrader.com/support/h...nstruments.htm

            Comment


              #7
              Originally posted by NinjaTrader_PatrickH View Post
              Hello nathanneal7,

              Thank you for your response.

              If I understand your idea correctly, the following code would work without the need for the spread indicator:
              Code:
                      #region Variables
                      private DataSeries ratio;
                      private int period = 10;
                      #endregion
                      
                      protected override void Initialize()
                      {
                          ratio = new DataSeries(this);
                          Add(new Plot(Color.Red, "Ratio"));
                          Add(new Plot(Color.Blue, "StdDev"));
                          
                          Add("TF 12-14", PeriodType.Tick, 1); // apply the indicator to an ES 12-14 1 Tick
                      }
                      
                      protected override void OnBarUpdate()
                      {
                          double esPrice = Closes[0][0] * Instruments[0].MasterInstrument.PointValue;
                          double tfPrice = Closes[1][0] * Instruments[1].MasterInstrument.PointValue;
                          
                          ratio.Set(esPrice/tfPrice);
                          
                          Values[0].Set(ratio[0]);
                          Values[1].Set(StdDev(ratio, period)[0]);
                      }
              You can find information on multiple instruments in your code at the following link: http://www.ninjatrader.com/support/h...nstruments.htm
              The ratio is one measure (a ratio of the two series) and the spread (i.e. the difference) is a different measure. Should we not be dealing with the spread, the difference between the instruments, rather than a ratio?

              On a different topic (but relevant to pairs trading), is it possibler to run a regression between the instruments and retrieve the regression coefficients? Thanks.

              Comment


                #8
                Hello Farmer George,

                The code suggested by NinjaTrader_PatrickH does make a ratio.

                ratio.Set(esPrice/tfPrice);

                This would be instrument1 divided by instrument2 which will give you a ratio.

                Are you finding this value is incorrect?


                Regarding the regression, you can use any formula that you come up with in your code.

                Do you have a regression formula that you are trying to add to your code?


                If you are looking for a formula, there is an indicator that has this formula in it.
                http://www.ninjatrader.com/support/f...tid=-1&lpage=1
                Last edited by NinjaTrader_ChelseaB; 04-06-2015, 08:18 AM.
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  Originally posted by NinjaTrader_ChelseaB View Post
                  Hello Farmer George,

                  The code suggested by NinjaTrader_PatrickH does make a ratio.

                  ratio.Set(esPrice/tfPrice);

                  This would be instrument1 divided by instrument2 which will give you a ratio.

                  Are you finding this value is incorrect?


                  Regarding the regression, you can use any formula that you come up with in your code.

                  Do you have a regression formula that you are trying to add to your code?


                  If you are looking for a formula, there is an indicator that has this formula in it.
                  http://www.ninjatrader.com/support/f...tid=-1&lpage=1
                  Thanks for that. I guess one could use a ratio or a difference calculation in working the spread out - all clear.

                  Something I'm unclear about.Where do I enter the second series I want to regress on and how do I get at the regression coefficient values, using the indicator in the above link? To be clear, I want to run a linear regression such as y = a + bx, where y and x are different dataseries - for example y = esPrice and x = tfPrice in the example.Thanks.
                  Last edited by Farmer George; 04-06-2015, 12:59 PM.

                  Comment


                    #10
                    Originally posted by Farmer George View Post
                    Thanks for that. I guess one could use a ratio or a difference calculation in working the spread out - all clear.

                    Something I'm unclear about.Where do I enter the second series I want to regress on and how do I get at the regression coefficient values, using the indicator in the above link? To be clear, I want to run a linear regression such as y = a + bx, where y and x are different dataseries - for example y = esPrice and x = tfPrice in the example.Thanks.
                    Can anyone help with the regression equation question, thanks?

                    Comment


                      #11
                      Hi Farmer George,

                      While the NinjaTrader Support is not able to assist with creating the regression equation, this thread will remain open for anyone in the community that would like to assist.

                      If you hit a wall, below is a link to a list of professional NinjaScript Consultants who would be happy to assist you in creating this formula.
                      http://ninjatraderecosystem.com/Part...ultants.php#81
                      DanielleNinjaTrader Customer Service

                      Comment


                        #12
                        Originally posted by NinjaTraderEcosystem_Danielle View Post
                        Hi Farmer George,

                        While the NinjaTrader Support is not able to assist with creating the regression equation, this thread will remain open for anyone in the community that would like to assist.

                        If you hit a wall, below is a link to a list of professional NinjaScript Consultants who would be happy to assist you in creating this formula.
                        http://ninjatraderecosystem.com/Part...ultants.php#81
                        Ok, thanks for that. Will first try a work-around.

                        Comment


                          #13
                          Unable to get code

                          Originally posted by NinjaTrader_PatrickH View Post
                          Hello DZ954,

                          Thank you for your note.

                          You can find such an indicator at the following link: http://www.ninjatrader.com/support/f...d=4&linkid=512
                          Hello,

                          I'm unable to download uncorrupted code at the linked location. When I get the code and attempt to unzip, it states the code is corrupted. Is there a backup anywhere?

                          Comment


                            #14
                            Hello mrooths1,

                            Thank you for your post.

                            The file should not be corrupted. Are you using NinjaTrader 7 or 8?

                            Comment


                              #15
                              I'm currently using NinjaTrader 8 however the code is C# and isn't bound to an application correct? I ask because I'm using a Mac to just look at the syntax.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by kujista, Today, 06:23 AM
                              0 responses
                              1 view
                              0 likes
                              Last Post kujista
                              by kujista
                               
                              Started by traderqz, Yesterday, 04:32 PM
                              1 response
                              10 views
                              0 likes
                              Last Post NinjaTrader_Gaby  
                              Started by f.saeidi, Today, 05:56 AM
                              1 response
                              4 views
                              0 likes
                              Last Post Jltarrau  
                              Started by Jltarrau, Today, 05:57 AM
                              0 responses
                              4 views
                              0 likes
                              Last Post Jltarrau  
                              Started by Stanfillirenfro, Yesterday, 09:19 AM
                              7 responses
                              53 views
                              0 likes
                              Last Post NinjaTrader_Gaby  
                              Working...
                              X