OPEN-SOURCE SCRIPT

9 EMA Angle + Price % Filter

68
//version=5
indicator("9 EMA Angle + Price % Filter", overlay=true)

length = 9
emaLine = ta.ema(close, length)

// === INPUTS ===
angleThreshold = input.float(20, "EMA Angle Threshold (°)")
pricePercentThreshold = input.float(80, "Price % Above/Below EMA")

// === PRICE DISTANCE FROM EMA IN % ===
percentAbove = close >= emaLine ? ((close - emaLine) / emaLine) * 100 : 0
percentBelow = close < emaLine ? ((emaLine - close) / emaLine) * 100 : 0

// === ANGLE CALCULATION ===
lookbackBars = input.int(5, "Bars for Angle Calculation")
p1 = emaLine
p2 = emaLine[lookbackBars]
deltaY = p1 - p2
deltaX = lookbackBars

angleRadians = math.atan(deltaY / deltaX)
angleDegrees = angleRadians * 180 / math.pi

// === CONDITIONS ===
isFlat = percentAbove < pricePercentThreshold and percentBelow < pricePercentThreshold and angleDegrees > -angleThreshold and angleDegrees < angleThreshold
isPriceAbove = percentAbove >= pricePercentThreshold
isPriceBelow = percentBelow >= pricePercentThreshold
isAngleUp = angleDegrees >= angleThreshold
isAngleDown = angleDegrees <= -angleThreshold

// === EMA COLOR LOGIC ===
emaColor = isFlat ? color.black :
isAngleUp or isPriceAbove ? color.green :
isAngleDown or isPriceBelow ? color.red : color.gray

// === PLOT EMA ===
plot(emaLine, "9 EMA", color=emaColor, linewidth=2)

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.