Trend
Trend Quality Score
A score from zero to three counting how many trend conditions hold right now, drawn as a stepped line so the states are countable instead of eyeballed across three panes.
indicator
//@version=6
indicator("Trend Quality Score", "Quality", precision = 0)
maLen = input.int(50, "MA length", minval = 1, group = "Settings")
slopeLen = input.int(5, "Rising over bars", minval = 1, group = "Settings")
adxLen = input.int(14, "ADX length", minval = 1, group = "Settings")
adxMin = input.int(20, "ADX threshold", minval = 1, maxval = 100, group = "Settings")
bull = input.color(#26A69A, "Three of three", group = "Style")
flat = input.color(#787B86, "One or two", group = "Style")
bear = input.color(#EF5350, "None", group = "Style")
basis = ta.sma(close, maLen)
[diPlus, diMinus, adx] = ta.dmi(adxLen, adxLen)
aboveMa = close > basis
maRising = basis > basis[slopeLen]
strongAdx = adx > adxMin
score = (aboveMa ? 1 : 0) + (maRising ? 1 : 0) + (strongAdx ? 1 : 0)
tone = score == 3 ? bull : score == 0 ? bear : flat
plot(score, "Score", color = tone, style = plot.style_stepline, linewidth = 2)
hline(3, "All three", color = color.new(flat, 60))
hline(0, "None", color = color.new(flat, 60))
bgcolor(score == 3 ? color.new(bull, 90) : na, title = "All three")
reachedThree = score == 3 and score[1] < 3
leftThree = score < 3 and score[1] == 3
plotshape(reachedThree, "Reached three", location = location.bottom, style = shape.triangleup, color = bull, size = size.tiny)
plotshape(leftThree, "Left three", location = location.top, style = shape.triangledown, color = bear, size = size.tiny)
alertcondition(reachedThree, "Score reached three", "All three trend conditions are now true")
alertcondition(leftThree, "Score left three", "The trend quality score dropped below three of three")
This runs in TradingView, not here
Pine Script only executes inside TradingView. Paste the source into the Pine Editor and add it to a chart to see it plotted.
What it will not do
- Three measurements derived from the same price series are not three independent confirmations. They agree often and they are wrong together.
- Every component lags, so the score tends to reach three in the middle of a move and to fall only once the move has already ended.
- The number describes conditions, not an action. Two out of three is not half a trade and three out of three is not a signal.
Written from this description
Count how many of three conditions are true, price above a moving average, that average rising, and ADX above a threshold, then plot the count from zero to three as a stepped line with alerts as it reaches and leaves three.
Educational only, not financial advice. The maths is simple arithmetic on the numbers you enter; it knows nothing about your broker, fees, slippage or the market. Something wrong with it? Say so in Site Feedback.