Trendline Detector

Portfolio Analytics Intermediate United Kingdom Equity ETFs Futures Options Forex Commodities Indices
Learn this and United Kingdom-market strategies in depth — one-time purchase, lifetime access.
Unlock full hub →

Quick Reference

Purpose Automatically detect, validate, and monitor trendlines from historical price data to identify trend direction, potential breakout/breakdown points, and dynamic support/resistance levels
Core Function Analyzes swing points to construct ascending and descending trendlines, validates them based on touch count and accuracy, and monitors for breaks and retests
Primary Users Technical traders, swing traders, trend followers, and algorithmic systems requiring automated trendline detection
Key Benefit Removes subjectivity from trendline drawing, ensures consistent detection across instruments, and identifies trendlines that may be missed by visual inspection
Data Sources Historical OHLCV data, swing point analysis
Update Frequency Real-time updates as new price data arrives, with periodic validation
Uk Context Accounts for UK market trading hours (8:00 AM - 4:30 PM London, continuous, no lunch break), overnight and 7:00 AM RNS gap behavior, and monthly option-expiry effects on trendline validity
Typical Outputs Ranked list of valid trendlines with slope, touch count, break alerts, and projected levels
Risk Consideration Trendlines are subjective tools - automated detection provides consistency but not guaranteed accuracy

Payoff Profile

Trendline Detector displays detected trendlines overlaid on price charts with metadata

United Kingdom Market Details

Data Sources London Stock Exchange for historical OHLCV • Hargreaves Lansdown, AJ Bell, Interactive Investor, IG, Trading 212 for retail data and execution • TradingView, ChartIQ for visualization and validation

Frequently Asked Questions

Should I use wicks or candle bodies when drawing trendlines?

Both approaches have merit. Wick-based trendlines capture the true price extremes and may be more accurate for intraday analysis. Body-based (using opens and closes) trendlines are often cleaner and filter out noise from extreme wicks. The key is consistency - pick one approach and apply it uniformly. Many traders use body-based for daily charts (cleaner) and wick-based for intraday (more precise). If your wick-based trendline has too many minor violations, try body-based as an alternative.

How steep should a valid trendline be?

There's no single correct slope, but extreme slopes are problematic. Very steep trendlines (>45° visually or >2% per day) are unsustainable and break quickly. Very flat trendlines (<0.1% per day) may not represent significant trends. The 'sweet spot' is typically 20-45° visually (0.2-1% per day for daily charts). Also consider the context - fast-moving stocks naturally have steeper trendlines than slow-moving utilities. If your trendline seems excessively steep or flat, it may not be a useful trading tool.

What if price slightly penetrates the trendline but then reverses back?

This is called a 'false break' or 'whipsaw.' If the penetration is just a wick (price closes back above ascending trendline or below descending trendline), the trendline is still intact. Many traders use 'close-based' validation - the trendline is only broken if the candle closes beyond it. You can also use a tolerance zone (0.5-1% beyond the line) to filter out minor violations. If false breaks are common at your trendlines, consider using internal trendlines or wider tolerance bands.

How long do trendlines remain valid?

Trendline validity depends on continued price respect and recency. A trendline remains valid as long as: (1) It hasn't been broken (no close beyond it), (2) It has been tested relatively recently (within the last 20-50 bars), and (3) Price is still in a position to interact with it. Very old trendlines that haven't been tested in months may lose relevance as market conditions change. However, major trendlines from higher timeframes (weekly, monthly) can remain relevant for extended periods. When in doubt, prioritize recent trendlines.

Can I draw trendlines on any stock or instrument?

Trendlines work best on liquid instruments with clear trends. They're most effective for: Indices (FTSE 100, FTSE 350 Banks), large-cap stocks with consistent trading, forex pairs, and commodities. They're less reliable for: Illiquid stocks (choppy price action, gaps), stocks with frequent news-driven moves, and very low-priced stocks with erratic behavior. If a chart looks 'messy' with no discernible trend, trendlines may not be the right tool. Focus on stocks showing clear trending behavior.

How do I handle trendlines during earnings or major news events?

Major events can cause gaps and volatility that temporarily invalidate trendlines. Strategies: (1) Before events: Reduce positions or set wider stops - trendlines may gap through. (2) During events: Don't trade trendlines during high-impact news. Wait for dust to settle. (3) After events: Re-evaluate all trendlines. If gapped through, the trendline is broken. Draw new trendlines using post-event swing points. (4) Gap handling: If price gaps through but quickly recovers, the original trendline may still be valid. Wait for confirmation before deciding. Generally, trendlines drawn from pre-event data should be treated cautiously post-event.

What's the difference between external and internal trendlines?

External trendlines connect the absolute price extremes (highest wicks for descending, lowest wicks for ascending). Internal trendlines are 'best fit' lines that may cut through some price points but touch the majority. Internal lines capture the 'center of gravity' of price action rather than extremes. Use external when: Trendline has clean touches at extremes. Wicks are not outliers. Use internal when: External line has been pierced multiple times but price returned. There are obvious outlier wicks distorting external line. You want to identify equilibrium rather than absolute boundaries.

How do I combine trendlines with options strategies?

Trendlines inform options strategies in several ways: At ascending trendline support: Sell puts below trendline (benefiting from support holding), buy calls above trendline (participating in bounce). At descending trendline resistance: Sell calls above trendline (benefiting from resistance holding), buy puts below (participating in rejection). Within channels: Use iron condors with wings at channel boundaries. Breakout plays: Buy straddles/strangles when price consolidates near a trendline (expecting volatility on break). Use trendline levels for strike selection - place sold strikes at or beyond significant trendlines where you expect support/resistance to hold.

