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 автор этого скрипта опубликовал его с открытым исходным кодом, чтобы трейдеры могли понять, как он работает, и проверить на практике. Вы можете воспользоваться им бесплатно, но повторное использование этого кода в публикации регулируется Правилами поведения. Вы можете добавить этот скрипт в избранное и использовать его на графике.

Отказ от ответственности

Все виды контента, которые вы можете увидеть на TradingView, не являются финансовыми, инвестиционными, торговыми или любыми другими рекомендациями. Мы не предоставляем советы по покупке и продаже активов. Подробнее — в Условиях использования TradingView.

Хотите использовать этот скрипт на графике?