Function Polynomial Regression: An Indicator That Draws a Curve Through Swing Highs and Lows
A trend can look healthy on the surface while it quietly runs out of steam, or it can be speeding up. Staring at a moving average, it’s hard to tell which. That “bend” in the trend is what this indicator is built to show.
Function Polynomial Regression is a TradingView indicator that grabs the 10 most recent swing highs and lows on your chart and fits a curve through them. The math behind it is polynomial regression, and the easiest way to think of it is a regression line that’s allowed to bend.

It plots five lines in total: one center curve and two pairs of bands around it. The slope and bend of the curve tell you how the trend is changing, while the bands show the “normal” swing range and the largest recent overshoot. There are no buy or sell signals. This is an analysis tool that cleans up the shape of the market for you.
The five lines Function Polynomial Regression draws
It fits a quadratic curve to the last 10 swing highs and lows, then draws a center line and two types of bands.
Vowars DE ver.3.23.2
For this review I loaded it on Bitcoin across eight timeframes, from the 1-minute to the weekly. Every timeframe shows the same five lines; the only thing that changes is how much history the curve covers.
What the Five Lines Mean
Let’s start by going through what each of the five lines represents.
The Solid Blue Line Runs Through the Middle of the 10 Swings
The thick solid blue line is the star of the show. It’s the curve that best fits the last 10 swing highs and lows, meaning the one with the smallest overall error Figure 1. With the default settings it’s a quadratic, so you get an arc that bends just once.
Look closely and you’ll see the curve is actually a series of short straight segments joined together. It’s split at each swing point and drawn with up to nine segments, so where the swings are spaced far apart the curve can look a bit angular.
The Dashed Aqua Lines Show the Average Deviation
The dashed aqua lines above and below the blue curve take the average distance between the 10 swing points and the curve, and add it equally on both sides Figure 2. Unlike Bollinger Bands, this isn’t a standard-deviation band; it’s the plain average of how far the pivots sit from the curve. Read it as “recent swings usually land about this far from the curve.”
The Dotted Purple Lines Touch the Most Extreme Swing
The outermost dotted purple lines mark the distance to the point furthest above the curve and the point furthest below it Figure 3. They always touch one of the swing points used in the calculation, so they act like a record of the biggest overshoot among the last 10 pivots.
Because the top and bottom are set independently, the two widths rarely match. When a single high spikes out, only the upper purple line widens Figure 1. The lower line is set by the deepest swing low Figure 2, and it’s the aqua lines that stay equally wide on both sides Figure 3.
The purple bands can be lopsided
The outer purple lines stretch to whichever of the 10 pivots sits furthest from the curve.
Vowars DE ver.3.23.2
You’ll see this lopsided look on live charts all the time. On the 4-hour chart in this example, the upper line stretched to meet the high of a big pump candle, while the lower line sat close to the aqua band. When the purple band is wide on just one side, it tells you there’s one swing on that side that moved much further than the rest.

| Line | Style | What it shows | How to read it |
|---|---|---|---|
| Solid blue line | Thick solid line | Curve fitted to the last 10 swing highs and lows | Slope shows direction, bend shows momentum shifts |
| Dashed aqua lines | Thin dashed lines (upper and lower) | Average deviation from the curve | Guide to the normal swing range. Same width on both sides |
| Dotted purple lines | Thin dotted lines (upper and lower) | Distance to the swing furthest from the curve | Largest overshoot among the last 10 pivots. Width can differ above and below |
The Curve Is Built From Just 10 Confirmed Swing Points
The most important thing to understand here is what the curve is actually built from. It doesn’t use the close of every bar. It picks highs that are higher than the two bars on each side as swing highs, lows that are lower as swing lows, and keeps only the 10 most recent Figure 1.
Each time a new swing high or low appears, the oldest one gets pushed out Figure 2. The small up-and-down moves between pivots aren’t part of the calculation, so even in a wick-heavy market the curve doesn’t get yanked around by every single candle.
There’s one more detail: a swing high or low only confirms once two bars have closed to its right Figure 3. That means the curve doesn’t end at the current bar; it stops at the last confirmed pivot. That’s why you’ll usually see a gap of a few bars between the right edge of the chart and the end of the curve.
The 10 swing points behind the curve
A bar higher than the two bars on each side becomes a swing high, a lower one a swing low, and only the 10 most recent are used.
Vowars DE ver.3.23.2
Comparing two bars on each side to define a swing high or low is essentially the same idea as TradingView’s built-in Williams Fractals. If you already run fractals on your chart, think of it this way: the highs and lows marked by those fractals are what the curve is built from. Since highs and lows sit in the same list, the curve runs roughly between the swing highs and the swing lows.
How to Read the Curve and Bands on Your Chart
When you look at a live chart, run through these three checks in order.
1 How is the slope of the curve changing?
Start with the slope of the blue curve. A steep slope means highs and lows are stepping up (or down) quickly Figure 1. If the curve starts to flatten during an uptrend, that’s a sign the higher highs and higher lows are losing steam Figure 2.
You can read slope off a moving average too, but because Function Polynomial Regression fits an arc to the swing points alone, acceleration and deceleration show up directly in the shape of the line. After a sell-off, if the curve forms a visible bottom and its right side starts turning up, that’s the moment to start suspecting a shift from a bottoming market into a relief rally.
Reading momentum from the curve's slope
When the blue curve flattens, the higher highs and higher lows are losing steam.
Vowars DE ver.3.23.2
On the 5-minute chart I caught a clean dome-shaped arc rolling over from up to down. Even when price action still “looks like it wants to go higher,” a curve that has already peaked and turned lower is a good cue to step back and take a breath.

