OPEN-SOURCE SCRIPT
Linearity V1.0

Linearity Research — Trend Quality & Move Detection
This indicator finds clean, low-chop upward price moves ("linear" moves) and scores how good each one is, then rolls those scores up into a single Linearity Score so you can quickly judge whether a stock tends to trend smoothly or in choppy, unreliable swings.
How a move is detected
- A move begins when price closes above its EMA (default length 21).
- It ends only after price closes back below the EMA and then makes a new low below the low of that breakdown bar — a two-step exit that avoids ending a move on a single EMA wick.
Qualifying a move
- Persistence = the % of bars in the move that closed above the EMA. This measures how smooth vs. choppy the move was.
Qualifying a move
- Persistence = the % of bars in the move that closed above the EMA. This measures how smooth vs. choppy the move was.
- Smooth moves (persistence ≥ the High Persistence Threshold) only need to clear a lower minimum peak-gain bar to qualify. Choppier moves must clear a higher bar. This keeps ragged-but-large rallies from scoring as well as genuinely straight-line moves.
Per-move score (0–100)
- Peak % gain — 40%
- Efficiency Ratio (net move ÷ total price path traveled; 1.0 = a straight line, lower = more back-and-forth) — 30%
- Persistence — 20%
- Max intra-move drawdown (light penalty) — 5%
- Pullback count (light penalty) — 5%
Linearity Score
Over a configurable lookback window (in years), the script averages the score, peak %, and Efficiency Ratio of every qualifying move, then adds a small bonus for having more qualifying moves (capped), producing one 0–100 Linearity Score. This, along with move count, average peak %, and average ER, is shown in an on-chart panel.
Visuals
- Green boxes mark each qualifying move, labeled with its peak % gain and score.
- Optional EMA plot.
- A configurable bottom panel shows either the Linearity summary or a detailed table of every qualifying move (dates, peak %, ER, persistence, drawdown, pullbacks, duration, score) — position, text size, and colors are all adjustable.
How to use it
Use the Linearity Score to screen for stocks whose historical rallies tend to be smooth and orderly rather than violent and choppy — useful for trend-following or momentum approaches that don't want to fight excessive volatility. Switch the bottom panel to the Detailed Table to audit exactly which historical moves are driving the score.
Note: this script only evaluates upward (bullish) moves triggered by EMA crossovers — it does not detect or score downtrends.
This indicator finds clean, low-chop upward price moves ("linear" moves) and scores how good each one is, then rolls those scores up into a single Linearity Score so you can quickly judge whether a stock tends to trend smoothly or in choppy, unreliable swings.
How a move is detected
- A move begins when price closes above its EMA (default length 21).
- It ends only after price closes back below the EMA and then makes a new low below the low of that breakdown bar — a two-step exit that avoids ending a move on a single EMA wick.
Qualifying a move
- Persistence = the % of bars in the move that closed above the EMA. This measures how smooth vs. choppy the move was.
Qualifying a move
- Persistence = the % of bars in the move that closed above the EMA. This measures how smooth vs. choppy the move was.
- Smooth moves (persistence ≥ the High Persistence Threshold) only need to clear a lower minimum peak-gain bar to qualify. Choppier moves must clear a higher bar. This keeps ragged-but-large rallies from scoring as well as genuinely straight-line moves.
Per-move score (0–100)
- Peak % gain — 40%
- Efficiency Ratio (net move ÷ total price path traveled; 1.0 = a straight line, lower = more back-and-forth) — 30%
- Persistence — 20%
- Max intra-move drawdown (light penalty) — 5%
- Pullback count (light penalty) — 5%
Linearity Score
Over a configurable lookback window (in years), the script averages the score, peak %, and Efficiency Ratio of every qualifying move, then adds a small bonus for having more qualifying moves (capped), producing one 0–100 Linearity Score. This, along with move count, average peak %, and average ER, is shown in an on-chart panel.
Visuals
- Green boxes mark each qualifying move, labeled with its peak % gain and score.
- Optional EMA plot.
- A configurable bottom panel shows either the Linearity summary or a detailed table of every qualifying move (dates, peak %, ER, persistence, drawdown, pullbacks, duration, score) — position, text size, and colors are all adjustable.
How to use it
Use the Linearity Score to screen for stocks whose historical rallies tend to be smooth and orderly rather than violent and choppy — useful for trend-following or momentum approaches that don't want to fight excessive volatility. Switch the bottom panel to the Detailed Table to audit exactly which historical moves are driving the score.
Note: this script only evaluates upward (bullish) moves triggered by EMA crossovers — it does not detect or score downtrends.
开源脚本
秉承TradingView的精神,该脚本的作者将其开源,以便交易者可以查看和验证其功能。向作者致敬!您可以免费使用该脚本,但请记住,重新发布代码须遵守我们的网站规则。
免责声明
这些信息和出版物并非旨在提供,也不构成TradingView提供或认可的任何形式的财务、投资、交易或其他类型的建议或推荐。请阅读使用条款了解更多信息。
开源脚本
秉承TradingView的精神,该脚本的作者将其开源,以便交易者可以查看和验证其功能。向作者致敬!您可以免费使用该脚本,但请记住,重新发布代码须遵守我们的网站规则。
免责声明
这些信息和出版物并非旨在提供,也不构成TradingView提供或认可的任何形式的财务、投资、交易或其他类型的建议或推荐。请阅读使用条款了解更多信息。