OPEN-SOURCE SCRIPT

Volatility Crypto Trading Strategy

//version=5
indicator("Volatility Crypto Trading Strategy", overlay=true)

// Input parameters for Bollinger Bands and MACD
bb_length = input.int(20, title="Bollinger Band Length")
bb_std_dev = input.float(2.0, title="Bollinger Band Standard Deviation")
macd_fast = input.int(12, title="MACD Fast Length")
macd_slow = input.int(26, title="MACD Slow Length")
macd_signal = input.int(9, title="MACD Signal Length")

// Input for higher timeframe
htf = input.timeframe("30", title="Higher Timeframe")

// Bollinger Bands calculation
bb_basis = ta.sma(close, bb_length)
bb_upper = bb_basis + bb_std_dev * ta.stdev(close, bb_length)
bb_lower = bb_basis - bb_std_dev * ta.stdev(close, bb_length)

// MACD calculation
[macd_line, signal_line, _] = ta.macd(close, macd_fast, macd_slow, macd_signal)

// Higher timeframe trend confirmation
htf_close = request.security(syminfo.tickerid, htf, close)
htf_trend = ta.sma(htf_close, bb_length)
higher_trend_up = htf_close > htf_trend
higher_trend_down = htf_close < htf_trend

// Entry conditions
long_condition = close < bb_lower and macd_line > signal_line and higher_trend_up
short_condition = close > bb_upper and macd_line < signal_line and higher_trend_down

// Exit conditions
long_exit_condition = close >= bb_basis * 1.1
short_exit_condition = close <= bb_basis * 0.9

// Plot Bollinger Bands
plot(bb_upper, color=color.red, title="Upper Bollinger Band")
plot(bb_lower, color=color.green, title="Lower Bollinger Band")
plot(bb_basis, color=color.blue, title="Bollinger Band Basis")

// Plot Buy/Sell signals
plotshape(series=long_condition, title="Buy Signal", location=location.belowbar, color=color.green, style=shape.labelup, text="BUY")
plotshape(series=short_condition, title="Sell Signal", location=location.abovebar, color=color.red, style=shape.labeldown, text="SELL")

// Alerts
alertcondition(long_condition, title="Long Entry", message="Buy Signal")
alertcondition(short_condition, title="Short Entry", message="Sell Signal")
alertcondition(long_exit_condition, title="Long Exit", message="Exit Long")
alertcondition(short_exit_condition, title="Short Exit", message="Exit Short")
Candlestick analysisChart patternsCycles

Open-source script

In true TradingView spirit, the author of this script has published it open-source, so traders can understand and verify it. Cheers to the author! You may use it for free, but reuse of this code in publication is governed by House rules. You can favorite it to use it on a chart.

Want to use this script on a chart?

Disclaimer