Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Ninja PairsTrader

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

    #31
    I agree. I am currently working on your code and I am implementing a "greedier" form of it. Basically, you select the base pair as the less liquid of the two contracts. The idea is you work the less liquid leg of the trade with a limit order, and once the order is filled (or partially filled) an appropriate amount of the hedge is filled at market to hedge the position.

    I finished coding the first draft last night so I will be testing it today. One good aspect of it is that you specify the price when you initiate the trade (from the "alpha" part of the code). Therefore, if you want to be "greedy", you can put in a bid that may or may not get hit/filled. If, based on your strategy, you have to be aggressive, you can specify the ask (GetCurrentAsk()) as the price in which case it would be almost like a market order (provided enough liquidity on the ask and assuming you are going long the spread).

    I'll keep you guys updated on my progress.

    Comment


      #32
      PairsStrategyBase

      Hello,
      attached my generic framework for pair trading strategy.
      The base logic is contained in PairsStrategyBase.cs
      All the alpha generating logic is completely seperated.
      As a sample there is SamplePairsStrategy.cs
      this strategy uses the indicator SpreadZScore.cs for determining Spread entries and exits.

      Also done is:
      1. Error handling if some orders (first or second leg) are not executed within time limits.
      2. Defined behaviour how to handle those cases (LegIncompletehandling, ->
      TrailProtectPosition,
      TryCompleteWithPayupOrder,
      CloseWithMar****rder
      3. Defined some standard presets (ZN-ZB, NQ-ES,...)

      All this will work fine in real-time or in market replay.
      Since I used windows timers to check for order expired conditions these timeout will remain the same indipendent of the market-replay speed used, therefore results will be different for market-replay speeds greater than 1. Also backtesting results will be different than reality.

      Please feel free to try out, I am looking for feedback.
      Installation:
      Please unzip the PairsStrategy.Zip file into /NinjaTrader 7/bin/Custom
      You will then find a file PairsStrategyBase.zip in the directory NinjaTrader 7/bin/Custom
      Please import this assemply using File->Utilities->Import Ninjascript.

      regards

      Andreas
      Attached Files
      Last edited by zweistein; 08-11-2010, 04:46 AM.

      Comment


        #33
        There seems to be an error in some of your strategy files. Followed your instructions but could not import ninjascript because there was an error in a "custom" file.

        Comment


          #34
          My instructions were not correct:

          1.Please delete (temporarily) the files @PairsStrategy.cs and SamplePairsStrategy.cs and maybe SpreadZScore.cs.

          2. Compile your scripts

          3. Import PairsStrategyBase.zip
          If without errors, then all is fine, if you have errors please report

          5. restrore above files from 1. and compile. Should be error free.


          regarrds
          andreas

          Comment


            #35
            @zweistein I looked through some of your code and you really seem to know your way around NT and C#. I am also in the process of trying to code this thing and I was thinking it would be great if we could have a DOM that displays the "synthetic" DOM created from the spread. Then, one could work an order at a given spread price. When his limit order on the spread gets hit, the order is executed, and all this, from the DOM.

            Is this feasible or is the code for the DOM (NinjaTrader.Gui.SuperDom I believe) not open? Would we have to code up a whole new DOM?

            Cheers

            Comment


              #36
              There is a newer version of SpreadZScore floating around which might cause a conflict as it has a different # of overloads. Not sure if it helps but the latest version is attached as a .cs file.
              Attached Files

              Comment


                #37
                @MZASJ

                thank you for your updated code.
                Actually the SpreadZScore.cs in my .zip is internally different from yours, so I should have changed name...

                @pmorissette

                Or you spend time finding the NT interface or you spend it writing a new Spread Dom from scatch. As you need the spread DOM only for display of price and not for order entry I personally would rather write a new SpreadDOM.

                Comment


                  #38
                  @zweistein

                  Is there a way I can get data from NT in a custom class? Some kind of interface or something that will give me data?

                  Comment


                    #39
                    I realize this is an old thread... But maybe someone is still reading.

                    I've been playing around with the SpreadZScore indicator and have been unsuccessful in getting it to work in backtesting. The trades don't come anywhere close to being in the same ballpark as market replay. Even if I use a large slippage # in backtesting, the differences are quite large over a single day or multiple day run..

                    Has anyone had similar experiences? I'd like to use it for pair trading, but right now, I cannot, for the life of me, figure out why the backtesting/market replay results are so far apart. I've had many instances w/ NT having discrepancies between live/backtesting, but this one seems different.

                    Thanks

                    Comment


                      #40
                      Importing your strategy into NinjaTrader 7 failed with an error. Message is "The specified module could not be found".

                      Would you mind reposting a version 7 of your files?

                      Thanks.

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                      0 responses
                      649 views
                      0 likes
                      Last Post Geovanny Suaza  
                      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                      0 responses
                      370 views
                      1 like
                      Last Post Geovanny Suaza  
                      Started by Mindset, 02-09-2026, 11:44 AM
                      0 responses
                      109 views
                      0 likes
                      Last Post Mindset
                      by Mindset
                       
                      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                      0 responses
                      574 views
                      1 like
                      Last Post Geovanny Suaza  
                      Started by RFrosty, 01-28-2026, 06:49 PM
                      0 responses
                      576 views
                      1 like
                      Last Post RFrosty
                      by RFrosty
                       
                      Working...
                      X