ozdemirtrading

Bollinger Pair Trade

ozdemirtrading 업데이트됨   
MA-1.6*V

Revision: 1
Author: @ozdemirtrading

Revision 2 Considerations :
- Simplify and clean up plotting

Disclaimer: This strategy is currently working on the 5M chart. Change the length input to accommodate your needs.
For the backtesting of more than 3 months, you may need to upgrade your membership.

Description:

The general idea of the strategy is very straightforward: it takes positions according to the lower and upper Bollinger bands.
But I am mainly using this strategy for pair trading stocks. Do not forget that you will get better results if you trade with cointegrated pairs.

Bollinger band: Moving average & standard deviation are calculated based on 20 bars on the 1H chart (approx 240 bars on a 5m chart). X-day moving averages (20 days as default) are also used in the background in some of the exit strategy choices.
You can define position entry levels as the multipliers of standard deviation (for exp: mult2 as 2 * standard deviation).

There are 4 choices for the exit strategy:

SMA: Exit when touches simple moving average (SMA)
SKP: Skip SMA and do not stop if moving towards 20D SMA, and exit if it touches the other side of the band
SKPXDSMA: Skip SMA if moving towards 20D SMA, and exit if it touches 20D SMA
NoExit: Exit if it touches the upper & lower band only.


Options:
- Strategy hard stop: if trade loss reaches a point defined as a percent of the initial capital. Stop taking new positions. (not recommended for pair trade)
- Loss per trade: close position if the loss is at a defined level but keeps watching for new positions.
- Enable expected profit for trade (expected profit is calculated as the distance to SMA) (recommended for pair trade)
- Enable VIX threshold for the following options: (recommended for volatile periods)
- Stop trading if VIX for the previous day closes above the threshold
- Reverse active trade direction if VIX for the previous day is above the threshold
- Take reverse positions (assuming the Bollinger band is going to expand) for all trades

Backtesting:

Close positions after a defined interval: mark this if you want the close the final trade for backtesting purposes. Unmark it to get live signals.
Use custom interval: Backtest specific time periods.

Other Options:

- Use EMA: use an exponential moving average for the calculations instead of simple moving average
- Not against XDSMA: do not take a position against 20D SMA (if X is selected as 20) (recommended for pairs with a clear trend)
- Not in XDSMA 1 DEV: do not take a position in 20D SMA 1*standart deviation band (recommended if you need to decrease # of trades and increase profit for trade)
- Not in XDSMA 2 DEV: do not take a position in 20D SMA 2*standart deviation band

Session management:
- Not in session: Session start and end times can be defined here. If you do not want to trade in certain time intervals, mark that session.(helps to reduce slippage and get more realistic backtest results)
릴리즈 노트:
Important Bugfix: Close Interval option was blocking the live strategy signals. Corrected with a simple if loop.
릴리즈 노트:
@graph update
릴리즈 노트:
@correction
릴리즈 노트:
Changes to readme, added comments
오픈 소스 스크립트

이 스크립트의 오써는 참된 트레이딩뷰의 스피릿으로 이 스크립트를 오픈소스로 퍼블리쉬하여 트레이더들로 하여금 이해 및 검증할 수 있도록 하였습니다. 오써를 응원합니다! 스크립트를 무료로 쓸 수 있지만, 다른 퍼블리케이션에서 이 코드를 재사용하는 것은 하우스룰을 따릅니다. 님은 즐겨찾기로 이 스크립트를 차트에서 쓸 수 있습니다.

면책사항

이 정보와 게시물은 TradingView에서 제공하거나 보증하는 금융, 투자, 거래 또는 기타 유형의 조언이나 권고 사항을 의미하거나 구성하지 않습니다. 자세한 내용은 이용 약관을 참고하세요.

차트에 이 스크립트를 사용하시겠습니까?