
The Dynamic Tracking ADX-Enhanced SMA Crossover Strategy is a quantitative trading system that combines Simple Moving Average (SMA) crossover signals with an Average Directional Index (ADX) filter. This strategy confirms market trend strength using the ADX indicator, executes SMA crossover trading signals only when sufficient momentum exists, and employs dynamic take-profit, stop-loss, and trailing stop mechanisms to protect profits and limit risk. The strategy also includes session close timing to avoid overnight risk.
The core logic of this strategy is based on the following key components:
SMA Crossover Signals: Uses a short-term (default 3-period) Simple Moving Average where buy signals are generated when price crosses above the SMA, and sell signals when price crosses below the SMA.
ADX Filter: Manually calculates the ADX indicator (default period of 15) and only confirms trades when the ADX value exceeds a set threshold (default 15), ensuring sufficient trend strength. This effectively filters out false signals in oscillating markets.
Dynamic Risk Management:
Session Management: Forces closure of all positions at a specified trading session end time (default 16:00) to avoid overnight risk.
Real-time Signal Alerts: Generates JSON-formatted alert messages containing trade direction, entry price, stop-loss price, and take-profit price when trading signals are triggered.
No-Repaint Function: Provides a reso_no_repaint function to ensure indicators don’t repaint, improving strategy reliability.
Trend Confirmation Mechanism: By combining SMA crossovers with the ADX indicator, the strategy effectively identifies strong trend conditions, reducing false signals in oscillating markets. This increases the probability of successful trades compared to pure SMA crossover strategies.
Flexible Risk Management: Offers comprehensive risk control measures including fixed stops, target profits, and trailing stops, allowing traders to adjust parameters according to their risk preferences.
Session Management Functionality: Automatically closes positions at the end of the trading day, avoiding overnight risk, making it particularly suitable for day traders or those wishing to avoid major economic news and event risks.
Real-time Alert System: Provides structured JSON-format alerts, facilitating integration into automated trading systems or notification mechanisms.
Simple Yet Effective: Strategy logic is clear with few parameters, making it easy to understand and adjust, suitable for traders of all levels.
No-Repaint Design: Ensures strategy reliability in live trading environments through the no-repaint function.
Short-term SMA Volatility: The default 3-period SMA may be overly sensitive, potentially generating excessive trading signals in highly volatile markets, increasing transaction costs and possibly leading to consecutive losses. The solution is to adjust the SMA length based on different market conditions and timeframes.
Fixed Point Risk Management: The strategy uses fixed points rather than percentages or ATR multiples for setting profit and loss targets, which may not be flexible enough in different volatility environments. In high-volatility markets, stops may be too small; in low-volatility markets, stops may be too large. Consider switching to ATR-based dynamic risk management.
ADX Lag: ADX is a lagging indicator and may only provide confirmation signals after a trend has already been established, resulting in late entries. This can be improved by optimizing ADX parameters or combining with other leading indicators.
Lack of Market State Differentiation: The strategy doesn’t distinguish between different market states (such as trending, ranging), using the same trading logic in all market environments, which may lead to poor performance in non-trending markets.
Single Timeframe Limitation: The strategy is based solely on single timeframe analysis, lacking multi-timeframe confirmation, potentially missing important market reversals in the context of larger trends.
Dynamic Risk Management Improvement: Replace fixed point profit/loss targets with an ATR (Average True Range) based dynamic risk management system, allowing the strategy to adapt to different market volatility environments. For example, set stop-loss at 1.5x ATR and take-profit at 3x ATR.
Multi-timeframe Analysis: Add higher timeframe trend confirmation, trading only in the direction of the larger trend to improve win rates. Consider adding a longer-period SMA as a trend filter.
Market State Recognition: Introduce market state classification mechanisms, such as volatility indicators or trend strength indicators, to apply different strategy parameters or trading logic in different market environments.
Entry Optimization: Consider adding additional entry confirmation indicators such as RSI (Relative Strength Index) or Bollinger Bands to improve entry signal quality. Also consider implementing a scaled position entry strategy to reduce single-point entry risk.
Adaptive Parameters: Implement parameter adaptation mechanisms that automatically adjust SMA length, ADX threshold, and risk management parameters based on recent market behavior, allowing the strategy to adapt to changing market conditions.
Time Filters: Add trading time filters to avoid low liquidity periods or high volatility news release periods, reducing slippage and abnormal price movement risks.
The Dynamic Tracking ADX-Enhanced SMA Crossover Strategy is a complete trading system combining technical analysis and risk management. By combining simple SMA crossover signals with ADX trend confirmation, the strategy can more precisely identify favorable trading opportunities. The dynamic stop-loss and trailing stop mechanisms provide good risk control, while the session management functionality further reduces overnight risk.
Despite some limitations, such as fixed point risk management and single timeframe analysis, these issues can be addressed through the optimization directions proposed in this article. By introducing ATR-based dynamic risk management, multi-timeframe analysis, and market state recognition, the strategy has the potential to become a more robust and adaptive trading system.
Ultimately, the success of this strategy depends on the trader’s fine-tuning of parameters and adaptability to specific markets and timeframes. It is recommended to conduct thorough backtesting and simulated trading before live trading to validate the strategy’s performance under different market conditions.
/*backtest
start: 2024-08-04 00:00:00
end: 2025-08-02 08:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("safa bot alert", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=100)
// === INPUTS ===
smaLength = input.int(3, title="SMA Length")
tpPoints = input.float(80, title="Take Profit (Points)")
slPoints = input.float(35, title="Stop Loss (Points)")
trailPoints = input.float(15, title="Trailing Stop (Points)")
sessionCloseHour = input.int(16, "Session Close Hour (24h)")
sessionCloseMinute = input.int(0, "Session Close Minute")
// === ADX INPUTS ===
adxLength = input.int(15, title="ADX Length")
adxThreshold = input.float(15, title="Minimum ADX to Trade")
// === INDICATORS ===
sma = ta.sma(close, smaLength)
plot(sma, title="3 SMA", color=color.orange)
// === MANUAL ADX CALCULATION ===
upMove = high - high[1]
downMove = low[1] - low
plusDM = (upMove > downMove and upMove > 0) ? upMove : 0
minusDM = (downMove > upMove and downMove > 0) ? downMove : 0
trur = ta.rma(ta.tr, adxLength)
plusDI = 100 * ta.rma(plusDM, adxLength) / trur
minusDI = 100 * ta.rma(minusDM, adxLength) / trur
dx = 100 * math.abs(plusDI - minusDI) / (plusDI + minusDI)
adx = ta.rma(dx, adxLength)
plot(adx, title="ADX", color=color.blue)
// === ENTRY CONDITIONS ===
longCondition = ta.crossover(close, sma) and adx > adxThreshold
shortCondition = ta.crossunder(close, sma) and adx > adxThreshold
// === STRATEGY EXECUTION ===
if (longCondition)
strategy.entry("Long", strategy.long)
strategy.exit("Exit", from_entry="Long", limit=close + tpPoints, stop=close - slPoints, trail_points=trailPoints, trail_offset=trailPoints)
// FIRE ALERT
string alertMsg = '{"signal":"BUY","entry":' + str.tostring(close) +
',"SL":' + str.tostring(close - slPoints) +
',"TP":' + str.tostring(close + tpPoints) +
',"time":"' + str.tostring(time) + '"}'
alert(alertMsg, alert.freq_once_per_bar_close)
if (shortCondition)
strategy.entry("Short", strategy.short)
strategy.exit("Exit", from_entry="Short", limit=close - tpPoints, stop=close + slPoints, trail_points=trailPoints, trail_offset=trailPoints)
// FIRE ALERT
string alertMsg = '{"signal":"SELL","entry":' + str.tostring(close) +
',"SL":' + str.tostring(close + slPoints) +
',"TP":' + str.tostring(close - tpPoints) +
',"time":"' + str.tostring(time) + '"}'
alert(alertMsg, alert.freq_once_per_bar_close)
// === FORCE EXIT AT SESSION CLOSE ===
sessionCloseTime = (hour == sessionCloseHour and minute == sessionCloseMinute)
if (sessionCloseTime)
strategy.close_all(comment="Session Close")
// === NO-REPAINT FUNCTION ===
reso_no_repaint(exp, use, res) =>
use ? request.security(syminfo.tickerid, res, exp[1], lookahead=barmerge.lookahead_off, gaps=barmerge.gaps_on)[0] : exp