
이 전략은 주로 ATR ((Average True Range, 평균 실제 변동 범위) 와 SMA ((Simple Moving Average, 간단한 이동 평균) 두 지표를 사용하여 시장의 정리와 돌파구를 판단하여 거래한다. 전략의 주요 아이디어는: 가격이 ATR 상하 궤도를 돌파할 때, 시장이 돌파구가 발생했다고 생각하며, 포지션을 열다. 가격이 ATR 궤도 안에 돌아 왔을 때, 시장이 정리되어 평정 포지션이 종료되었다고 생각한다. 동시에, 전략은 위험 제어 및 포지션 관리를 사용하여 각 거래의 위험과 포지션 크기를 제어한다.
이 전략은 ATR와 SMA라는 두 가지 간단한 지표를 사용하여 가격의 돌파와 정리 등을 판단하여 거래를 수행하며, 위험 제어 및 포지션 관리를 사용하여 각 거래의 위험과 포지션 크기를 제어합니다. 전략의 논리는 명확하고 이해하기 쉽고 구현되지만 실제 응용에서는 전략의 성과에 영향을 미치는 변수 설정이 너무 커서 동요 시장에서 좋지 않은 성능, 중지 및 중지 설정이 충분하지 않으며, 포지션 관리가 너무 단순합니다. 따라서 실제 응용에서는 추세 필터를 추가하여 더 유연한 중지 및 중지 방식을 사용하거나 더 복잡한 포지션 관리 방법을 사용하여 전략의 신뢰성 및 안정성을 높이기 위해 다른 조건을 추가합니다.
/*backtest
start: 2024-05-09 00:00:00
end: 2024-05-16 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("Consolidation Breakout Strategy", overlay=true)
// Input Parameters
length = input.int(20, "Length", minval=1)
multiplier = input.float(2.0, "Multiplier", minval=0.1, maxval=10.0)
risk_percentage = input.float(1.0, "Risk Percentage", minval=0.1, maxval=10.0)
stop_loss_percentage = input.float(1.0, "Stop Loss Percentage", minval=0.1, maxval=10.0)
take_profit_percentage = input.float(2.0, "Take Profit Percentage", minval=0.1, maxval=10.0)
// ATR calculation
atr_value = ta.atr(length)
// Average price calculation
average_price = ta.sma(close, length)
// Upper and lower bounds for consolidation detection
upper_bound = average_price + multiplier * atr_value
lower_bound = average_price - multiplier * atr_value
// Consolidation detection
is_consolidating = (high < upper_bound) and (low > lower_bound)
// Breakout detection
is_breakout_up = high > upper_bound
is_breakout_down = low < lower_bound
// Entry conditions
enter_long = is_breakout_up and not is_consolidating
enter_short = is_breakout_down and not is_consolidating
// Exit conditions
exit_long = low < (average_price - atr_value * stop_loss_percentage) or high > (average_price + atr_value * take_profit_percentage)
exit_short = high > (average_price + atr_value * stop_loss_percentage) or low < (average_price - atr_value * take_profit_percentage)
// Risk calculation
risk_per_trade = strategy.equity * (risk_percentage / 100)
position_size = risk_per_trade / atr_value
// Strategy
if (enter_long)
strategy.entry("Long", strategy.long, qty=position_size)
if (enter_short)
strategy.entry("Short", strategy.short, qty=position_size)
if (exit_long)
strategy.close("Long")
if (exit_short)
strategy.close("Short")