Strategi ini adalah sistem mengikuti tren adaptif berdasarkan beberapa filter indikator teknis. Ini menggabungkan berbagai indikator teknis termasuk Rata-rata Bergerak Eksponensial (EMA), Rata-rata Bergerak Sederhana (SMA), dan Perbedaan Konvergensi Rata-rata Bergerak (MACD), secara dinamis menyesuaikan parameter untuk beradaptasi dengan lingkungan pasar yang berbeda untuk menangkap tren yang efisien dan pengendalian risiko. Strategi ini menggunakan mekanisme penyaringan berlapis, secara signifikan meningkatkan keandalan sinyal perdagangan melalui kombinasi sinergis dari beberapa indikator teknis.
Logika inti didasarkan pada mekanisme penyaringan tiga lapisan:
Generasi sinyal perdagangan membutuhkan semua kondisi filter untuk dipenuhi: transisi tren, konfirmasi arah SMA, dan dukungan garis sinyal MACD. Strategi ini juga mencakup sistem manajemen posisi dinamis berdasarkan ekuitas akun, secara otomatis menyesuaikan ukuran posisi melalui faktor leverage.
Strategi ini mencapai tren yang relatif dapat diandalkan melalui mekanisme penyaringan multi-lapisan dan penyesuaian parameter dinamis. Meskipun ada beberapa risiko lag dan ketergantungan parameter, kinerja stabil masih dapat dicapai dalam perdagangan aktual melalui optimasi parameter yang wajar dan langkah-langkah pengendalian risiko. Pedagang disarankan untuk secara menyeluruh backtest dan menyesuaikan pengaturan parameter sesuai dengan toleransi risiko individu sebelum perdagangan langsung.
/*backtest start: 2024-12-29 00:00:00 end: 2025-01-05 00:00:00 period: 45m basePeriod: 45m exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}] */ //@version=6 strategy("Adaptive Trend Flow Strategy with Filters for SPX", overlay=true, max_labels_count=500, initial_capital=1000, commission_type=strategy.commission.cash_per_order, commission_value=0.01, slippage=2, margin_long=20, margin_short=20, default_qty_type=strategy.percent_of_equity, default_qty_value=100) // User-defined inputs for trend logic atr = input.int(14, "Main Length", minval=2, group = "Find more strategies like this on pineindicators.com") length = input.int(2, "Main Length", minval=2) smooth_len = input.int(2, "Smoothing Length", minval=2) sensitivity = input.float(2.0, "Sensitivity", step=0.1) // User-defined inputs for SMA filter use_sma_filter = input.bool(true, "Enable SMA Filter?") sma_length = input.int(4, "SMA Length", minval=1) // User-defined inputs for MACD filter use_macd_filter = input.bool(true, "Enable MACD Filter?") macd_fast_length = input.int(2, "MACD Fast Length", minval=1) macd_slow_length = input.int(7, "MACD Slow Length", minval=1) macd_signal_length = input.int(2, "MACD Signal Length", minval=1) // User-defined inputs for leverage leverage_factor = input.float(4.5, "Leverage Factor", minval=1.0, step=0.1) id = input("besttrader123", title= "Your TradingView username", group = "Automate this strategy with plugpine.com") key = input("nc739ja84gf", title= "Unique identifier (UID)") ticker = input("SPX", title= "Ticker/symbol of your broker") bullcolor = #0097a7 bearcolor = #ff195f showbars = input.bool(true, "Color Bars?") showbg = input.bool(true, "Background Color?") showsignals = input.bool(true, "Show Signals?") // Trend calculation functions calculate_trend_levels() => typical = hlc3 fast_ema = ta.ema(typical, length) slow_ema = ta.ema(typical, length * 2) basis = (fast_ema + slow_ema) / 2 vol = ta.stdev(typical, length) smooth_vol = ta.ema(vol, smooth_len) upper = basis + (smooth_vol * sensitivity) lower = basis - (smooth_vol * sensitivity) [basis, upper, lower] get_trend_state(upper, lower, basis) => var float prev_level = na var int trend = 0 if na(prev_level) trend := close > basis ? 1 : -1 prev_level := trend == 1 ? lower : upper if trend == 1 if close < lower trend := -1 prev_level := upper else prev_level := lower else if close > upper trend := 1 prev_level := lower else prev_level := upper [trend, prev_level] [basis, upper, lower] = calculate_trend_levels() [trend, level] = get_trend_state(upper, lower, basis) // SMA filter sma_value = ta.sma(close, sma_length) sma_condition = use_sma_filter ? close > sma_value : true // MACD filter [macd_line, signal_line, _] = ta.macd(close, macd_fast_length, macd_slow_length, macd_signal_length) macd_condition = use_macd_filter ? macd_line > signal_line : true // Signal detection with filters long_signal = trend == 1 and trend[1] == -1 and sma_condition and macd_condition short_signal = trend == -1 and trend[1] == 1 // Plotting visuals p2 = plot(basis, color=trend == 1 ? bullcolor : bearcolor, linewidth=2) p1 = plot(level, color=close > level ? bullcolor : bearcolor, linewidth=2, style=plot.style_linebr) // if showsignals and ta.crossover(close, level) // label.new(bar_index, level, "▲", color=bullcolor, textcolor=chart.bg_color, style=label.style_label_upper_right) // if showsignals and ta.crossunder(close, level) // label.new(bar_index, level, "▼", color=bearcolor, textcolor=chart.fg_color, style=label.style_label_lower_right) qty = strategy.equity / close * leverage_factor // Automated alerts if long_signal alert('{"AccountID": "' + id + '","Key": "' + key + '", "symbol": "' + ticker + '", "action": "long", "volume": ' + str.tostring(qty) + '}', alert.freq_once_per_bar) if short_signal alert('{"AccountID": "' + id + '","Key": "' + key + '", "symbol": "' + ticker + '", "action": "closelong"}', alert.freq_once_per_bar) // Strategy entries and exits if long_signal strategy.entry("Long", strategy.long, qty=qty) if short_signal strategy.close("Long") // Optional SMA and MACD plot plot(use_sma_filter ? sma_value : na, color=color.new(color.blue, 80), title="SMA") plot(use_macd_filter ? macd_line : na, color=color.new(color.orange, 80), title="MACD Line") plot(use_macd_filter ? signal_line : na, color=color.new(color.red, 80), title="Signal Line")