
이 전략은 트렌드 추적과 진동 지표의 장점을 결합 한 다중 기술 지표에 기반 한 거래 시스템입니다. 핵심 논리는 SMA 평균의 교차로 트렌드 방향을 판단하고, ADX를 사용하여 트렌드 강도를 확인하고, 추후 무작위 RSI를 사용하여 트렌드 방향에서 최적의 입구를 찾고, 추적 스톱 로드를 사용하여 이익을 보호합니다. 이 전략은 5 분 시간 주기 거래에 적합하며, 시장의 주요 트렌디 성 기회를 효과적으로 포착 할 수 있습니다.
전략의 구체적인 작동 원리는 다음과 같습니다.
이 전략은 여러 클래식 기술 지표를 조합하여 포괄적인 거래 시스템을 구축한다. 주요 트렌드를 포착할 수 있고, 트렌드에서 최적의 진입점을 찾을 수 있으며, 완벽한 위험 관리 메커니즘을 갖추고 있다. 일부 고유한 위험이 존재하지만, 지속적인 최적화와 세밀한 파라미터 조정으로 이 전략은 다양한 시장 환경에서 안정적인 성능을 유지할 것으로 예상된다. 전략의 모듈화 설계는 후속 최적화에 좋은 토대를 제공하며, 실제 거래 효과에 따라 지속적으로 개선 및 개선 할 수 있다.
/*backtest
start: 2024-02-18 00:00:00
end: 2025-02-17 00:00:00
period: 2h
basePeriod: 2h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=6
strategy("XAU/USD 5M SMA + Stochastic RSI + ADX Strategy", overlay=true, default_qty_type=strategy.fixed, default_qty_value=1)
// === Входные параметры ===
sma_fast_length = input(20, title="SMA Fast Period")
sma_slow_length = input(200, title="SMA Slow Period")
stoch_k_length = input(14, title="Stochastic RSI K Length")
stoch_d_length = input(3, title="Stochastic RSI D Length")
adx_length = input(10, title="ADX Period")
adx_smoothing = input(10, title="ADX Smoothing Period")
atr_length = input(14, title="ATR Period")
// === Уровни фильтрации ===
adx_min_trend = input(20, title="ADX Minimum Trend Strength") // Было 25 → уменьшено до 20
stoch_buy_level = input(30, title="Stoch RSI Buy Level") // Было 20 → увеличено для входов
stoch_sell_level = input(70, title="Stoch RSI Sell Level") // Было 80 → снижено для входов
// === Трейлинг-стоп ===
use_trailing_stop = input(true, title="Enable Trailing Stop")
trailing_stop_pips = input(40, title="Trailing Stop (Pips)") // Было 50 → уменьшено для активной торговли
trailing_step_pips = input(5, title="Trailing Step (Pips)")
// === Управление позициями ===
entry_delay = input(1, title="Bars Delay Before Re-Entry") // Было 2 → уменьшено до 1
// === Расчёт индикаторов ===
sma_fast = ta.sma(close, sma_fast_length)
sma_slow = ta.sma(close, sma_slow_length)
[diPlus, diMinus, adx_value] = ta.dmi(adx_length, adx_smoothing)
atr_value = ta.atr(atr_length)
// === Stochastic RSI ===
stoch_rsi_k = ta.stoch(close, stoch_k_length, stoch_d_length, stoch_d_length)
stoch_rsi_d = ta.sma(stoch_rsi_k, stoch_d_length)
// === Фильтр волатильности (Убран, если мешает входам) ===
// atr_threshold = ta.sma(atr_value, 20)
// volatility_ok = atr_value > atr_threshold // Комментируем, если ATR слишком строгий
// === Пересечения ===
sma_crossover = ta.crossover(sma_fast, sma_slow)
sma_crossunder = ta.crossunder(sma_fast, sma_slow)
stoch_rsi_crossover = ta.crossover(stoch_rsi_k, stoch_rsi_d)
stoch_rsi_crossunder = ta.crossunder(stoch_rsi_k, stoch_rsi_d)
// === Условия входа ===
longCondition = sma_crossover and adx_value > adx_min_trend and stoch_rsi_crossover and stoch_rsi_k < stoch_buy_level
shortCondition = sma_crossunder and adx_value > adx_min_trend and stoch_rsi_crossunder and stoch_rsi_k > stoch_sell_level
// === Исправленный таймер на повторные входы ===
barsSinceExit = ta.barssince(strategy.position_size == 0)
canReenter = not na(barsSinceExit) and barsSinceExit > entry_delay
// === Переворот позиции (исправлен) ===
if strategy.position_size > 0 and shortCondition and canReenter
strategy.close("BUY")
strategy.entry("SELL", strategy.short)
if strategy.position_size < 0 and longCondition and canReenter
strategy.close("SELL")
strategy.entry("BUY", strategy.long)
// === Открытие позиций ===
if strategy.position_size == 0 and longCondition
strategy.entry("BUY", strategy.long)
if strategy.position_size == 0 and shortCondition
strategy.entry("SELL", strategy.short)
// === Трейлинг-стоп (работает корректно) ===
if use_trailing_stop
strategy.exit("Exit Long", from_entry="BUY", trail_points=trailing_stop_pips, trail_offset=trailing_step_pips)
strategy.exit("Exit Short", from_entry="SELL", trail_points=trailing_stop_pips, trail_offset=trailing_step_pips)
// === Визуализация ===
plot(sma_fast, color=color.blue, title="SMA 20")
plot(sma_slow, color=color.red, title="SMA 200")
hline(stoch_buy_level, title="Stoch RSI Buy Level", color=color.blue)
hline(stoch_sell_level, title="Stoch RSI Sell Level", color=color.purple)
hline(adx_min_trend, title="ADX Min Trend Level", color=color.orange)