Discussing the article: "Developing Smart Chart Objects in MQL5 (Part 2): Automating Trendline Discovery and Lifecycle Management"

 

Check out the new article: Developing Smart Chart Objects in MQL5 (Part 2): Automating Trendline Discovery and Lifecycle Management.

Learn how Smart Trendline Manager separates creation from lifecycle control while handling both manual and auto-generated trendlines. It demonstrates discovery, registration, proximity and touch handling, bounce/break confirmation, post-break resurrection, expiration, and state-driven visualization. This gives you a consistent, configurable way to manage multiple lines through one orchestrated update process.

You already treat trendlines as “live” objects with states (touch, bounce, break), but adding automatic generation risks fragmenting that architecture: generators begin depending on state, managers on swings, and the chart fills with duplicates and orphaned objects. This part addresses that problem by introducing automatic trendline construction while preserving a single, consistent lifecycle. The Builder (CTrendlineBuilder) turns market structure into candidates; the Manager discovers and registers chart objects; and CManagedTrendline remains the single authority for lifecycle, confirmation, resurrection, expiration, and visual state. Success is measured by observable behavior: auto-generated lines appear, are discovered and registered, and then follow the same state machine, update ordering, and visual rules as manual lines—without generator-specific logic leaking into the lifecycle engine.

A trendline can now enter the framework in two ways. It can be drawn manually by the user, or it can be generated automatically from market structure. Although the entry paths are different, both eventually converge into the same management system. This distinction introduces two separate responsibilities. Registration and ownership handle the transition from a chart object to a managed object. Lifecycle management then takes over. It handles proximity, touches, bounces, breaks, resurrection, expiration, and the related state transitions.

The architecture can be viewed through a simple flow.

Fig. 1. Flow diagram

Author: Francis Nyoike Thumbi

 
How do YOU define touch, bounce and break?  Thank you.
 
Avery Horton #:
How do YOU define touch, bounce and break?  Thank you.
 A touch occurs when price enters the configured ATR/proximity threshold around the trendline. A bounce is confirmed after the required consecutive closes move away from the line by the bounce threshold, while a break requires consecutive closes beyond the line by the break threshold. Part 1 covers the lifecycle logic and implementation.
Developing Smart Chart Objects in MQL5 (Part 1): Building a Stateful Trendline Management Framework
Developing Smart Chart Objects in MQL5 (Part 1): Building a Stateful Trendline Management Framework
  • 2026.08.21
  • www.mql5.com
This article details a practical framework for converting MetaTrader 5 trendlines from static drawings into managed runtime entities. It covers object discovery, event-driven synchronization of user edits, and confirmation logic based on ATR multipliers and closed candles. A central manager coordinates multiple lines and updates their visual state. Readers can implement consistent, extensible rules for detecting proximity, validating bounces, and confirming breakouts.