
이 전략은 피보나치 회귀 레벨에 기반한 트렌드 추적 전략이다. 전략은 주로 전날 거래의 최고 가격과 최저 가격을 계산하는 중요한 피보나치 회귀 레벨을 활용하여, 개시 가격 위치와 시간 창을 결합하여 여러 개의 입문 조건을 설정하고, 다른 조건에 대해 그에 따른 중지 위치를 설정하여, 트렌드에 대한 파악과 위험을 제어한다.
전략은 먼저 여섯 가지 중요한 피보나치 회수 수준을 계산합니다: 0.23.6%, 38.2%, 50%, 61.8%, 그리고 100%. 오픈 가격의 이러한 수준에 대한 위치에 따라 입점 조건을 세 가지로 나눕니다: 1) 오픈 가격이 23.6%-50% 사이; 2) 오픈 가격은 61.8%이며 지정된 시간 창에 있습니다: 9.15-9:30); 3) 오픈 가격은 23.6%보다 낮고 전날의 낮은 가격입니다.
이 전략은 피보나치 회귀 수준, 시간 창 및 다중 조건 판단을 결합하여 보다 완전한 거래 시스템을 구축한다. 전략의 장점은 논리적으로 명확하고, 위험이 통제 가능하지만, 여전히 시장 상황에 따라 최적화 및 개선이 필요하다. 추세 판단, 동적 스톱 손실 및 거래량 분석 등의 측면의 최적화를 추가함으로써 전략의 안정성과 수익성을 더욱 향상시킬 수 있다.
/*backtest
start: 2024-11-19 00:00:00
end: 2024-12-18 08:00:00
period: 1h
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=6
strategy("Fibonacci Retracement Strategy", overlay=true)
// Get the high and low of the previous day
previousHigh = request.security(syminfo.tickerid, "D", high[1])
previousLow = request.security(syminfo.tickerid, "D", low[1])
// Fibonacci levels for the previous day (from high to low)
fib0 = previousHigh
fib236 = previousHigh - (previousHigh - previousLow) * 0.236
fib382 = previousHigh - (previousHigh - previousLow) * 0.382
fib50 = previousHigh - (previousHigh - previousLow) * 0.5
fib618 = previousHigh - (previousHigh - previousLow) * 0.618
fib1 = previousHigh - (previousHigh - previousLow) * 1
// Current open price (for the current day)
openPrice = open
// Time for 9:15 AM check
timeStart = timestamp(year, month, dayofmonth, 9, 15)
timeClose = timestamp(year, month, dayofmonth, 9, 30) // Time window to allow for opening range
// Entry Conditions
buyCondition1 = openPrice >= fib236 and openPrice <= fib50
buyCondition2 = openPrice == fib618 and time >= timeStart and time <= timeClose
buyCondition3 = openPrice < fib236 and openPrice < previousLow
// Stop Loss based on conditions
stopLoss1 = fib618
stopLoss2 = fib618 - (fib618 - fib1) / 2
stopLoss3 = fib382
// Plot Fibonacci levels with calculated values
plot(fib0, color=color.green, linewidth=1, title="Fib 0")
plot(fib236, color=color.red, linewidth=1, title="Fib 0.236")
plot(fib382, color=color.blue, linewidth=1, title="Fib 0.382")
plot(fib50, color=color.yellow, linewidth=1, title="Fib 0.5")
plot(fib618, color=color.purple, linewidth=1, title="Fib 0.618")
plot(fib1, color=color.orange, linewidth=1, title="Fib 1")
// Plot labels for Fibonacci levels with actual values
label.new(x=bar_index, y=fib0, text="Fib 0: " + str.tostring(fib0), style=label.style_label_right, color=color.green, textcolor=color.white, size=size.small, yloc=yloc.abovebar)
label.new(x=bar_index, y=fib236, text="Fib 0.236: " + str.tostring(fib236), style=label.style_label_right, color=color.red, textcolor=color.white, size=size.small, yloc=yloc.abovebar)
label.new(x=bar_index, y=fib382, text="Fib 0.382: " + str.tostring(fib382), style=label.style_label_right, color=color.blue, textcolor=color.white, size=size.small, yloc=yloc.abovebar)
label.new(x=bar_index, y=fib50, text="Fib 0.5: " + str.tostring(fib50), style=label.style_label_right, color=color.yellow, textcolor=color.white, size=size.small, yloc=yloc.abovebar)
label.new(x=bar_index, y=fib618, text="Fib 0.618: " + str.tostring(fib618), style=label.style_label_right, color=color.purple, textcolor=color.white, size=size.small, yloc=yloc.abovebar)
label.new(x=bar_index, y=fib1, text="Fib 1: " + str.tostring(fib1), style=label.style_label_right, color=color.orange, textcolor=color.white, size=size.small, yloc=yloc.abovebar)
// Entry conditions and strategy execution
if (buyCondition1)
strategy.entry("Buy", strategy.long, stop=stopLoss1)
label.new(bar_index, low, "BUY", color=color.green, textcolor=color.white, style=label.style_label_up, size=size.small)
if (buyCondition2)
strategy.entry("Buy", strategy.long, stop=stopLoss2)
label.new(bar_index, low, "BUY", color=color.green, textcolor=color.white, style=label.style_label_up, size=size.small)
if (buyCondition3)
strategy.entry("Buy", strategy.long, stop=stopLoss3)
label.new(bar_index, low, "BUY", color=color.green, textcolor=color.white, style=label.style_label_up, size=size.small)
// Show exit signals and labels
if (buyCondition1)
strategy.exit("Exit", from_entry="Buy", stop=stopLoss1)
label.new(bar_index, high, "EXIT", color=color.red, textcolor=color.white, style=label.style_label_down, size=size.small)
if (buyCondition2)
strategy.exit("Exit", from_entry="Buy", stop=stopLoss2)
label.new(bar_index, high, "EXIT", color=color.red, textcolor=color.white, style=label.style_label_down, size=size.small)
if (buyCondition3)
strategy.exit("Exit", from_entry="Buy", stop=stopLoss3)
label.new(bar_index, high, "EXIT", color=color.red, textcolor=color.white, style=label.style_label_down, size=size.small)