Strategy vault / Trend following
Adaptive Trend Following Strategy Based on Fibonacci Retracement
This strategy is a trend-following trading system based on the Fibonacci retracement principle. It utilizes Fibonacci levels to determine market trends and potential reversal points, executing trades based on these…

Overview
This strategy is a trend-following trading system based on the Fibonacci retracement principle. It utilizes Fibonacci levels to determine market trends and potential reversal points, executing trades based on these levels. The core of the strategy lies in identifying price crossovers with key Fibonacci levels as entry and exit signals. Additionally, the strategy incorporates a dynamic stop-loss and take-profit mechanism to manage risk and lock in profits.
Strategy Principles
Fibonacci Level Calculation: The strategy first calculates Fibonacci retracement levels based on the highest and lowest prices of the past 20 candles. It focuses on two key levels: 61.8% and 38.2%.
Trade Signal Generation:
- A long signal is triggered when the price crosses above the 61.8% level.
- A short signal is triggered when the price crosses below the 38.2% level.
Position Management: The strategy enters long or short positions directly when signals occur.
Stop-Loss and Take-Profit Settings:
- For long trades: Take-profit = Entry price + target_points Stop-loss = Entry price - stop_loss_points
- For short trades: Take-profit = Entry price - target_points Stop-loss = Entry price + stop_loss_points
Visualization: The strategy plots the 61.8% and 38.2% Fibonacci levels on the chart for easy observation by traders.
Strategy Advantages
High Adaptability: By dynamically calculating Fibonacci levels, the strategy can adapt to different market environments and volatilities.
Combines Trend Following and Reversal: The strategy captures both trend continuation (breakout of 61.8% level) and potential reversals (breakdown of 38.2% level), enhancing trading comprehensiveness.
Comprehensive Risk Management: Built-in dynamic stop-loss and take-profit mechanism effectively controls risk exposure for each trade.
Flexible Parameters: Allows users to customize the number of historical candles, target points, and stop-loss points to suit different trading styles and market characteristics.
Visual Support: Graphical display of Fibonacci levels helps traders intuitively understand market structure and potential support/resistance levels.
Strategy Risks
False Breakout Risk: In range-bound markets, price may frequently cross Fibonacci levels, leading to multiple false signals.
Slippage Impact: In highly volatile markets, actual execution prices may significantly deviate from signal prices.
Limitations of Fixed Stop-Loss and Take-Profit: Using fixed point values for stop-loss and take-profit may not be suitable for all market environments, especially when volatility changes significantly.
Overtrading Risk: Under certain market conditions, the strategy may generate too many trading signals, increasing transaction costs.
Single Timeframe Limitation: Relying solely on signals from a single timeframe may overlook larger market trends.
Strategy Optimization Directions
Introduce Trend Filters: Incorporate longer-term moving averages or ADX indicators to ensure trading in the direction of the main trend.
Dynamic Stop-Loss and Take-Profit: Adjust stop-loss and take-profit levels dynamically based on ATR (Average True Range) to adapt to different market volatilities.
Multi-Timeframe Analysis: Integrate Fibonacci levels from higher timeframes to improve trading decision reliability.
Add Volume Confirmation: Consider volume factors when generating signals to filter out low-quality breakouts.
Optimize Parameter Selection: Utilize backtesting data and machine learning algorithms to find optimal parameter combinations for different market environments.
Incorporate Other Technical Indicators: Combine RSI or MACD indicators to add confirmation mechanisms for trading signals.
Improve Entry Timing: Consider setting limit orders near Fibonacci levels instead of simple market orders to obtain better execution prices.
Conclusion
The Adaptive Trend Following Strategy Based on Fibonacci Retracement is a trading system that combines classical technical analysis principles with modern quantitative trading techniques. It seeks to balance trend continuation and potential reversals by dynamically identifying key price levels, providing traders with a flexible and systematic trading approach.
The core advantages of the strategy lie in its adaptability and risk management capabilities, allowing it to maintain relatively stable performance across different market environments. However, traders using this strategy need to be aware of potential risks such as false breakouts and overtrading, and consider introducing additional filtering mechanisms and multi-dimensional analysis to further enhance the strategy's robustness.
Through continuous optimization and improvement, such as introducing dynamic stop-loss and take-profit mechanisms and multi-timeframe analysis, this strategy has the potential to become a more comprehensive and efficient trading system. Ultimately, traders need to personalize the strategy based on their own risk preferences and market insights to achieve optimal trading results.
Source Pine Script
/*backtest
start: 2024-06-30 00:00:00
end: 2024-07-30 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("Fibonacci Retracement Strategy", overlay=true)
// Input parameters
fib_levels = input.bool(true, title="Show Fibonacci Levels")
n = input.int(20, title="Number of Historical Candles")
target_points = input.int(100, title="Target Points")
stop_loss_points = input.int(50, title="Stop Loss Points")
// Calculate Fibonacci levels
high_price = ta.highest(close, 20)
low_price = ta.lowest(close, 20)
range_ = high_price - low_price
fib618 = high_price - range_ * 0.618
fib382 = high_price - range_ * 0.382
// Strategy logic
long_condition = ta.crossover(close, fib618)
short_condition = ta.crossunder(close, fib382)
// Plot Fibonacci levels
plot(fib_levels ? fib618 : na , "61.8%", color=color.blue, trackprice=true)
plot(fib_levels ? fib382 : na , "38.2%", color=color.red, trackprice=true)
// Strategy entry and exit
if long_condition
strategy.entry("Long", strategy.long)
if short_condition
strategy.entry("Short", strategy.short)
// Calculate target and stop loss levels
long_target = strategy.position_avg_price + target_points
long_stop_loss = strategy.position_avg_price - stop_loss_points
short_target = strategy.position_avg_price - target_points
short_stop_loss = strategy.position_avg_price + stop_loss_points
// Strategy exit
strategy.exit("Long Exit", "Long", limit=long_target, stop=long_stop_loss)
strategy.exit("Short Exit", "Short", limit=short_target, stop=short_stop_loss)
Published by ChaoZhang on the FMZ strategy square · last modified 2024-07-31. Collected in the Quant Trading Vault. Unvalidated research: re-test with your own data and costs before trusting it.
Build this with AgenKit
A spec is not a trading system. Paste this into your coding agent and AgenKit runs a specialist team — architecture, test-first build, risk gates, review — with paper trading on by default.
/agenkit build a production-grade trading bot with a backtest engine, risk controls and paper trading by default from strategies/Adaptive-Trend-Following-Strategy-Based-on-Fibonacci-Retracement.md- npx agenkit install engineering-kit in your project
- Paste the command into your agent and approve each phase
- Get tests, backtest, risk controls and a paper-trading switch
Understand it first
Before you run this, read the lesson behind the idea and how to backtest it honestly. Specs like this one are the survivors of an unknown number of trials; deflate their results accordingly.
Related specs
- Automated Fibonacci Retracement Trading System StrategyPine Script · Trend following · 1d
- Incremental Order Size Fibonacci Retracement Trend Following StrategyPine Script · Trend following · 1d
- Double Filtering High Frequency Quantitative Trading StrategyPine Script · Trend following · 1m
- Multi Period Trend Confirmation Dynamic Risk Control Quantitative Trading StrategyPine Script · Trend following · 1h
- Advanced Dynamic Fibonacci Retracement Trend Quantitative Trading StrategyPine Script · Trend following · 1h
- AlphaTradingBot Trading StrategyPine Script · Trend following · 1h