Correlation Based Pair Trading Strategy (Trading the spread)
There are three popular styles of Pair trading:
* Distance based pair trading * Correlation based pair trading * Cointegration based pair trading
The correlation based strategy is to short the outperforming instrument and go long on the underperforming one whenever the temporary correlation weakens which means one instrument going up and another going down. Here, instead of two different instruments two timeframes of the same instrument are used, lower and higher. In order to calculate the trade size, we would need to calculate hedge_ratio, which is simply the ratio of the closing price of the instrument in the current tf to the higher tf. So whenever we want to go short on spread we’ll short 1 unit of current tf and go long on hedge ratio times units of higher tf.
NOTE: There is a minor problem to it in Pinescript. After a while the signal line goes horizontal and the two bounds, upper and lower, converge unless you update the time frame. Kepp me in the know if you find a solution to this problem)
릴리즈 노트
Correlation Based Pair Trading Strategy (Trading the spread)
There are three popular styles of Pair trading:
* Distance based pair trading * Correlation based pair trading * Cointegration based pair trading
The correlation based strategy is to short the outperforming instrument and go long on the underperforming one whenever the temporary correlation weakens which means one instrument going up and another going down. Here, instead of two different instruments two timeframes of the same instrument are used, lower and higher. In order to calculate the trade size, we would need to calculate hedge_ratio, which is simply the ratio of the closing price of the instrument in the current tf to the higher tf. So whenever we want to go short on spread we’ll short 1 unit of current tf and go long on hedge ratio times units of higher tf.
In order to generate trading signals, we need to define our trading logic. So, we’ll go long on the spread when the hedge ratio goes below its p rolling mean by mult times of its rolling standard deviation and vice versa. Note that both p and mult, as well as tf, can be changed as per your selection of instruments. See: analyticsprofile.com/algo-trading/pair-trading-part-2-code-correlation-based-pair-trading-strategy-in-r/
진정한 TradingView 정신에 따라, 이 스크립트의 저자는 트레이더들이 이해하고 검증할 수 있도록 오픈 소스로 공개했습니다. 저자에게 박수를 보냅니다! 이 코드는 무료로 사용할 수 있지만, 출판물에서 이 코드를 재사용하는 것은 하우스 룰에 의해 관리됩니다. 님은 즐겨찾기로 이 스크립트를 차트에서 쓸 수 있습니다.