
This strategy is an automated trading system that combines Exponential Moving Average (EMA) crossover signals with Fibonacci retracement levels. It identifies market trend direction through the crossover of fast and slow EMAs while using automatically calculated Fibonacci levels to set intelligent stop-loss and take-profit points. The strategy aims to capture market trend changes while protecting capital through preset risk management parameters.
The core logic of this strategy is based on the following points:
EMA Crossover Signals: The system uses two exponential moving averages with different periods (fast EMA with 9 periods and slow EMA with 21 periods) to identify trend changes. When the fast EMA crosses above the slow EMA, a long signal is generated; when the fast EMA crosses below the slow EMA, a short signal is generated.
Anti-Repainting Design: The strategy uses the barstate.isconfirmed condition to ensure signals are only confirmed after a bar closes, effectively avoiding signal repainting issues and improving reliability.
Automatic Fibonacci Levels: The system automatically identifies the highest and lowest points within a user-defined lookback period (default 100 bars), then calculates key Fibonacci retracement levels (0.382 and 0.618).
Smart Stop-Loss and Take-Profit Settings:
Customizable Parameters: The strategy provides multiple adjustable parameters, including EMA period lengths, stop-loss percentage, take-profit percentage, trailing stop-loss percentage, Fibonacci lookback period, and trade quantity, allowing users to optimize according to their risk preferences and market conditions.
Trend Following and Reversal Capture: By combining EMA crossovers and Fibonacci levels, the strategy effectively captures market trend changes while setting stop-losses and take-profits at important support and resistance levels.
Adaptive to Market Conditions: Automatic Fibonacci calculations allow the strategy to adjust stop-loss and take-profit positions based on different market environments, rather than using fixed percentages, making it relatively stable across markets with varying volatility.
Anti-Repainting Mechanism: By using barstate.isconfirmed and lookahead=barmerge.lookahead_off parameters, the strategy ensures all signals are based on closed bars, eliminating discrepancies between backtesting and live trading.
Multi-Timeframe Analysis: The strategy allows users to select different signal timeframes, enabling cross-timeframe analysis and improving signal quality.
Visualized Trading Signals: The strategy clearly marks buy/sell points, stop-loss, and take-profit positions on the chart, allowing traders to visually understand trading logic and risk management.
Integrated Alert Functionality: Built-in trading signal alerts make real-time market opportunity monitoring convenient.
False Breakout Risk: EMA crossover signals may generate frequent false breakouts in sideways markets, leading to consecutive losses. This can be mitigated by adding additional filtering conditions (such as volume confirmation, volatility filters, or trend strength indicators).
Excessive Stop-Loss Distance: Under certain market conditions, stop-loss positions based on Fibonacci levels may be relatively far from entry points, increasing risk per trade. Consider setting maximum stop-loss distance limits or using ATR (Average True Range) to dynamically adjust stop-loss distances.
Parameter Optimization Trap: Excessive parameter optimization may lead to good performance on historical data but fail in future markets. Forward testing and robustness testing are recommended to verify strategy stability.
Insufficient Money Management: The strategy uses fixed quantity trading by default, without adjusting position size based on account size and risk. Integrating money management modules, such as fixed risk percentage or Kelly criterion, is recommended for dynamic position sizing.
Lack of Market Condition Filtering: The strategy generates signals under all market conditions, without distinguishing between trending and ranging markets. Adding market environment recognition functionality to use different trading parameters or pause trading in different market states could improve performance.
Add Multi-Timeframe Confirmation: Introduce longer-period trend confirmation mechanisms, executing trades only when the main trend direction is consistent, reducing counter-trend trading frequency. For example, check daily or weekly trend direction and only execute long positions when the daily trend is upward.
Integrate Volatility Adjustment: Introduce the ATR indicator to dynamically adjust stop-loss and take-profit distances, allowing the strategy to adapt to different volatility environments. Increase stop-loss distance in high volatility and decrease it in low volatility.
Add Volume Confirmation: Check for volume expansion when signals are generated, executing trades only when supported by volume to improve signal quality.
Optimize Money Management: Implement dynamic position management based on account size and risk, ensuring each trade’s risk is controlled at a fixed percentage of total capital.
Develop Market Environment Filters: Design a market state recognition module to distinguish between trending and ranging markets, adopting different trading strategies or parameters in different market states.
Optimize Fibonacci Parameters: The current strategy uses fixed 0.382 and 0.618 Fibonacci levels. Testing other levels (such as 0.5 or 0.786) or dynamically selecting optimal Fibonacci levels based on market characteristics could improve performance.
Add Trading Time Filters: Pause trading during important economic data releases or periods of insufficient market liquidity to avoid excessive slippage and unpredictable market behavior.
This is an intelligent trading strategy that combines classic technical analysis tools, identifying trend changes through EMA crossovers, utilizing Fibonacci levels to set key support and resistance points, and implementing automatic stop-loss and take-profit management. The strategy’s strengths lie in its adaptability and comprehensive risk management system, but attention must still be paid to false breakout risks and parameter over-optimization.
By adding multi-timeframe confirmation, volatility adjustment, volume filtering, and market environment recognition, this strategy can further enhance its stability and profitability. For traders seeking systematic trading methods, it provides a solid foundational framework that can be further customized and optimized according to individual trading styles and market characteristics.
/*backtest
start: 2024-08-13 00:00:00
end: 2025-08-11 08:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT","balance":5000000}]
*/
//@version=5
strategy("ETH Futures Auto Buyer with Auto Fib by Govind", overlay=true, max_labels_count=500)
// ===== Inputs =====
timeframe_input = input.timeframe("5", "Signal Timeframe")
fastLen = input.int(9, "Fast EMA Length")
slowLen = input.int(21, "Slow EMA Length")
slPercent = input.float(0.5, "Stop Loss %")
tpPercent = input.float(1.0, "Take Profit %")
trailPercent = input.float(0.3, "Trailing SL %")
lookbackBars = input.int(100, "Fib Swing Lookback")
qty = input.int(1, "Order Quantity", minval=1)
// ===== EMA Logic with no repainting =====
price = request.security(syminfo.tickerid, timeframe_input, close, lookahead=barmerge.lookahead_off)
emaFast = request.security(syminfo.tickerid, timeframe_input, ta.ema(close, fastLen), lookahead=barmerge.lookahead_off)
emaSlow = request.security(syminfo.tickerid, timeframe_input, ta.ema(close, slowLen), lookahead=barmerge.lookahead_off)
longSignal = ta.crossover(emaFast, emaSlow)
shortSignal = ta.crossunder(emaFast, emaSlow)
// Confirm signals only on closed bar (no repaint)
longSignalConfirmed = longSignal and barstate.isconfirmed
shortSignalConfirmed = shortSignal and barstate.isconfirmed
// ===== Auto Fibonacci Levels =====
swingHigh = ta.highest(high, lookbackBars)
swingLow = ta.lowest(low, lookbackBars)
fib618 = swingHigh - (swingHigh - swingLow) * 0.618
fib382 = swingHigh - (swingHigh - swingLow) * 0.382
// ===== SL & TP Prices =====
longSL = fib618
shortSL = fib382
longTP = swingHigh
shortTP = swingLow
// ===== Strategy Entries =====
if (longSignalConfirmed)
strategy.entry("Long", strategy.long, qty)
strategy.exit("Long Exit", from_entry="Long", stop=longSL, limit=longTP)
if (shortSignalConfirmed)
strategy.entry("Short", strategy.short, qty)
strategy.exit("Short Exit", from_entry="Short", stop=shortSL, limit=shortTP)
// ===== Plotting =====
plot(longSL, color=color.lime, title="Long SL")
plot(shortSL, color=color.fuchsia, title="Short SL")
plot(longTP, color=color.blue, title="Long TP")
plot(shortTP, color=color.orange, title="Short TP")
plotshape(longSignalConfirmed, title="Long Signal", style=shape.labelup, text="BUY", location=location.belowbar, color=color.green, size=size.small)
plotshape(shortSignalConfirmed, title="Short Signal", style=shape.labeldown, text="SELL", location=location.abovebar, color=color.red, size=size.small)
// ===== Alerts =====
alertcondition(longSignalConfirmed, title="Long Signal", message="ETH Futures LONG Entry")
alertcondition(shortSignalConfirmed, title="Short Signal", message="ETH Futures SHORT Entry")