OPEN-SOURCE SCRIPT

Trend Strength Gauge sam

105
//version=6
indicator("Trend Strength Gauge", overlay=true)

// Input for indicators
lengthMA = input.int(50, title="Moving Average Length")
lengthATR = input.int(14, title="ATR Length")
lengthRSI = input.int(14, title="RSI Length")
rsiOverbought = input.int(70, title="RSI Overbought Level")
rsiOversold = input.int(30, title="RSI Oversold Level")

// Calculating Moving Averages
maShort = ta.sma(close, lengthMA)
maLong = ta.sma(close, lengthMA * 2) // Using a longer period for trend confirmation

// Calculating ATR for volatility
atrValue = ta.atr(lengthATR)

// Calculating RSI for momentum
rsiValue = ta.rsi(close, lengthRSI)

// Trend Strength Calculation
trendDirection = maShort > maLong ? 1 : -1
volatilityFactor = atrValue / close
momentumFactor = rsiValue > rsiOverbought ? -1 : (rsiValue < rsiOversold ? 1 : 0)

// Trend Strength Formula (0 to 100)
strength = (trendDirection * 50 + volatilityFactor * 50 + momentumFactor * 50)

// Normalize strength to be between 0 and 100
strength := math.min(math.max(strength, 0), 100)

// Plot the Trend Strength Gauge as a histogram
plot(strength, title="Trend Strength", color=color.new(color.blue, 0), linewidth=2, style=plot.style_histogram)

// Color the background based on trend strength
bgcolor(strength > 70 ? color.new(color.green, 90) : (strength < 30 ? color.new(color.red, 90) : na))

// Plot the moving averages on the chart for reference
plot(maShort, title="Short MA", color=color.green, linewidth=2)
plot(maLong, title="Long MA", color=color.red, linewidth=2)

Clause de non-responsabilité

Les informations et les publications ne sont pas destinées à être, et ne constituent pas, des conseils ou des recommandations en matière de finance, d'investissement, de trading ou d'autres types de conseils fournis ou approuvés par TradingView. Pour en savoir plus, consultez les Conditions d'utilisation.