2 Where is price sitting within the bands?
Next, check where price is relative to the bands. Inside the aqua lines is the “normal” swing range; the purple lines mark the most extreme point among the last 10 pivots.
- In an upward arc, a swing low that holds near the lower aqua line is a candidate to buy the dip
- In a downward arc, a swing high that stalls near the upper aqua line is a candidate to sell the rally
- A move that stretches close to a purple line is on the overextended side for recent swings. It works as a guide for when to start thinking about taking profit
- A move that blows well past a purple line is outside the range of the last 10 pivots. Once the next swing confirms, there’s a good chance the shape of the curve will change
3 Check the bars after the last pivot yourself
Finally, look at the bars to the right of where the curve ends. That stretch isn’t in the calculation yet, so the curve can’t tell you anything about it Figure 3. Extend the curve’s direction by eye and see which side of that projection the current bar is on. That gives you something to go on when judging whether the trend is still intact.
Function Polynomial Regression isn’t built to give entry or exit signals. Use the direction of the curve and price’s position in the bands to frame “what the market looks like right now,” and get your actual entry trigger from price action or another indicator.
Switching Between a Straight Line and an Arc With degree
degree sets the order of the polynomial, which is basically “how many times the curve is allowed to bend.” The default is 2, which gives you an arc that bends once. Set it to 1 and you get a straight line, the same idea as a regression line fitted to the swing points.
With the same swing points, a degree of 1 shows only the overall slope as a single straight line Figure 1, while 2 also captures the bend from a bottom into an uptrend Figure 2. In my testing, the split that worked best was 1 when you only care about trend direction and 2 when you also want to see momentum shifts.
degree switches between a line and an arc
Same 10 pivots, different center line, depending on degree.
Vowars DE ver.3.23.2
You can type in 3 or higher. However, this indicator feeds the raw bar number, counted from the left edge of the chart, straight into the curve calculation. When I reproduced the same calculation myself, once bar numbers got into the thousands the extra bend of a 3rd-degree curve almost disappeared and it looked nearly identical to degree 2. The more bars your chart has loaded, the more likely a setting of 3 or higher won’t give you the shape you expect. Sticking to 1 and 2 is the safer bet.
Changing How Far Back the Curve Looks With length and fractal_size
Two settings control how much history the curve covers. length is the number of swing points used, and fractal_size is the number of bars compared on each side when detecting a swing.
By default it uses 10 small swings, so the curve only looks back a few dozen bars Figure 1. Raising length to 20 doubles the number of pivots, and in my test the whole sell-off from the previous major high fit into a single arc Figure 2.
Set fractal_size to 5 and only bars higher (or lower) than the five bars on each side count as swings. Minor waves get filtered out, so even with the same 10 pivots they’re spaced further apart, and the entire move from rally to decline became one big arc Figure 3. Keep in mind that each swing then needs five bars to its right to confirm, so the right end of the curve lags by that much more.
Two ways to widen the curve's lookback
You can either use more pivots (length) or make the pivot test stricter (fractal_size).
Vowars DE ver.3.23.2
The curve and bands are drawn with up to nine connected segments. If you set length to something that isn’t a multiple of 10, like 15, the segments get assigned unevenly and the newest stretch or some middle stretches may not be drawn, leaving gaps in the curve. I reproduced this as well: at 15, the segment connecting the most recent swings was missing. If you go above 10, use 20, 30 and so on, and the curve stays connected from start to finish.
Settings
There are six inputs in the settings panel. The input names are shown exactly as the variable names in the script.
| Setting | Default | Suggested | Effect |
|---|---|---|---|
| length | 10 | 10 (20 or 30 for a longer view) | Number of swing points used for the curve. Higher values capture a longer stretch in one arc and tend to widen the bands. Above 10, use multiples of 10 so the curve isn’t broken |
| degree | 2 | 2 (1 for slope only) | Order of the curve. 1 gives a straight line, 2 an arc that bends once. 3 or higher tends to be unstable on charts with many bars loaded |
| fractal_size | 2 | 2–5 | Number of bars compared on each side to detect a swing. Higher values keep only prominent swings and lengthen the curve’s lookback, but delay swing confirmation |
| _pr_mid_col | Blue | Default | Color of the center curve (solid line) |
| _pr_std_col | Aqua | Default | Color of the dashed lines showing the average deviation |
| _pr_max_col | Purple | Default | Color of the dotted lines showing the distance to the most extreme swing |
Suggested Settings by Use Case
These are the combinations that worked well for different goals in my testing. Swing spacing depends on how the market is moving, so treat them as a starting point.
| Goal | length | degree | fractal_size | Why |
|---|---|---|---|---|
| See how recent small swings are bending | 10 | 2 | 2 | Default. For day trading, tracks momentum shifts over the last few dozen bars |
| See the shape of a bigger move | 20 | 2 | 2 | Uses more pivots so the arc reaches back to the previous major high or low |
| Spot major tops and bottoms | 10 | 2 | 4–5 | Ignores minor waves and fits the arc to major swings only |
| Check trend direction only | 10–20 | 1 | 2 | No bend, just the direction of the swing sequence as a straight line |
How It Looks on Different Timeframes
I ran it on the 1-minute, 5-minute, 15-minute, 30-minute, 1-hour, 4-hour, daily and weekly charts. Since the curve always covers “10 swings,” the lower the timeframe, the shorter the window. On the 1-minute it covered a little under an hour; on the weekly, more than six months of price action became a single arc.

