该策略是一个基于斐波那契回撤水平的高级趋势追踪和反转交易系统。它通过动态识别价格的高低点,自动计算并绘制七个关键的斐波那契回撤水平(0%, 23.6%, 38.2%, 50%, 61.8%, 78.6%和100%),以此来识别潜在的支撑和阻力位。系统采用双向交易机制,既可以捕捉上升趋势中的买入机会,也可以在下跌趋势中进行做空操作。
策略的核心逻辑基于以下几个关键要素: 1. 动态高低点识别:通过用户自定义的回溯期计算最高点和最低点,确保斐波那契水平的实时更新。 2. 双向交易信号:在61.8%回撤位上方突破时触发做多信号,在38.2%回撤位下方突破时触发做空信号。 3. 精确的退出机制:多头在达到23.6%水平时退出,空头在达到78.6%水平时退出。 4. 视觉优化选项:提供紧凑线条显示模式,减少图表视觉干扰。
该策略通过结合经典的斐波那契回撤理论和现代量化交易技术,构建了一个全面的交易系统。其优势在于能够自动识别关键价格水平并提供清晰的交易信号,但同时也需要注意市场环境对策略表现的影响。通过建议的优化方向,策略的稳定性和盈利能力有望得到进一步提升。
/*backtest
start: 2024-01-06 00:00:00
end: 2025-01-05 00:00:00
period: 3h
basePeriod: 3h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("Fibonacci Retracement Strategy for Crypto", overlay=true)
// Input parameters
lookback = input.int(50, title="Lookback Period", minval=1)
plotLevels = input.bool(true, title="Plot Fibonacci Levels?")
compactLines = input.bool(true, title="Compact Fibonacci Lines?")
// Calculate highest high and lowest low for the lookback period
highestHigh = ta.highest(high, lookback)
lowestLow = ta.lowest(low, lookback)
// Fibonacci retracement levels
diff = highestHigh - lowestLow
level0 = highestHigh
level23_6 = highestHigh - diff * 0.236
level38_2 = highestHigh - diff * 0.382
level50 = highestHigh - diff * 0.5
level61_8 = highestHigh - diff * 0.618
level78_6 = highestHigh - diff * 0.786
level100 = lowestLow
// Plot Fibonacci levels (compact mode to make lines shorter)
// if plotLevels
// lineStyle = compactLines ? line.style_dashed : line.style_solid
// line.new(bar_index[lookback], level0, bar_index, level0, color=color.green, width=1, style=lineStyle)
// line.new(bar_index[lookback], level23_6, bar_index, level23_6, color=color.blue, width=1, style=lineStyle)
// line.new(bar_index[lookback], level38_2, bar_index, level38_2, color=color.blue, width=1, style=lineStyle)
// line.new(bar_index[lookback], level50, bar_index, level50, color=color.orange, width=1, style=lineStyle)
// line.new(bar_index[lookback], level61_8, bar_index, level61_8, color=color.red, width=1, style=lineStyle)
// line.new(bar_index[lookback], level78_6, bar_index, level78_6, color=color.red, width=1, style=lineStyle)
// line.new(bar_index[lookback], level100, bar_index, level100, color=color.green, width=1, style=lineStyle)
// Long trade: Buy when price crosses above 61.8% retracement
longCondition = ta.crossover(close, level61_8)
if longCondition
strategy.entry("Long", strategy.long, alert_message="Price bounced off Fibonacci level - Enter Long")
// Short trade: Sell when price crosses below 38.2% retracement
shortCondition = ta.crossunder(close, level38_2)
if shortCondition
strategy.entry("Short", strategy.short, alert_message="Price crossed below Fibonacci level - Enter Short")
// Exit conditions
exitLong = close >= level23_6
if exitLong
strategy.close("Long", alert_message="Price reached 23.6% Fibonacci level - Exit Long")
exitShort = close <= level78_6
if exitShort
strategy.close("Short", alert_message="Price reached 78.6% Fibonacci level - Exit Short")