StockFetcher Forums · Filter Exchange · SF FILTER FOR PAIR TRADES<< >>Post Follow-up
Kevin_in_GA
4,599 posts
msg #127871
Ignore Kevin_in_GA
4/6/2016 10:29:29 PM

I haven' really posted any new filters in a while, and thought that for those who are interested in pair trades this might be helpful. I typically use a 14 day BB approach on the pair ratio, with entries above or below the BB(14,2) bands. Exit is on the cross back above/below the center line. You can adjust the trade size, look back period, and entry exit points to suit your own style.

Kevin

Fetcher[
SYMLIST(AOS,AZZ)

/*CALCULATE THE PAIR RATIO*/
SET{RATIO, IND(AOS,CLOSE) / IND(AZZ,CLOSE)}

/*DETERMINE THE 14 DAY MOVING AVERAGE FOR THE RATIO*/
SET{RATIOMA14, CMA(RATIO,14)}

/*DETERMINE THE PERCENT ABOVE/BELOW THE MA(14) FOR THE RATIO*/
SET{RATIOPCT1, RATIO / RATIOMA14}
SET{RATIOPCT2, RATIOPCT1 - 1}
SET{RATIOPCT, RATIOPCT2 * 100}

/*DETERMINE THE 14 DAY ZSCORE FOR THE RATIO*/
SET{RATIOSTD14, CSTDDEV(RATIO,14)}
SET{RATIO2STD, 2 * RATIOSTD14}
SET{RATIOUPPERBB, RATIOMA14 + RATIO2STD}
SET{RATIOLOWERBB, RATIOMA14 - RATIO2STD}
SET{RATIODIFF14, RATIO - RATIOMA14}
SET{RATIOZSCORE, RATIODIFF14 / RATIOSTD14}

/*DETERMINE DIRECTION OF PAIR TRADE AND THE NUMBER OF SHARES TO BE BOUGHT OR SOLD*/
SET{BELOWLBB, COUNT(RATIOZSCORE BELOW -2,1)}
SET{ABOVEUBB, COUNT(RATIOZSCORE ABOVE 2,1)}

SET{AOSSHARES1, 10000 / IND(AOS,CLOSE)}
SET{AOSSHARES, ROUND(AOSSHARES1, 0)}
SET{AOSLONG, BELOWLBB * AOSSHARES}
SET{AOSSHORT, ABOVEUBB * AOSSHARES}

SET{AZZSHARES1, 10000 / IND(AZZ,CLOSE)}
SET{AZZSHARES, ROUND(AZZSHARES1, 0)}
SET{AZZLONG, ABOVEUBB * AZZSHARES}
SET{AZZSHORT, BELOWLBB * AZZSHARES}

/*FORMAT FILTER COLUMN OUTPUT*/
ADD COLUMN RATIO {RATIO}
ADD COLUMN RATIOMA14
ADD COLUMN RATIOZSCORE {RATIO Z-SCORE}
ADD COLUMN RATIOPCT {PERCENT AWAY FROM MEAN}
ADD COLUMN SEPARATOR
ADD COLUMN AOSLONG {AOS - SHARES LONG}
ADD COLUMN AZZSHORT {AZZ - SHARES SHORT}
ADD COLUMN SEPARATOR
ADD COLUMN AOSSHORT {AOS - SHARES SHORT}
ADD COLUMN AZZLONG {AZZ - SHARES LONG}

/*DRAW RATIO PLOT AND ZSCORE*/
DRAW RATIO ON PLOT RATIOMA14
DRAW RATIOUPPERBB ON PLOT RATIOMA14
DRAW RATIOLOWERBB ON PLOT RATIOMA14

PLOTTYPE{RATIOZSCORE, ZEROBAR}
DRAW RATIOZSCORE LINE AT 2
DRAW RATIOZSCORE LINE AT -2
DRAW RATIOZSCORE LINE AT 0

CHART-TIME IS 6 MONTHS
]



graftonian
1,089 posts
msg #128415
Ignore graftonian
modified
5/11/2016 6:22:49 PM

Kevin:I Read through your pair trade filter, and tried some of the tricks on the UPRO-SPXU pair. I've messed with this pair for for a while , and watching the slope of the MA(3), and the relative position of the RATIOPCT works better than anything else I've tried.
I have not worked out the entry and exit criterion yet, but ran manual 1 year backtest using
Enter UPRO when RATIOPCT < -2 and MA(3) slope > 0
Exit UPRO when RATIOPCT > 2 and MA(3) slope < 0 (Switching to SPXU)
Wash, rinse, repeat
One year result : $5000 trades, 12 round trips, 96% Gain (with compounding less comissions)

