
이 전략은 시장의 연속적인 운동 특성에 기반한 양적 거래 시스템으로, 가격이 연속적으로 상승하거나 하락하는 빈도를 분석하여 시장 역전 기회를 포착한다. 전략의 핵심은 연속적으로 상승하거나 하락하는 하락값을 설정하고, 하락값이 도달했을 때 역전 작업을 수행하며, 포지션 보유 시간 및 K선 형태와 같은 다차원 지표와 결합하여 거래 결정을 내린다. 이 전략은 시장의 역전 특성을 최대한 활용하여 가격 오버 바이 또는 오버 셀 특성이있는 경우 역전 작업을 수행한다.
전략의 핵심 논리에는 다음과 같은 핵심 요소가 포함됩니다.
이 전략은 시장 역전 특성에 기반한 정량 거래 시스템으로, 가격의 연속적인 움직임을 분석하여 시장 역전 기회를 포착한다. 전략은 합리적으로 설계되어 있으며, 위험을 통제할 수 있지만, 시장 환경에 따라 매개 변수를 조정해야 한다. 지속적인 최적화와 개선을 통해 전략은 실제 거래에서 안정적인 수익을 얻을 수 있다.
/*backtest
start: 2019-12-23 08:00:00
end: 2024-11-27 08:00:00
period: 2d
basePeriod: 2d
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("Streak-Based Trading Strategy", overlay=true)
// User Inputs
trade_direction = input.string(title="Trade Direction", defval="Long", options=["Long", "Short"]) // Option to choose Long or Short
streak_threshold = input.int(title="Streak Threshold", defval=8, minval=1) // Input for number of streaks before trade
hold_duration = input.int(title="Hold Duration (in periods)", defval=7, minval=1) // Input for holding the position
doji_threshold = input.float(0.01, title="Doji Threshold (%)", minval=0.001) / 100 // Doji sensitivity
// Calculate win or loss streak
is_doji = math.abs(close - open) / (high - low) < doji_threshold
win = close > close[1] and not is_doji
loss = close < close[1] and not is_doji
// Initialize variables for streak counting
var int win_streak = 0
var int loss_streak = 0
var bool in_position = false
var int hold_counter = 0
// Track streaks (only when not in a position)
if not in_position
if win
win_streak += 1
loss_streak := 0
else if loss
loss_streak += 1
win_streak := 0
else
win_streak := 0
loss_streak := 0
// Logic for closing the position after the holding duration
if in_position
hold_counter -= 1
if hold_counter <= 0
strategy.close_all() // Close all positions
in_position := false // Reset position flag
win_streak := 0 // Reset streaks after position is closed
loss_streak := 0
// Trade condition (only when no position is open and streak is reached)
if not in_position
if trade_direction == "Long" and loss_streak >= streak_threshold
strategy.entry("Long", strategy.long) // Open a long position
in_position := true
hold_counter := hold_duration // Set holding period
if trade_direction == "Short" and win_streak >= streak_threshold
strategy.entry("Short", strategy.short) // Open a short position
in_position := true
hold_counter := hold_duration // Set holding period
// Plotting streaks for visualization
plot(win_streak, color=color.green, title="Winning Streak", style=plot.style_histogram, linewidth=2)
plot(loss_streak, color=color.red, title="Losing Streak", style=plot.style_histogram, linewidth=2)