How do I adjust my trendline when a new swing point forms?

When a new swing point forms that would 'improve' your trendline, you have options: (1) Keep original: If original trendline is still valid (no breaks, recent touches), don't change it. The new point may form a secondary trendline. (2) Adjust: If the new point creates a better line (more touches, cleaner fit), adjust anchors. Keep the old line as reference. (3) Draw both: Use original as primary and new as secondary. They may converge at key levels. Rules of thumb: Only adjust if significantly improved. Document why you adjusted. Don't constantly redraw - if you need frequent adjustments, the trend may not be clean enough to trade.

How reliable are trendlines compared to horizontal support/resistance?

Both are useful but have different strengths: Horizontal S/R: More objective (exact price level), clearer in ranging markets, often stronger because price 'remembers' exact levels. Trendlines: Better for trending markets, show rate of change, provide context for trend direction. Reliability comparison: Well-established horizontal levels (many touches, long duration) are often more reliable than trendlines. But in strong trends, trendlines outperform horizontal levels (which get broken as price trends). Best approach: Use both. Horizontal for ranging/consolidation, trendlines for trends. Confluence of both (trendline meeting horizontal S/R) is most reliable.

What's the best algorithm for trendline detection - swing-based or regression-based?

Each has trade-offs: Swing-based (connecting defined swing points) produces traditional trendlines that traders recognize. It requires swing detection first, then line fitting. Results depend heavily on swing detection parameters. Regression-based (best-fit line through price data) produces 'average trend' lines but doesn't ensure actual price touches. Better for trend direction than for S/R trading. Recommendation: Use swing-based for trendlines intended for S/R trading (need actual touches). Use regression-based (linear regression channel) for trend direction and mean reversion analysis. For production systems, swing-based with careful parameter tuning typically produces more actionable results.

How do I validate that my algorithmic trendline detection is working correctly?

Validation approaches: (1) Visual comparison: Overlay detected trendlines on charts and compare to manual analysis. Major trendlines should match. (2) Hold rate testing: Track percentage of trendline touches that resulted in bounces vs breaks. Well-detected trendlines should have >50% hold rate. (3) Out-of-sample testing: Detect trendlines on training period, test on future period. Does detection performance hold? (4) Cross-instrument testing: Same parameters should work across similar instruments. If not, parameters may be overfit. (5) Compare to baseline: Does your sophisticated detection outperform simple methods (just connecting obvious swings)? If not, simpler is better.

How often should trendline scoring weights be recalibrated?

Recalibrate on a schedule, not constantly: Frequency: Recompute hold-rate base rates and review the fixed scoring weights monthly or quarterly - daily changes cause churn. Monitor performance continuously and recalibrate early if accuracy degrades. Data window: Use an expanding window (all history) for stable base rates, or a rolling window (recent 2-3 years) to adapt to changing market structure. Process: (1) Recompute base rates on recent data. (2) If high-scored trendlines are no longer holding more often than low-scored ones, adjust the documented weights by hand. (3) Verify the new weights rank reliability correctly on a held-out recent window. (4) Apply changes incrementally and keep a changelog. Stability: If the evidence swings wildly between recalibrations, your buckets may be too small - require a minimum sample size before trusting a base rate. Keep the whole process deterministic and reproducible - no opaque models.

How do I handle the computational load of real-time trendline detection across many instruments?

Scaling strategies: (1) Incremental processing: On startup, run full detection. On each new bar, only check for new swings, update touches, detect breaks. This is O(number of trendlines) not O(history length). (2) Parallelization: Each instrument is independent. Use worker pools, one worker per instrument or batch of instruments. (3) Tiered processing: Tier 1 (most traded) - real-time updates. Tier 2 - update every minute. Tier 3 - update every 5 minutes. (4) Caching: Cache swing points and intermediate calculations. Invalidate only when new relevant data arrives. (5) Hardware: If necessary, use multiple servers partitioned by instrument.

What are the key UK market characteristics that affect trendline behavior?

Key UK considerations: (1) Gap behavior: UK shares gap frequently on overnight US and Asian moves and on 7:00 AM RNS company announcements before the open. Trendlines may gap through without trading through - use close-based validation carefully. (2) Trading hours: A continuous ~8.5-hour session (8:00 AM-4:30 PM London, no lunch break) gives more intraday data points than shorter sessions; the US market open at 2:30 PM London injects fresh volatility into the UK afternoon. (3) Derivative expiry: UK single stocks have no weekly expiry; third-Friday monthly index and single-stock option expiry can cause unusual price action - reduce trendline confidence near expiry on the index and the most-liquid names. (4) Volatility patterns: The first 30 minutes (8:00-8:30) is highly volatile, the midday is quieter until the US open, and the close into the 4:30 auction is active - intraday trendlines should account for this. (5) Price monitoring: The LSE uses automated auction extensions and brief execution suspensions when price moves beyond dynamic or static thresholds, rather than fixed daily circuit limits, so price rarely locks but can pause, which can distort very short-term trendlines.

Related Strategies

Master United Kingdom trading strategies on AlgoKing

Full guided lessons, quizzes, and a complete strategy library for the United Kingdom market. One-time purchase. No subscription, ever.

Get United Kingdom access →