
이것은 가격 폭등과 이동 평균 필터링에 기반한 트렌드 추적 거래 시스템이다. 이 전략은 통계적으로 유의미한 가격 폭등 신호를 식별하여 SMA 트렌드 필터와 결합하여 시장이 명확한 추세가 형성될 때 거래한다. 이 전략의 핵심 정신은 공급과 수요의 불균형으로 인한 가격 폭등으로 인한 추세 연장 기회를 포착하는 것이다.
이 전략은 다음과 같은 몇 가지 핵심 요소에 기반을 두고 있습니다.
이 전략은 가격 폭등과 평행선 트렌드 필터를 결합하여 논리적으로 명확하고 위험을 제어할 수 있는 거래 시스템을 구축한다. 합리적으로 설정된 매개 변수와 지속적인 최적화를 통해 이 전략은 트렌드 시장에서 안정적인 수익을 얻을 수 있다. 거래자는 실장에 사용하기 전에 충분한 역사 테스트를 수행하고 특정 시장 특성에 따라 타겟팅 최적화를 수행하는 것이 좋습니다.
/*backtest
start: 2019-12-23 08:00:00
end: 2024-11-27 08:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("Simplified Gap Strategy with SMA Filter", overlay=true)
// Input fields for user control
long_gap_threshold = input.float(0.1, title="Gap Threshold (%)", minval=0.01, step=0.01) // Minimum percentage for gaps
hold_duration = input.int(10, title="Hold Duration (bars)", minval=1) // Duration to hold the position
gap_trade_option = input.string("Long Up Gap", title="Select Trade Option", options=["Long Up Gap", "Short Down Gap", "Short Up Gap", "Long Down Gap"]) // Combined option
use_sma_filter = input.bool(false, title="Use SMA Filter") // Checkbox to activate SMA filter
sma_length = input.int(200, title="SMA Length", minval=1) // Length of the SMA
// RGB color definitions for background
color_up_gap = color.new(color.green, 50) // Green background for up gaps
color_down_gap = color.new(color.red, 50) // Red background for down gaps
// Gap size calculation in percentage terms
gap_size = (open - close[1]) / close[1] * 100 // Gap size in percentage
// Calculate gaps based on threshold input
up_gap = open > close[1] and gap_size >= long_gap_threshold // Long gap condition
down_gap = open < close[1] and math.abs(gap_size) >= long_gap_threshold // Short gap condition
// Calculate the SMA
sma_value = ta.sma(close, sma_length)
// Define the trading logic based on selected option and SMA filter
if (gap_trade_option == "Long Up Gap" and up_gap and (not use_sma_filter or close > sma_value))
strategy.entry("Long", strategy.long)
if (gap_trade_option == "Short Down Gap" and down_gap and (not use_sma_filter or close < sma_value))
strategy.entry("Short", strategy.short)
if (gap_trade_option == "Short Up Gap" and up_gap and (not use_sma_filter or close < sma_value))
strategy.entry("Short", strategy.short)
if (gap_trade_option == "Long Down Gap" and down_gap and (not use_sma_filter or close > sma_value))
strategy.entry("Long", strategy.long)
// Exit position after the hold duration
if (strategy.opentrades > 0)
if (bar_index - strategy.opentrades.entry_bar_index(0) >= hold_duration)
strategy.close("Long")
strategy.close("Short")
// Background coloring to highlight gaps on the chart
bgcolor((gap_trade_option == "Long Up Gap" and up_gap) ? color_up_gap : na, title="Up Gap Background")
bgcolor((gap_trade_option == "Short Down Gap" and down_gap) ? color_down_gap : na, title="Down Gap Background")
bgcolor((gap_trade_option == "Short Up Gap" and up_gap) ? color_down_gap : na, title="Short Up Gap Background")
bgcolor((gap_trade_option == "Long Down Gap" and down_gap) ? color_up_gap : na, title="Long Down Gap Background")
// Plot the SMA for visualization
plot(use_sma_filter ? sma_value : na, color=color.white, title="SMA", linewidth=1)