Strategies
多重指标波动率交易RSI-EMA-ATR策略-Multi-Indicator-Volatility-Trading-RSI-EMA-ATR-Strategy
ChaoZhang · PineScript · Volatility and Channels · 2024-12-20 14:47:41
Volatility and Channels
Trend FollowingMean Reversion
High Volatility · InferredLow Volatility · Inferred
Sizing
—
Risk control
Exit
—
Context terms
No English write-up in the source (no author description).
Source code (79 lines)
/*backtest
start: 2024-12-12 00:00:00
end: 2024-12-19 00:00:00
period: 3m
basePeriod: 3m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("Scalp Master BTCUSDT Strategy", overlay=true, max_labels_count=500, initial_capital=10000, commission_type=strategy.commission.percent, commission_value=0.1)
//=== Kullanıcı Parametreleri ===
rsi_length = input.int(14, "RSI Length")
rsi_lower_band = input.float(45, "RSI Lower Band")
rsi_upper_band = input.float(55, "RSI Upper Band")
ema_fast_length = input.int(5, "Fast EMA")
ema_slow_length = input.int(21, "Slow EMA")
atr_period = input.int(14, "ATR Period")
atr_mult = input.float(0.8, "ATR Multiplier")
volume_filter = input.bool(false, "Enable Volume Filter")
volume_period = input.int(20, "Volume SMA Period")
volume_mult = input.float(1.0, "Volume Threshold Multiplier")
//=== Hesaplamalar ===
// RSI Hesabı
rsi_val = ta.rsi(close, rsi_length)
// ATR Tabanlı Volatilite Kontrolü
atr_val = ta.atr(atr_period)
volatility_ok = atr_val > (ta.sma(atr_val, atr_period) * atr_mult)
// EMA Trend
ema_fast_val = ta.ema(close, ema_fast_length)
ema_slow_val = ta.ema(close, ema_slow_length)
trend_up = ema_fast_val > ema_slow_val
trend_down = ema_fast_val < ema_slow_val
// Hacim Filtresi
volume_sma = ta.sma(volume, volume_period)
high_volume = volume > (volume_sma * volume_mult)
// Sinyal Koşulları (Aynı Alarm Koşulları)
long_signal = trend_up and rsi_val < rsi_lower_band and volatility_ok and (volume_filter ? high_volume : true)
short_signal = trend_down and rsi_val > rsi_upper_band and volatility_ok and (volume_filter ? high_volume : true)
//=== Strateji Mantığı ===
// Basit bir yaklaşım:
// - Long sinyali gelince önce Short pozisyonu kapat, sonra Long pozisyona gir.
// - Short sinyali gelince önce Long pozisyonu kapat, sonra Short pozisyona gir.
if (long_signal)
strategy.close("Short") // Eğer varsa Short pozisyonu kapat
strategy.entry("Long", strategy.long)
if (short_signal)
strategy.close("Long") // Eğer varsa Long pozisyonu kapat
strategy.entry("Short", strategy.short)
// EMA Çizimleri
plot(ema_fast_val, title="Fast EMA (5)", color=color.new(color.orange, 0), linewidth=2)
plot(ema_slow_val, title="Slow EMA (21)", color=color.new(color.blue, 0), linewidth=2)
// Sinyal İşaretleri
plotshape(long_signal, title="BUY Signal", location=location.belowbar,
color=color.new(color.green, 0), style=shape.labelup, text="BUY")
plotshape(short_signal, title="SELL Signal", location=location.abovebar,
color=color.new(color.red, 0), style=shape.labeldown, text="SELL")
// Arka plan renklendirmesi
bgcolor(long_signal ? color.new(color.green, 85) : short_signal ? color.new(color.red, 85) : na)
// Alarm Koşulları (İndikatör ile aynı koşullar)
alertcondition(long_signal, title="Buy Alert", message="BTCUSDT Scalp Master: Buy Signal Triggered")
alertcondition(short_signal, title="Sell Alert", message="BTCUSDT Scalp Master: Sell Alert Triggered")