This strategy is designed based on the Bollinger Bands indicator to go short when price breaks above the upper band and go long when price breaks below the lower band, realizing intelligent tracking trading.
The strategy uses the middle line, upper band and lower band of the Bollinger Bands as the base indicators. The middle line is the moving average of the closing prices over n days. The upper band is the middle line shifted up by two standard deviations while the lower band is shifted down by two standard deviations. When price breaks the lower band upwards, go long. When price breaks the upper band downwards, go short. This allows intelligent tracking of price based on market volatility.
Specifically, the strategy mainly judges two metrics:
ta.crossover(source, lower): closing price breaks above lower band, go long
ta.crossunder(source, upper): closing price breaks below upper band, go short
When the exit condition triggers, use strategy.cancel() function to flatten existing position.
The main advantages of this strategy are:
There are also some risks with this strategy:
Corresponding solutions:
The strategy can be further optimized by:
This strategy is designed based on the Bollinger Bands indicator, using price breakouts of upper and lower bands to automatically track prices. The logic is simple and sensitive to market volatility. Further optimizations can be done via parameter tuning and stop loss mechanisms. Overall this strategy works well for indices and commodities with higher volatility. Traders can backtest and optimize based on their trading preference to derive an astika trading strategy.
/*backtest start: 2023-12-17 00:00:00 end: 2024-01-16 00:00:00 period: 1h basePeriod: 15m exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}] */ //@version=5 strategy("Bollinger Bands Strategy with alerts (incl. pending orders) via TradingConnector to Forex", overlay=true) source = close length = input.int(20, minval=1) mult = input.float(2.0, minval=0.001, maxval=50) basis = ta.sma(source, length) dev = mult * ta.stdev(source, length) upper = basis + dev lower = basis - dev buyEntry = ta.crossover(source, lower) sellEntry = ta.crossunder(source, upper) if (ta.crossover(source, lower)) strategy.entry("BBandLE", strategy.long, stop=lower, oca_name="BollingerBands", comment="BBandLE") alert(message='long price='+str.tostring(lower), freq=alert.freq_once_per_bar_close) else strategy.cancel(id="BBandLE") alert(message='cancel long', freq=alert.freq_once_per_bar_close) if (ta.crossunder(source, upper)) strategy.entry("BBandSE", strategy.short, stop=upper, oca_name="BollingerBands", comment="BBandSE") alert(message='short price='+str.tostring(upper), freq=alert.freq_once_per_bar_close) else strategy.cancel(id="BBandSE") alert(message='cancel short', freq=alert.freq_once_per_bar_close) //plot(strategy.equity, title="equity", color=color.red, linewidth=2, style=plot.style_areabr) //Lines of code added to the original built-in script: 14, 17, 20 and 23 only. //They trigger alerts ready to be executed on real markets through TradingConnector //available for Forex, indices, crypto, stocks - anything your broker offers for trading via MetaTrader4/5