On higher timeframes like the weekly, you get a big U-shape from bottom to recovery, which makes it easy to confirm the market’s larger phase with a single line. On lower timeframes, swings get replaced quickly and the shape of the curve changes just as fast.
As I’ll cover below, this indicator doesn’t redraw the curve on its own while the chart stays open. With that in mind, I found it pairs best with day and swing trading on the 30-minute to 4-hour charts, where you naturally re-check the shape each time you open the chart, and with reading the market’s phase on the daily and above.
How It Differs From the Linear Regression Channel
When you hear “regression,” TradingView’s built-in Linear Regression Channel probably comes to mind. Both draw bands above and below a fitted line, so they look alike, but they’re built from different data and their bands mean different things.
| Comparison | Function Polynomial Regression | Linear Regression Channel |
|---|---|---|
| Input data | Highs and lows of the last 10 swing points | Closes of a fixed number of recent bars |
| Center line | Arc that bends once by default (can be set to a straight line) | Straight line |
| Band width | Two types: average deviation, and distance to the most extreme swing | A multiple of the standard deviation |
| Right end | Stops at the last confirmed swing | Extends to the current bar |
The Linear Regression Channel uses a fixed bar count, so it treats quiet and volatile stretches as the same number of bars. Function Polynomial Regression is defined by the number of swings instead: in a market with big, widely spaced waves it naturally looks further back, and in a market full of small waves it looks at a shorter window. If you want to read the market’s shape in terms of “number of waves,” I think this one is the better fit.
Three Situations Where It Helped
After using it for a while, these are the situations where Function Polynomial Regression actually helped my decision-making.
1 Before buying a dip, check that the upward arc is still intact
When waiting to buy a pullback in an uptrend, if the curve is still a rising arc and price drops to around the lower aqua line, that’s a dip worth watching. If the curve has already flattened, or has peaked and turned down, it’s a hint that this may be a correction near the top rather than a dip to buy.
2 Use the recent overshoot as a take-profit guide
The purple line on the side of your open position marks the furthest point reached among the last 10 swings. A move that gets there has stretched a lot by recent standards, which made it a handy level for scaling out part of the position.
3 Spot a sideways market by how flat the curve is
In a range, swing highs and lows keep hitting similar levels, so the curve goes almost flat and the bands spread out comfortably above and below. While the curve stays flat, treat it as a market with no clear direction, and wait for higher lows and higher highs to tilt the curve upward before jumping on the trend.
It feels better suited to day trading and swing trading, where you can wait for a few swings to confirm, than to scalping, where you’re reacting bar by bar.
Drawing Quirks Worth Knowing
When New Swings Are Added, the Past Curve Gets Redrawn Too
Function Polynomial Regression recalculates the curve and bands from scratch every time the set of 10 swings changes. Just two new pivots can turn a curve whose right end was almost flat Figure 1 into an upward arc over the very same stretch Figure 2. As old swings drop out, the start of the curve also shifts to the right Figure 3.
When new pivots confirm, the whole curve is redrawn
Every time the 10 pivots change, the indicator recalculates the curve and bands from scratch.
Vowars DE ver.3.23.2
This is simply how a regression curve works, and it’s a different thing from a buy or sell signal appearing and disappearing. Still, a clean-looking curve on historical bars isn’t necessarily the curve you would have seen in real time, and that’s worth keeping in mind. When you look back and think “I should have bought the bottom of the curve,” also check when that bottom actually confirmed.
While the Chart Is Open, the Curve Keeps Its Shape From Load Time
The other quirk is update timing. When the chart loads, the indicator calculates every historical bar and draws the curve, then keeps updating it until the bar that was forming at load time closes Figure 1. From the next bar on, new swings are still being recorded, but the curve itself isn’t redrawn Figure 2.
When the curve gets redrawn
The curve and bands are drawn when the chart loads, and while it stays open they only update on the bar that was forming at load time.
Vowars DE ver.3.23.2
If you leave the chart open for a long time, the curve keeps its old shape even after new swings confirm. To see the latest shape, switch timeframes, change an input, or reload the page, which forces a recalculation and redraws the curve using every swing up to that point.
No Built-In Alerts
This indicator doesn’t include any alert conditions. If you want to know when price is approaching the curve or a band, one option is to draw a horizontal line at the level you care about and set an alert on that drawing in TradingView. Since the curve moves each time it’s redrawn, remember to adjust the horizontal line as well.
Pair It With the Fisher Transform to Catch Turns Earlier
The Function Polynomial Regression curve doesn’t change direction until new swings confirm and enter the calculation. Even after a top is in, the curve can stay flat until the next swing low and high confirm.
A good match to cover this weak spot is TradingView’s built-in Fisher Transform. It’s an oscillator that converts price’s position within its recent range so that extremes swing harder; it updates on every bar and flips direction sharply at turning points.
Spotting the top earlier with the Fisher Transform
The curve rarely turns until new pivots confirm, so the Fisher Transform, which updates on every bar, is used to catch the momentum shift first.
Vowars DE ver.3.23.2
While the right end of the curve is still nearly flat Figure 1, the Fisher Transform has already crossed down on the very next bar after the top Figure 2 and drops below 0 a few bars later Figure 3. Use the curve to confirm the shape of the bigger move and the Fisher Transform to see whether momentum has turned first, and you’ll have something to work with while you wait for the curve to catch up.
You can also split roles with indicators like these.
- Pair it with Historical Volatility. The width of the purple band is set by a single swing among the recent pivots, so it can’t tell you whether the whole market is volatile. Adding Historical Volatility, which measures how choppy price is overall, in a lower pane makes it easier to tell whether wide bands come from “one spike” or “a volatile market overall”
- Pair it with Keltner Channels. Its ATR-based bands update on every bar, so even in the stretch to the right where the curve has stopped, they still give you a read on when price is overextended. Useful as a backup when deciding where to take profit
Where It Shines and What to Watch For
What swing-based arcs reveal
- Builds the curve from the sequence of swings rather than every candle’s noise, so the shape of the trend is easy to see
- Changes in the curve’s slope let you read trend acceleration and deceleration as a shape
- Shows two bands with different jobs at once: the aqua lines for the “normal” swing range and the purple lines for the “largest recent overshoot”
- length and fractal_size let you scale the view from small recent swings up to multi-month arcs
Things to keep in mind
- The curve stops at the last confirmed swing and doesn’t extend to the current bar
- Each new swing triggers a full redraw, including the earlier part of the curve
- The curve doesn’t update on its own while the chart stays open, so you need to force a recalculation to see the latest shape
- Setting length to anything other than a multiple of 10 can leave parts of the curve undrawn
My Take After Using Function Polynomial Regression
ImageFunction Polynomial Regression uses nothing but swing highs and lows to show, with a single line, “what kind of arc the market is tracing right now.” Unlike a moving average that reacts to every candle, it turns the sequence of swings itself into a curve, so you can actually see whether a trend is accelerating or fading.
On the flip side, the curve stops at the last swing and gets redrawn every time a new one comes in. Factor in that it doesn’t update while the chart stays open, and it’s easiest to use if you treat it as “an indicator for checking the market’s shape at that moment.”
For settings, keep degree at 1 or 2 and length at 10 or a multiple of 10, and it’s easy to dial in. Open the chart, check the curve’s slope and where price sits. Used that way, it’s a nice nudge to keep the trend’s turning points in mind.









