OPEN-SOURCE SCRIPT

9 EMA Angle Color Indicator

49
//version=5
indicator("9 EMA Angle Color Indicator", overlay=true)

// === INPUTS ===
emaLength = input.int(9, title="EMA Length")
angleThreshold = input.float(20.0, title="Angle Threshold (Degrees)", minval=0.1)
lookbackBars = input.int(5, title="Bars to Calculate Angle", minval=1)

// === EMA CALCULATION ===
emaValue = ta.ema(close, emaLength)

// === ANGLE CALCULATION (in degrees) ===
// Use simple slope * 100 and arc tangent conversion to degrees
slope = (emaValue - emaValue[lookbackBars]) / lookbackBars
angle = math.atan(slope) * (180 / math.pi)

// === COLOR LOGIC ===
var color emaColor = color.black

// Initial color: black when angle is within range
emaColor := color.black

// Price and angle-based color change
if angle > angleThreshold and close > emaValue
emaColor := color.green
else if angle < -angleThreshold and close < emaValue
emaColor := color.red
else
emaColor := color.black

// === PLOT EMA ===
plot(emaValue, color=emaColor, linewidth=2, title="9 EMA Colored")

Declinazione di responsabilità

Le informazioni ed i contenuti pubblicati non costituiscono in alcun modo una sollecitazione ad investire o ad operare nei mercati finanziari. Non sono inoltre fornite o supportate da TradingView. Maggiori dettagli nelle Condizioni d'uso.