OPEN-SOURCE SCRIPT
MarketMaulers Auto Trendlines

MarketMaulers Auto Trendlines draws the diagonal structure you would have drawn yourself, and then stays with the line through the part that matters. Two confirmed pivots anchor it, the market's own touches validate it, and its parallel rail is projected through the furthest price travelled while the line was forming. Then it waits for the break, and reports which of the only two things that can follow a break took place.
Forming · Validated · Broken · Retested / Failed break
THE RETEST IS THE PRODUCT
Anyone can draw a line through two pivots and print a marker when price closes through it. The break is the least informative moment in a trendline's life. Most lines break, and the break on its own says nothing about whether the level still matters.
Two things can follow, and they mean opposite things.
• RETEST. Price comes back and respects the line from the OTHER side. Old support is now resistance. The line survived its own break as a reference and is arguably more useful after it than before.
• FAILED BREAK. Price closes straight back on the original side. The break was noise, the line was never beaten, and anyone who traded the break is offside.
This tool waits for one of those and names it. That is the read you cannot get by eyeballing the chart in the moment, because in the moment the two look identical.
FROM ZERO: WHY A DIAGONAL LINE IS A DIFFERENT ANIMAL FROM A HORIZONTAL ONE
A horizontal level is a price. It sits at one number and it is still that number tomorrow. A trendline is a price AND a rate. It asks the market to keep making higher lows at a certain speed, or lower highs at a certain speed. That is a much stronger claim, which is why trendlines break more often than horizontal levels and why the break carries less information when they do.
It is also why a line has to be earned rather than drawn. Two points define any line at all. Three or more touches is the market repeatedly agreeing to the rate.
HOW A LINE EARNS ITS PLACE
Five gates, each closing a specific way auto-trendline scripts produce clutter.
• Confirmed pivots only, paired for direction. A rising support line needs a second swing low strictly HIGHER than the first, a falling resistance line a second high strictly lower. A zero slope is unreachable by construction, so this file never draws a horizontal line.
• A cleanliness scan. Every bar between the two anchors is checked for a close through the line. A line price has already spent time on the wrong side of was never a valid line, and drawing it anyway is how a chart fills with lines nobody would have drawn by hand.
• Touch counting with a spacing rule. A touch is a bar reaching within a quarter of an ATR of the line, and touches within three bars of each other count once. Without the spacing rule one slow drift along a line counts as five touches and validates anything.
• Near-duplicate rejection. Two lines are compared at two sample points, now and fifty bars back, and the newer one is dropped if they sit within 0.75 ATR at BOTH. Comparing at a single point lets two lines with different slopes look identical at the moment they cross.
• A slope cap and abandoned-line retirement. Near-vertical lines off a single spike are refused, and a line price has stayed far away from for twenty consecutive bars is retired. That is what keeps ancient support lines from hanging under current price forever.
TWO WAYS A LINE BREAKS, AND THE SECOND ONE IS THE INTERESTING ONE
The obvious break is distance: a close sitting at least 0.35 ATR beyond the line. That catches the decisive break and it misses the slow one.
Price can park a fraction through a line, too shallow to trigger the distance test and too close to trigger retirement, and grind there bar after bar. Under a distance-only rule the line stays marked VALIDATED with price on the wrong side of it for as long as the grind lasts, which is a tool stating something false. So three consecutive wrong-side closes break a line at any distance. Decisive breaks are caught by distance, grinds by persistence, and there is no state left where the display and the price disagree.
A RETESTED LINE GOES BACK TO WORK
Most implementations treat the retest as the end of a line's life, which is backwards from what the retest proves. A line that broke, was left alone, and then held from the other side has demonstrated it still matters, and the tools that go quiet there stop watching at the exact moment the line earned its keep.
The mechanism is a POLARITY FLIP rather than a new line. Old support becomes resistance, so the side the break test looks at flips while the line's geometric identity does not. It is still a rising line, it keeps its color and its channel offset, and it starts being tested for a break to the upside. The label carries R1, R2, R3 so a twice-proven line is visibly different from a fresh one, and the cycle is capped at three, after which retested is terminal. A line oscillating around price cannot churn forever.
The status card reports both facts rather than picking one. RISING · RES is a rising line currently acting as resistance. Unflipped lines read RISING · SUP and FALLING · RES, which is what they always meant, said out loud.
THE CHANNEL
Once a line is validated, its parallel rail is projected through the furthest the market travelled away from it while the line was forming. The rail comes from a real extreme rather than from a statistical fit, so the width means something specific: this is how far this structure has been willing to travel from its own floor. Fill and opacity are yours to set, and the fill carries the state, so there is no color legend to memorize.
CONVERGENCE, WITH A TIME
Two validated lines with different slopes meet at an apex, and an apex is a price AND a bar. That is a triangle or a wedge resolving, one of the oldest readable objects in chart reading. It needs both lines retained as DATA rather than as drawings, which is why most auto-trendline scripts cannot offer it at all.
It is reported on the card and alerted, not drawn. A marker painted into future bars would say the same thing and add a drawing to a chart whose whole design rule is fewer marks. And it is a fact, not a forecast: it says where and when the structure runs out of room, not what happens when it gets there.
HIGHER TIMEFRAME LINES
A second engine, off by default, sharing the concepts of the chart-timeframe engine and none of its code paths. If the higher-timeframe layer is wrong, the layer you already trust keeps working.
Why most higher-timeframe trendline overlays are unsound is worth stating. A security call hands back prices. It does not hand back the ability to walk backwards through higher-timeframe bars, and the cleanliness scan IS a walk. So an HTF line built off a plain security read cannot be validated the way a chart line is, and most implementations quietly skip the check. Here, completed higher-timeframe bars are pushed into a ring buffer as they close and the whole HTF engine walks those. A real scan, real HTF touches, and a break that is a real HTF close through the line.
Breaks are judged by the timeframe that OWNS the line. A 15m candle closing through a 4H trendline is not a 4H close, and treating it as one is the most common way an HTF overlay lies. The visible consequence is that an HTF line can die up to one HTF bar later than the chart makes it look like it should. That is correct, and it will look wrong the first time.
What the HTF layer deliberately does not do, each one a decision rather than an omission: no channel, no polarity flip, no apex participation, and no separate alerts. The rail is measured by the same pass that validates the chart line. Converging HTF and chart slopes needs a unit conversion that is wrong the moment the chart timeframe changes. And two engines firing the same alert would double every notification. One slot, defaulted off, because new surface gets proven before it gets duplicated.
THE STATUS CARD
Six live lines on a chart and no way to tell which one matters this bar. The card names the nearest line, the distance to it in points and in ATR, its geometry and its current role, how many broken lines are still awaiting a verdict, and the soonest apex. A table rather than a label, because a label draws inside the price pane and loses the z-order fight with candles.
ALERTS
Trendline validated · Trendline broken · Trendline retest confirmed · Failed trendline break · Trendline convergence approaching
The convergence alert is the one worth leaving on. The other four report something that has already finished, which is useful for a journal. Convergence is the one thing the tool knows about the future, so it is the one alert that can reach you while there is still something to do about it. It is edge-triggered: it arms while the apex is beyond your warning distance and fires once on the way in, rather than firing every bar of the approach until you mute it forever.
WHY IT DOES NOT REPAINT
Lines anchor on confirmed pivots only, and a pivot is not known until the required bars have closed after it. Every state change is judged on a closed bar. The chart-timeframe engine contains no security call at all, and the higher-timeframe engine reads only completed HTF bars, never the one in progress, using the last-closed idiom with an atomic tuple so high, low, close and time cannot straddle a boundary. The cost is a deliberate lag of a few bars on every anchor, and that lag is the guarantee.
WHAT THIS TOOL IS NOT
It draws structure. It shades no band, marks no zone, and makes no claim about resting orders anywhere. When a broken line is reclaimed, this tool calls it a FAILED BREAK, which is a statement about structure and is what the price action supports on its own. A liquidity tool looking at the same bar would call it a sweep, which is a statement about order flow. Same behavior, different claim, and only one of them is visible on the chart.
MADE TO FIT YOUR CHART
Eight card positions, three text sizes, separate colors for rising and falling lines and for their higher-timeframe counterparts, line width, channel fill and opacity, labels on or off, and a toggle per section. Detection, channel, break and retest, style, higher timeframe, card and alerts are separate groups. Pivot length, minimum touches, maximum active lines, the slope cap, the retirement distance, the retest confirmation mode and the retest window are all exposed.
HOW TRADERS ACTUALLY USE IT
Pivot Length decides everything downstream, because it decides which swings exist to be paired. If the chart looks emptier than you expect, that is the first knob, ahead of the touch count.
Minimum touches is the honesty dial. Two touches is a line you drew. Three is a line the market drew. Three is the default for that reason.
Treat a break as the question and the following bars as the answer. Wait for RETESTED or FAILED before deciding what the break meant. The whole tool is built so you do not have to guess which one you are sitting in.
Works on any market and any timeframe.
Display only. This draws structure and reports what happened to it, it does not fire buy/sell signals and it does not forecast. Educational tool, not financial advice.
Published open-source. The pivot pairing and cleanliness scan, the near-duplicate rejection, the two-mode break test, the polarity-flip lifecycle, the apex pre-filter and the higher-timeframe ring buffer are all readable in the source. Everything above explains what it draws and how it decides what to draw; the code is there so you can check that the description is accurate rather than take it on faith. Read it, fork it, argue with the constants.
Forming · Validated · Broken · Retested / Failed break
THE RETEST IS THE PRODUCT
Anyone can draw a line through two pivots and print a marker when price closes through it. The break is the least informative moment in a trendline's life. Most lines break, and the break on its own says nothing about whether the level still matters.
Two things can follow, and they mean opposite things.
• RETEST. Price comes back and respects the line from the OTHER side. Old support is now resistance. The line survived its own break as a reference and is arguably more useful after it than before.
• FAILED BREAK. Price closes straight back on the original side. The break was noise, the line was never beaten, and anyone who traded the break is offside.
This tool waits for one of those and names it. That is the read you cannot get by eyeballing the chart in the moment, because in the moment the two look identical.
FROM ZERO: WHY A DIAGONAL LINE IS A DIFFERENT ANIMAL FROM A HORIZONTAL ONE
A horizontal level is a price. It sits at one number and it is still that number tomorrow. A trendline is a price AND a rate. It asks the market to keep making higher lows at a certain speed, or lower highs at a certain speed. That is a much stronger claim, which is why trendlines break more often than horizontal levels and why the break carries less information when they do.
It is also why a line has to be earned rather than drawn. Two points define any line at all. Three or more touches is the market repeatedly agreeing to the rate.
HOW A LINE EARNS ITS PLACE
Five gates, each closing a specific way auto-trendline scripts produce clutter.
• Confirmed pivots only, paired for direction. A rising support line needs a second swing low strictly HIGHER than the first, a falling resistance line a second high strictly lower. A zero slope is unreachable by construction, so this file never draws a horizontal line.
• A cleanliness scan. Every bar between the two anchors is checked for a close through the line. A line price has already spent time on the wrong side of was never a valid line, and drawing it anyway is how a chart fills with lines nobody would have drawn by hand.
• Touch counting with a spacing rule. A touch is a bar reaching within a quarter of an ATR of the line, and touches within three bars of each other count once. Without the spacing rule one slow drift along a line counts as five touches and validates anything.
• Near-duplicate rejection. Two lines are compared at two sample points, now and fifty bars back, and the newer one is dropped if they sit within 0.75 ATR at BOTH. Comparing at a single point lets two lines with different slopes look identical at the moment they cross.
• A slope cap and abandoned-line retirement. Near-vertical lines off a single spike are refused, and a line price has stayed far away from for twenty consecutive bars is retired. That is what keeps ancient support lines from hanging under current price forever.
TWO WAYS A LINE BREAKS, AND THE SECOND ONE IS THE INTERESTING ONE
The obvious break is distance: a close sitting at least 0.35 ATR beyond the line. That catches the decisive break and it misses the slow one.
Price can park a fraction through a line, too shallow to trigger the distance test and too close to trigger retirement, and grind there bar after bar. Under a distance-only rule the line stays marked VALIDATED with price on the wrong side of it for as long as the grind lasts, which is a tool stating something false. So three consecutive wrong-side closes break a line at any distance. Decisive breaks are caught by distance, grinds by persistence, and there is no state left where the display and the price disagree.
A RETESTED LINE GOES BACK TO WORK
Most implementations treat the retest as the end of a line's life, which is backwards from what the retest proves. A line that broke, was left alone, and then held from the other side has demonstrated it still matters, and the tools that go quiet there stop watching at the exact moment the line earned its keep.
The mechanism is a POLARITY FLIP rather than a new line. Old support becomes resistance, so the side the break test looks at flips while the line's geometric identity does not. It is still a rising line, it keeps its color and its channel offset, and it starts being tested for a break to the upside. The label carries R1, R2, R3 so a twice-proven line is visibly different from a fresh one, and the cycle is capped at three, after which retested is terminal. A line oscillating around price cannot churn forever.
The status card reports both facts rather than picking one. RISING · RES is a rising line currently acting as resistance. Unflipped lines read RISING · SUP and FALLING · RES, which is what they always meant, said out loud.
THE CHANNEL
Once a line is validated, its parallel rail is projected through the furthest the market travelled away from it while the line was forming. The rail comes from a real extreme rather than from a statistical fit, so the width means something specific: this is how far this structure has been willing to travel from its own floor. Fill and opacity are yours to set, and the fill carries the state, so there is no color legend to memorize.
CONVERGENCE, WITH A TIME
Two validated lines with different slopes meet at an apex, and an apex is a price AND a bar. That is a triangle or a wedge resolving, one of the oldest readable objects in chart reading. It needs both lines retained as DATA rather than as drawings, which is why most auto-trendline scripts cannot offer it at all.
It is reported on the card and alerted, not drawn. A marker painted into future bars would say the same thing and add a drawing to a chart whose whole design rule is fewer marks. And it is a fact, not a forecast: it says where and when the structure runs out of room, not what happens when it gets there.
HIGHER TIMEFRAME LINES
A second engine, off by default, sharing the concepts of the chart-timeframe engine and none of its code paths. If the higher-timeframe layer is wrong, the layer you already trust keeps working.
Why most higher-timeframe trendline overlays are unsound is worth stating. A security call hands back prices. It does not hand back the ability to walk backwards through higher-timeframe bars, and the cleanliness scan IS a walk. So an HTF line built off a plain security read cannot be validated the way a chart line is, and most implementations quietly skip the check. Here, completed higher-timeframe bars are pushed into a ring buffer as they close and the whole HTF engine walks those. A real scan, real HTF touches, and a break that is a real HTF close through the line.
Breaks are judged by the timeframe that OWNS the line. A 15m candle closing through a 4H trendline is not a 4H close, and treating it as one is the most common way an HTF overlay lies. The visible consequence is that an HTF line can die up to one HTF bar later than the chart makes it look like it should. That is correct, and it will look wrong the first time.
What the HTF layer deliberately does not do, each one a decision rather than an omission: no channel, no polarity flip, no apex participation, and no separate alerts. The rail is measured by the same pass that validates the chart line. Converging HTF and chart slopes needs a unit conversion that is wrong the moment the chart timeframe changes. And two engines firing the same alert would double every notification. One slot, defaulted off, because new surface gets proven before it gets duplicated.
THE STATUS CARD
Six live lines on a chart and no way to tell which one matters this bar. The card names the nearest line, the distance to it in points and in ATR, its geometry and its current role, how many broken lines are still awaiting a verdict, and the soonest apex. A table rather than a label, because a label draws inside the price pane and loses the z-order fight with candles.
ALERTS
Trendline validated · Trendline broken · Trendline retest confirmed · Failed trendline break · Trendline convergence approaching
The convergence alert is the one worth leaving on. The other four report something that has already finished, which is useful for a journal. Convergence is the one thing the tool knows about the future, so it is the one alert that can reach you while there is still something to do about it. It is edge-triggered: it arms while the apex is beyond your warning distance and fires once on the way in, rather than firing every bar of the approach until you mute it forever.
WHY IT DOES NOT REPAINT
Lines anchor on confirmed pivots only, and a pivot is not known until the required bars have closed after it. Every state change is judged on a closed bar. The chart-timeframe engine contains no security call at all, and the higher-timeframe engine reads only completed HTF bars, never the one in progress, using the last-closed idiom with an atomic tuple so high, low, close and time cannot straddle a boundary. The cost is a deliberate lag of a few bars on every anchor, and that lag is the guarantee.
WHAT THIS TOOL IS NOT
It draws structure. It shades no band, marks no zone, and makes no claim about resting orders anywhere. When a broken line is reclaimed, this tool calls it a FAILED BREAK, which is a statement about structure and is what the price action supports on its own. A liquidity tool looking at the same bar would call it a sweep, which is a statement about order flow. Same behavior, different claim, and only one of them is visible on the chart.
MADE TO FIT YOUR CHART
Eight card positions, three text sizes, separate colors for rising and falling lines and for their higher-timeframe counterparts, line width, channel fill and opacity, labels on or off, and a toggle per section. Detection, channel, break and retest, style, higher timeframe, card and alerts are separate groups. Pivot length, minimum touches, maximum active lines, the slope cap, the retirement distance, the retest confirmation mode and the retest window are all exposed.
HOW TRADERS ACTUALLY USE IT
Pivot Length decides everything downstream, because it decides which swings exist to be paired. If the chart looks emptier than you expect, that is the first knob, ahead of the touch count.
Minimum touches is the honesty dial. Two touches is a line you drew. Three is a line the market drew. Three is the default for that reason.
Treat a break as the question and the following bars as the answer. Wait for RETESTED or FAILED before deciding what the break meant. The whole tool is built so you do not have to guess which one you are sitting in.
Works on any market and any timeframe.
Display only. This draws structure and reports what happened to it, it does not fire buy/sell signals and it does not forecast. Educational tool, not financial advice.
Published open-source. The pivot pairing and cleanliness scan, the near-duplicate rejection, the two-mode break test, the polarity-flip lifecycle, the apex pre-filter and the higher-timeframe ring buffer are all readable in the source. Everything above explains what it draws and how it decides what to draw; the code is there so you can check that the description is accurate rather than take it on faith. Read it, fork it, argue with the constants.
Skrypt open-source
W zgodzie z duchem TradingView twórca tego skryptu udostępnił go jako open-source, aby użytkownicy mogli przejrzeć i zweryfikować jego działanie. Ukłony dla autora. Korzystanie jest bezpłatne, jednak ponowna publikacja kodu podlega naszym Zasadom serwisu.
Wyłączenie odpowiedzialności
Informacje i publikacje nie stanowią i nie powinny być traktowane jako porady finansowe, inwestycyjne, tradingowe ani jakiekolwiek inne rekomendacje dostarczane lub zatwierdzone przez TradingView. Więcej informacji znajduje się w Warunkach użytkowania.
Skrypt open-source
W zgodzie z duchem TradingView twórca tego skryptu udostępnił go jako open-source, aby użytkownicy mogli przejrzeć i zweryfikować jego działanie. Ukłony dla autora. Korzystanie jest bezpłatne, jednak ponowna publikacja kodu podlega naszym Zasadom serwisu.
Wyłączenie odpowiedzialności
Informacje i publikacje nie stanowią i nie powinny być traktowane jako porady finansowe, inwestycyjne, tradingowe ani jakiekolwiek inne rekomendacje dostarczane lub zatwierdzone przez TradingView. Więcej informacji znajduje się w Warunkach użytkowania.