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. اقرأ المزيد في شروط الاستخدام.