Overview
The Trend Confirmation Stochastic Oscillation Strategy is a quantitative trading system that combines the Average Directional Index (ADX) and the Stochastic Oscillator. The core concept of this strategy is to identify potential entry and exit points by using the overbought/oversold regions of the Stochastic indicator and the crossover signals between %K and %D lines, but only when a strong trend has been confirmed. The strategy first uses ADX to verify whether the market is in a significant trend, with an ADX value exceeding a set threshold (default 25) indicating sufficient trend strength. It then combines Stochastic indicator signals, using crossovers in the oversold region as buy conditions and crossovers in the overbought region as sell conditions. This combination method effectively filters out false signals in weak trend environments, improving the strategy's reliability.
Strategy Principles
The core principle of this strategy is based on the coordinated work of two main indicators:
Manual Calculation of ADX (Average Directional Index):
- Calculation of upward momentum (plusDM) and downward momentum (minusDM) by comparing high and low point changes between adjacent trading days
- True Range (TR) calculation, considering the current day's price range and the difference from the previous day's closing price
- Average True Range (ATR) calculation using Wilder's smoothing method
- Calculation and standardization of Positive Directional Indicator (+DI) and Negative Directional Indicator (-DI)
- Direction Index (DX) calculation through the ratio of the difference and sum of +DI and -DI
- Final ADX value derived by applying RMA (Wilder's Moving Average) to the DX value
Application of the Stochastic Oscillator:
- %K line calculation based on the relative position of the current closing price within a specific period range
- Smoothed %K line through SMA processing, improving signal stability
- %D line as a moving average of the %K line, further smoothing fluctuations
Signal Generation Logic:
- Buy signal: When the ADX value is greater than the set threshold (25), confirming a strong trend, while the Stochastic indicator is in the oversold region (K<20), and the %K line crosses above the %D line
- Sell signal: When the ADX value is greater than the set threshold, confirming a strong trend, while the Stochastic indicator is in the overbought region (K>80), and the %K line crosses below the %D line
This design enables the strategy to capture overbought/oversold reversal opportunities in price during strong trend environments, effectively avoiding the risk of frequent trading in trendless or weak trend markets.
Strategy Advantages
In-depth analysis of the strategy's code implementation reveals the following significant advantages:
Trend Confirmation Filtering: By using an ADX threshold (default 25) to filter out signals in weak trend or oscillating markets, the strategy only executes trades when a clear trend is established, significantly reducing false signals in oscillating markets.
Precise Entry and Exit Timing: By combining the overbought/oversold regions of the Stochastic indicator with crossover signals, the strategy can capture potential reversal points when prices reach extreme positions, improving the precision of entries and exits.
High Customizability: The strategy provides multiple adjustable parameters, including ADX period, trend strength threshold, various Stochastic indicator parameters, and overbought/oversold levels, allowing users to optimize and adjust according to different market environments and personal preferences.
Intuitive Graphical Display: The strategy displays ADX values and the Stochastic indicator's %K and %D lines on the chart, as well as relevant threshold levels, making it easy for traders to intuitively understand the current market status and potential signals.
Comprehensive Alert System: The strategy integrates alert condition settings, enabling seamless connection with third-party platforms (such as 3Commas) through Webhooks for automated trade execution.
Capital Management Mechanism: The strategy adopts a percentage of account equity approach for position management (default 10%), providing a basic risk control mechanism.
Manual Implementation of Technical Indicators: The ADX indicator uses manual calculation methods rather than directly calling library functions, not only demonstrating the transparency of the calculation process but also providing convenience for possible custom modifications.
Strategy Risks
Despite its many advantages, the strategy still has the following potential risks in practical application:
Delayed Reaction to Trend Turning Points: The ADX indicator itself is a lagging indicator and may not capture the initial phase or turning points of a trend in a timely manner, leading to delayed entry timing or missing part of the market movement. Solution: Consider incorporating more sensitive short-term price breakthrough indicators as auxiliary confirmation.
False Signals from Stochastic Indicator: In strong unidirectional trends, the Stochastic indicator may remain in overbought or oversold regions for extended periods, generating premature reversal signals. Solution: Add holding time restrictions or introduce trend direction filtering conditions.
Parameter Sensitivity: Strategy performance is highly dependent on parameter settings, and different market environments may require different parameter combinations. Solution: Recommend historical backtesting to find optimal parameters for specific markets, or consider implementing adaptive parameter methods.
Lack of Stop-Loss Mechanism: The current strategy only has entry and exit conditions without a clear stop-loss mechanism, potentially facing significant losses in extreme market environments. Solution: Add dynamic stop-loss based on volatility or fixed percentage stop-loss conditions.
Single Signal Dependence: The strategy relies solely on the combination of ADX and Stochastic indicator signals, lacking multi-angle market analysis. Solution: Introduce volume indicators or other technical indicators as additional confirmation conditions.
Risk of Counter-Trend Trading: When the market is in an extremely strong unidirectional trend, reversal trading may face the risk of "going against the trend." Solution: Add trend direction judgment, only taking trades in the direction of the trend.
Optimization Directions
Based on the principles of the strategy and existing risks, here are several optimization directions worth considering:
Adaptive Parameter System: Design the ADX threshold and the Stochastic indicator's overbought/oversold levels as adaptive parameters based on historical volatility, allowing the strategy to dynamically adjust sensitivity according to market conditions. This improvement can enable the strategy to maintain consistent performance in different market environments without frequent manual parameter adjustments.
Trend Direction Filtering: Add trend direction judgment (such as using the relationship between +DI and -DI), making the strategy only look for long opportunities in uptrends and short opportunities in downtrends, avoiding the high risk of counter-trend operations.
Multi-Timeframe Analysis: Introduce higher timeframe trend confirmation mechanisms to ensure that the trading direction aligns with larger cycle trends, improving win rates.
Dynamic Stop-Loss System: Design dynamic stop-losses based on ATR or volatility to protect existing profits and limit the maximum loss risk of single trades.
Volume Confirmation: Add volume analysis as a signal confirmation condition, only executing trades when supported by volume, avoiding false signals in low liquidity environments.
Entry Optimization: Consider a phased position building strategy, allocating funds proportionally after the initial signal triggers, and increasing positions as prices develop in a favorable direction, reducing single-point entry risk.
Machine Learning Enhancement: Introduce simple machine learning models to classify and score historical signals, identifying pattern features with high probability of success, improving strategy selectivity.
Trading Session Filter: Add trading session restrictions to avoid low liquidity or high volatility market sessions, reducing risks brought by abnormal price movements.
These optimization directions aim to improve the strategy's adaptability, robustness, and long-term profitability, enabling it to maintain relatively stable performance in various market environments.
Conclusion
The Trend Confirmation Stochastic Oscillation Strategy constructs a complete trading system with both trend confirmation mechanisms and price extreme reversal signals by combining the ADX trend strength indicator and the overbought/oversold characteristics of the Stochastic indicator. The core advantage of this strategy lies in its ability to effectively filter noise signals in weak trend environments, only executing trades when a clear trend is confirmed, and using the Stochastic indicator to capture potential price reversal points.
The strategy implements the manual calculation process of the ADX indicator, showcasing the mathematical principles behind technical indicators, and provides high flexibility and adaptability through parameterized design. At the same time, the integrated alert system facilitates automated connection with external trading platforms.
Although there are risks such as lagging trend judgment, false signals from the Stochastic indicator, and lack of a comprehensive stop-loss mechanism, these risks can be effectively managed through the suggested optimization directions, such as adaptive parameters, trend direction filtering, multi-timeframe analysis, and dynamic stop-losses.
Overall, this strategy provides a framework that balances trend following and reversal trading, suitable for application in markets with clear trend characteristics. Through reasonable parameter adjustments and optimization improvements, it has the potential to become a robust trend trading system.
Strategy source code
/*backtest
start: 2024-03-05 00:00:00
end: 2025-03-03 08:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"SOL_USDT"}]
*/
//@version=5
strategy("MY3 ADX+Stokastik", overlay=true, initial_capital=10000, default_qty_type=strategy.percent_of_equity, default_qty_value=10)
// ADX Parameters
adxPeriod = input.int(14, title="ADX Period", minval=1)
adxThreshold = input.float(25.0, title="Trend Strength Threshold", step=0.1)
// Stochastic Parameters
stochKPeriod = input.int(14, title="Stochastic %K Period", minval=1)
stochSmoothK = input.int(3, title="Stochastic Smooth", minval=1)
stochDPeriod = input.int(3, title="Stochastic %D Period", minval=1)
stochOverbought = input.int(80, title="Overbought Level", minval=50)
stochOversold = input.int(20, title="Oversold Level", maxval=50)
// ADX Calculation (Manual)
// Basic elements used in calculation
upMove = high - high[1]
downMove = low[1] - low
plusDM = (upMove > downMove and upMove > 0) ? upMove : 0.0
minusDM = (downMove > upMove and downMove > 0) ? downMove : 0.0
// True Range calculation
tr0 = high - low
tr1 = math.abs(high - close[1])
tr2 = math.abs(low - close[1])
trueRange = math.max(math.max(tr0, tr1), tr2)
// ATR calculation: Wilder's Soft Average
atrValue = ta.rma(trueRange, adxPeriod)
plusDI = 100 * ta.rma(plusDM, adxPeriod) / atrValue
minusDI = 100 * ta.rma(minusDM, adxPeriod) / atrValue
dx = 100 * math.abs(plusDI - minusDI) / (plusDI + minusDI)
adxValue = ta.rma(dx, adxPeriod)
// Stochastic Calculation
k = ta.sma(ta.stoch(close, high, low, stochKPeriod), stochSmoothK)
d = ta.sma(k, stochDPeriod)
// Purchase and Sale Conditions:
// Buy: ADX is above the specified threshold and Stochastic is in the oversold area (k < stochOversold) while %K, %D intersection is upward.
buySignal = (adxValue > adxThreshold) and ta.crossover(k, d) and (k < stochOversold)
// Sell: ADX is above the specified threshold and Stochastic is in the overbought area (k > stochOverbought) while %K, %D intersection is down.
sellSignal = (adxValue > adxThreshold) and ta.crossunder(k, d) and (k > stochOverbought)
// Trading orders
if (buySignal)
strategy.entry("Long", strategy.long)
if (sellSignal)
strategy.close("Long")
// Displaying Indicators on Graphics
plot(adxValue, color=color.blue, title="ADX")
hline(adxThreshold, color=color.gray, linestyle=hline.style_dotted, title="ADX Threshold")
plot(k, color=color.green, title="Stokastik %K")
plot(d, color=color.orange, title="Stokastik %D")
hline(stochOverbought, color=color.red, linestyle=hline.style_dotted, title="Overbought")
hline(stochOversold, color=color.green, linestyle=hline.style_dotted, title="Oversold")
// Alert Conditions for 3Commas (To be used for Webhook integration)
alertcondition(buySignal, title="Buying alert", message="BUY_SIGNAL")
alertcondition(sellSignal, title="Sell alert", message="SELL_SIGNAL")
Strategy Parameters
The original address: Trend Confirmation Stochastic Oscillation Strategy: Dynamic Market Identification System Combining ADX and Stochastic Indicators
Now this is what I call a strategy with commitment issues—it won’t enter a trade until every indicator agrees like a group chat on vacation plans 😂 But seriously, combining trend confirmation with stochastic signals is a smart move—finally a system that waits for actual alignment instead of jumping in like it’s guessing the weather. Can’t wait to test this before my FOMO takes over again 😅