Trend Lines System Development
Trend lines are a fundamental technical analysis tool: an ascending line connects successive rising lows, a descending line — falling highs. Automatic construction of quality trend lines is more complex than it seems: you need to distinguish "correct" lines from artifacts.
Building Algorithm
Stage 1: Finding Anchor Points
We use pivot points — local extremes with minimum distance between them (min_strength parameter). The higher the strength, the "larger" the extremes.
Stage 2: Linear Regression on Point Pairs
For each pair of pivot lows we build a line and check if price breaks this line between points. Line is valid if price stays above/below it over the entire segment.
Stage 3: Quality Assessment
A good trend line has:
- Minimum of 3 touches (two points build the line, third confirms)
- Small number of false breaks (price closes through)
- Relevance — last touch is recent
Stage 4: Ranking
Line score = number of touches × timeframe_weight × (1 / days_since_last_touch)
Break Detection
When a trend line breaks (candle closes beyond it) the system:
- Marks the line as "broken"
- Generates alert with details (instrument, timeframe, break direction)
- Calculates potential target (equal move projection)
False breaks are filtered: if price returns within the line over the next 1–3 candles — this is a false break (bear/bull trap), not a real breakout.
Channels
Parallel line to main trend line, built through opposite extremes, forms a channel. System automatically builds channels and tracks price within them: touch of lower boundary of ascending channel = buy zone, upper = sell zone.
Stack: Python + pandas for calculations, PostgreSQL for storing lines with parameters, React + TradingView Lightweight Charts for rendering. Lines update in real-time on each candle close, break alerts — via Telegram Bot or webhook.







