
This strategy is a trend-following system that combines technical indicators with machine learning methods. The strategy integrates the Relative Strength Index (RSI), Average Directional Index (ADX), and linear regression prediction model to analyze market trends and trading opportunities from multiple dimensions. Operating on a 5-minute timeframe, it creates a complete trading decision system by combining RSI overbought/oversold signals, ADX trend confirmation, and linear regression predictions.
The strategy employs a three-layer filtering mechanism to determine trading signals: 1. RSI indicator identifies overbought/oversold conditions, generating long signals at RSI 30 (oversold) and short signals at RSI 70 (overbought) 2. ADX indicator confirms trend strength, allowing trades only when ADX is above 25 to ensure operations in strong trend environments 3. Linear regression prediction module analyzes data from the past 20 price periods to calculate price trend slope and intercept, predicting the next price level Trading signals are only generated when all three conditions align in direction.
This strategy builds a relatively complete trading system by combining traditional technical analysis with modern prediction methods. Its core advantage lies in the multi-dimensional signal confirmation mechanism, effectively reducing the impact of false signals. There is significant optimization potential through improving the prediction model, optimizing parameter adjustment mechanisms, and enhancing risk management. In practical application, investors should adjust strategy parameters according to specific market characteristics and their risk tolerance.
/*backtest
start: 2025-01-20 00:00:00
end: 2025-02-19 08:00:00
period: 1h
basePeriod: 1h
exchanges: [{"eid":"Binance","currency":"SOL_USDT"}]
*/
//@version=5
strategy("RSI + ADX + ML-like Strategy (5min)", overlay=true)
// ———— 1. Inputs ————
rsiLength = input(14, "RSI Length")
adxLength = input(14, "ADX Length")
mlLookback = input(20, "ML Lookback (Bars)")
// ———— 2. Calculate Indicators ————
// RSI
rsi = ta.rsi(close, rsiLength)
// ADX
[diPlus, diMinus, adx] = ta.dmi(adxLength, adxLength)
// ———— 3. Simplified ML-like Component (Linear Regression) ————
var float predictedClose = na
sumX = math.sum(bar_index, mlLookback) // FIXED: Using math.sum()
sumY = math.sum(close, mlLookback) // FIXED: Using math.sum()
sumXY = math.sum(bar_index * close, mlLookback) // FIXED: Using math.sum()
sumX2 = math.sum(bar_index * bar_index, mlLookback)
slope = (mlLookback * sumXY - sumX * sumY) / (mlLookback * sumX2 - sumX * sumX)
intercept = (sumY - slope * sumX) / mlLookback
predictedClose := slope * bar_index + intercept
// ———— 4. Strategy Logic ————
mlBullish = predictedClose > close
mlBearish = predictedClose < close
enterLong = ta.crossover(rsi, 30) and adx > 25 and mlBullish
enterShort = ta.crossunder(rsi, 70) and adx > 25 and mlBearish
// ———— 5. Execute Orders ————
strategy.entry("Long", strategy.long, when=enterLong)
strategy.entry("Short", strategy.short, when=enterShort)
// ———— 6. Plotting ————
plot(predictedClose, "Predicted Close", color=color.purple)
plotshape(enterLong, "Buy", shape.triangleup, location.belowbar, color=color.green)
plotshape(enterShort, "Sell", shape.triangledown, location.abovebar, color=color.red)