
이 전략은 시장 환경에 따라 거래 방향을 자동으로 조정할 수 있는 유연한 포지션 관리 메커니즘을 채택하고 있으며, 위험 제어 기능을 갖추고 있다. 이 전략은 다중 포지션 양방향 거래를 지원하며, 선택적으로 스윙 거래 모드를 시작할 수 있으며, 강한 적응력을 가지고 있다.
전략은 주로 시간 주기와 포지션 상태를 통해 거래를 제어한다. 우선 inActivePeriod () 함수를 통해 가장 가까운 500 K 선의 유효 거래 범위 내에 있는지 확인한다. 유효 범위 내에서 전략은 포지션 상태 (positionHeld), 포지션 시간 (barsHeld) 및 일시 중지 시간 (barsPaused) 과 같은 변수에 따라 거래 행동을 결정한다. 휘어지는 거래 모드를 활성화하면 전략은 다공간 방향에서 빠르게 회전한다. 휘어지는 거래 모드를 비활성화하면 전략은 포지션을 3주기 후 평정하고 새로운 거래 기회를 기다린다.
이 전략은 시간주기 제어 및 다공간 회전 방식으로 시장 수익을 획득하며, 강력한 유연성과 적응력을 가지고 있다. 약간의 위험이 있지만, 합리적인 최적화 및 위험 제어 조치를 통해 전략의 안정성과 수익성을 크게 향상시킬 수 있다. 전략의 핵심 장점은 단순하고 효과적인 거래 논리이며, 기본 전략에 대한 추가 최적화 및 확장에 적합하다.
/*backtest
start: 2024-10-12 00:00:00
end: 2024-11-11 00:00:00
period: 4h
basePeriod: 4h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("Tickerly Test Strategy", overlay=true)
// Inputs
longEnabled = input.bool(true, "Enable Long Trades")
shortEnabled = input.bool(true, "Enable Short Trades")
swingEnabled = input.bool(false, "Enable Swing Trading")
// Variables
var positionHeld = 0
var barsHeld = 0
var barsPaused = 0
var lastAction = "none"
// Function to determine if we're in the last 500 bars
inActivePeriod() =>
barIndex = bar_index
lastBarIndex = last_bar_index
barIndex >= (lastBarIndex - 499)
// Main strategy logic
if inActivePeriod()
if swingEnabled
if positionHeld == 0 and barstate.isconfirmed
if lastAction != "long"
strategy.entry("Long", strategy.long)
positionHeld := 1
barsHeld := 0
lastAction := "long"
else
strategy.entry("Short", strategy.short)
positionHeld := -1
barsHeld := 0
lastAction := "short"
if positionHeld != 0
barsHeld += 1
if barsHeld >= 2
if positionHeld == 1
strategy.entry("Short", strategy.short)
positionHeld := -1
barsHeld := 0
lastAction := "short"
else
strategy.entry("Long", strategy.long)
positionHeld := 1
barsHeld := 0
lastAction := "long"
else
if positionHeld == 0 and barsPaused >= 1 and barstate.isconfirmed
if longEnabled and shortEnabled
if lastAction != "long"
strategy.entry("Long", strategy.long)
positionHeld := 1
barsHeld := 0
barsPaused := 0
lastAction := "long"
else
strategy.entry("Short", strategy.short)
positionHeld := -1
barsHeld := 0
barsPaused := 0
lastAction := "short"
else if longEnabled
strategy.entry("Long", strategy.long)
positionHeld := 1
barsHeld := 0
barsPaused := 0
lastAction := "long"
else if shortEnabled
strategy.entry("Short", strategy.short)
positionHeld := -1
barsHeld := 0
barsPaused := 0
lastAction := "short"
if positionHeld != 0
barsHeld += 1
if barsHeld >= 3
strategy.close_all()
positionHeld := 0
barsHeld := 0
barsPaused := 0 // Reset pause counter when exiting a position
else
barsPaused += 1
// Plotting active period for visual confirmation
plot(inActivePeriod() ? 1 : 0, "Active Period", color=color.new(color.blue, 80), style=plot.style_areabr)