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

Script open-source

In pieno spirito TradingView, l'autore di questo script lo ha pubblicato open-source, in modo che i trader possano comprenderlo e verificarlo. Un saluto all'autore! È possibile utilizzarlo gratuitamente, ma il riutilizzo di questo codice in una pubblicazione è regolato dal nostro Regolamento. Per aggiungerlo al grafico, mettilo tra i preferiti.

Vuoi usare questo script sui tuoi grafici?

Declinazione di responsabilità