Pairs trading execution algo: need strategy help (Ninjatrader or R)

Discussion in 'Automated Trading' started by brucelevy, Jul 4, 2018.

  1. Hey so I put together a pairs trading system to basically enter long and short on two symbols simultaneously.

    So i.e., Long ES, Short NQ.

    As of now I am using it to manually enter both markets at the same time. The problem I've been having is in comparing the two markets inside a standard deviation to know when they should regress.

    For example,
    if the spread between the two instruments reached 2-3 sigmas, sell one buy the other.

    When overlaying both instrument on charts it appears that the line charts will fluctuate and not give an accurate reading.

    I have found this to be true on TOS and Ninja.

    Has anyone had any experience with feeding real time data into R Studio in order to accuratly plot the difference between the two markets? I'd like to automated the regression to the mean but cannot get accurate info.

    In addition I had reached out to TOS about their Pairs Trader and was told it is not accurate, and is known by support staff - they are currently working on it.
     
  2. ES/NQ spread is not fixed so if you chart it in TOS it will look like a priced security moving up and down. You have to maybe look intraday for extremes to trade but you have to be quick. ToS can send spread trades but at the market basically...
     
  3. fan27

    fan27

  4. traider

    traider

    You need to decide on model to use, in this case let's use simple linear regression.
    You then need to decide on how to get a hedging factor B and a constant k.

    Your formula will look like this
    ES = BNQ + k.

    example Buy 1 ES, short B NQ.

    This hedging factor and k is most likely not constant over time so a good trader will come up with a best estimate for them. This is also why you get jiggly lines that are always fluctuating with a static model.

    Once you decide it, you can do some light programming to get it working in Ninja.
     
    quant1 likes this.
  5. truetype

    truetype