11-2030 POSTED WRONG VERSION, MODIFIED

Fetcher[/*UPRO-SPXU RATIOS 511-01*/
SYMLIST(UPRO, SPXU)
/*CALCULATE THE PAIR RATIO*/
SET{RATIO, IND(UPRO,CLOSE) / IND(SPXU,CLOSE)}

/*DETERMINE THE 14 DAY MOVING AVERAGE FOR THE RATIO*/
SET{RATIOMA14, CMA(RATIO,14)}
DRAW RATIOMA14
/*DETERMINE THE 3 DAY MOVING AVERAGE FOR THE RATIO*/
SET{RATIOMA03, CMA(RATIO, 3)}
DRAW RATIOMA03 ON PLOT RATIOMA14
/*DETERMINE THE PERCENT ABOVE/BELOW THE MA(14) FOR THE RATIOMA03*/
SET{RATIOPCT1, RATIO / RATIOMA14}
SET{RATIOPCT2, RATIOPCT1 - 1}
SET{RATIOPCT, RATIOPCT2 * 100}
ADD COLUMN RATIOPCT
draw ratiopct
DRAW RATIOPCT LINE AT 0
DRAW RATIOPCT LINE AT -2
DRAW RATIOPCT LINE AT 2
/*DETERMINE THE SLOPE OF RATIOMA03*/
SET{SLOPEMA03, SLOPE OF RATIOMA03}
ADD COLUMN SLOPEMA03
DRAW SLOPEMA03
DRAW SLOPEMA03 LINE AT 0
]




Mactheriverrat
3,153 posts
msg #128418
Ignore Mactheriverrat
modified
5/12/2016 12:42:07 AM

Both great filters .
I wonder if these filters could be done using 1 or 2 moving averages and where the price is compared to that average say the EMA(13).

with both of these filters and the four stocks one might add the EMA(13) for sure and the MA(50).

One can see some really great gains using the EMA(13) and how the price crosses above or below that line and starts pulling that average in the direction of the trend. One can clearly see both bull , bear and a few sideways trends using that EMA(13)

Just saying.
I was hooked on the EMA(9) but now the EMA(13) keeps price with in a trend. Then again each stock has its own personality



BTW can one of you post the filter using the EMA(13) rather than the MA(14)
Thanks

graftonian
1,089 posts
msg #128419
Ignore graftonian
5/12/2016 9:56:45 AM

Mac, Thanks for the input. I will try and make the changes and re-post.

fotchstecker
304 posts
msg #128450
Ignore fotchstecker
5/13/2016 10:03:17 PM

Kevin, what criteria do you use for picking pairs to begin with?

Kevin_in_GA
4,599 posts
msg #128488
Ignore Kevin_in_GA
5/16/2016 1:28:32 PM

I use several sites and pieces of software - currently using www.pairtradinglab.com to validate pairs I pull from using another piece of good pair trading software (PairtradeFinder).

Pairtradinglab.com has an extensively analyzed pairs database that you can access if you are a premium member, as well as an automated trading capability through IB to place trades based on specific entry/exit criteria for any pair (I use 14 day window and a Z-score of 2 or more, other traders I know use 100 days and a Z-score of 2.7 for entries). Highly customizable.

fotchstecker
304 posts
msg #128491
Ignore fotchstecker
5/16/2016 3:01:01 PM

Thanks, Kevin. Hope all's well over by you.

StockFetcher Forums · Filter Exchange · SF FILTER FOR PAIR TRADES<< >>Post Follow-up

*** Disclaimer *** StockFetcher.com does not endorse or suggest any of the securities which are returned in any of the searches or filters. They are provided purely for informational and research purposes. StockFetcher.com does not recommend particular securities. StockFetcher.com, Vestyl Software, L.L.C. and involved content providers shall not be liable for any errors or delays in the content, or for any actions taken based on the content.


Copyright 2022 - Vestyl Software L.L.C.Terms of Service | License | Questions or comments? Contact Us
EOD Data sources: DDFPlus & CSI Data Quotes delayed during active market hours. Delay times are at least 15 mins for NASDAQ, 20 mins for NYSE and Amex. Delayed intraday data provided by DDFPlus


This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.