This strategy is a composite quantitative trading system based on Fibonacci retracement and extension levels, combined with EMA trend determination. The strategy identifies important support and resistance levels in the market and executes trades based on trend signals. The system uses 20-period and 50-period EMAs to determine market trends and utilizes Fibonacci retracement levels to find optimal trading opportunities.
The core logic consists of three main components: First, it calculates the highest and lowest prices over the past 10 periods to determine the price range; Second, it computes five key Fibonacci retracement levels (0.236, 0.382, 0.5, 0.618, 0.786) based on this range; Finally, it determines trend direction through the crossover of 20 and 50-period EMAs. Buy signals are generated when price breaks above retracement levels in an uptrend, while sell signals are triggered when price breaks below retracement levels in a downtrend.
The strategy builds a relatively complete trading system by combining classic technical analysis tools. While there are areas for optimization, the overall framework demonstrates good market adaptability. Through continuous optimization and improvement, the strategy shows promise for better performance in actual trading. It is recommended to conduct thorough historical data backtesting and parameter optimization before live trading.
/*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")