
Chiến lược này là một hệ thống giao dịch định lượng phức hợp dựa trên mức thu hồi và kéo dài Fibonacci kết hợp với phán đoán xu hướng đường trung bình EMA. Chiến lược này giao dịch bằng cách xác định mức kháng cự hỗ trợ quan trọng của thị trường kết hợp với tín hiệu xu hướng. Hệ thống sử dụng 20 chu kỳ và 50 chu kỳ EMA để đánh giá xu hướng thị trường và dựa trên đó sử dụng mức thu hồi Fibonacci để tìm cơ hội giao dịch tốt nhất.
Lịch lý cốt lõi của chiến lược bao gồm ba phần chính: đầu tiên tính toán giá cao nhất và giá thấp nhất trong gần 10 chu kỳ để xác định phạm vi biến động của giá; tiếp theo tính toán năm mức Fibonacci key dựa trên phạm vi này: 0.236, 0.382, 0.5, 0.618, 0.786); cuối cùng xác định hướng xu hướng thông qua sự giao thoa của 20 và 50 chu kỳ EMA. Trong xu hướng tăng, nhiều tín hiệu được phát ra khi giá vượt qua mức thu hồi; trong xu hướng giảm, tín hiệu trống được phát ra khi giá giảm xuống mức thu hồi.
Chiến lược này xây dựng một hệ thống giao dịch tương đối hoàn chỉnh bằng cách kết hợp các công cụ phân tích kỹ thuật cổ điển. Mặc dù có một số nơi cần được tối ưu hóa, nhưng khuôn khổ tổng thể có khả năng thích ứng tốt với thị trường. Với sự tối ưu hóa và cải tiến liên tục, chiến lược này có thể đạt được hiệu suất tốt hơn trong giao dịch thực tế.
/*backtest
start: 2019-12-23 08:00:00
end: 2024-11-11 00:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("Fibonacci Retracement and Extension Strategy", overlay=true)
// Define the Fibonacci levels for retracement and extension
fibRetracementLevels = array.new_float(5)
array.set(fibRetracementLevels, 0, 0.236)
array.set(fibRetracementLevels, 1, 0.382)
array.set(fibRetracementLevels, 2, 0.5)
array.set(fibRetracementLevels, 3, 0.618)
array.set(fibRetracementLevels, 4, 0.786)
fibExtensionLevels = array.new_float(5)
array.set(fibExtensionLevels, 0, 1.618)
array.set(fibExtensionLevels, 1, 2.618)
array.set(fibExtensionLevels, 2, 3.618)
array.set(fibExtensionLevels, 3, 4.236)
array.set(fibExtensionLevels, 4, 5.618)
// Calculate the high and low prices for the last 10 bars
highPrice = ta.highest(high, 10)
lowPrice = ta.lowest(low, 10)
// Calculate the Fibonacci retracement levels
fibRetracement = array.new_float(5)
for i = 0 to 4
array.set(fibRetracement, i, highPrice - (highPrice - lowPrice) * array.get(fibRetracementLevels, i))
// Calculate the trend using the Exponential Moving Average (EMA)
shortEMA = ta.ema(close, 20)
longEMA = ta.ema(close, 50)
// Define the trend conditions
isUptrend = shortEMA > longEMA
isDowntrend = shortEMA < longEMA
// Generate buy and sell signals
var float lastFibRetracementLevel = na
var float lastFibExtensionLevel = na
// Buy condition: price crosses above the highest retracement level
if (isUptrend)
for i = 0 to 4
if (close > array.get(fibRetracement, i))
lastFibRetracementLevel := array.get(fibRetracement, i)
strategy.entry("Buy", strategy.long)
// Sell condition: price crosses below the lowest retracement level
if (isDowntrend)
for i = 0 to 4
if (close < array.get(fibRetracement, i))
lastFibRetracementLevel := array.get(fibRetracement, i)
strategy.entry("Sell", strategy.short)
// Plotting the Fibonacci levels on the chart
// for i = 0 to 4
// line.new(bar_index[10], array.get(fibRetracement, i), bar_index, array.get(fibRetracement, i), color=color.new(color.blue, 70), width=1)
// Plot the EMAs
plot(shortEMA, color=color.red, title="Short EMA")
plot(longEMA, color=color.blue, title="Long EMA")