INDICATOR GUIDE / ILLUSTRATED EXPLANATION
MA Channel Optimizer: how does the pivot-fitted moving-average channel work?
The indicator shows a moving average and a channel fitted around it. It helps you examine where price sits relative to the trend and earlier turning points. The lines alone do not tell you where the market will move next.
Start with the picture!
The example uses EMA95 and the D1 timeframe with fictional prices. We drew the curves using the indicator's calculation method; this is an explanatory diagram, not a screenshot or forecast for an actual instrument.
1 · Centre line
The selected moving average. Its direction provides a smoothed view of the trend; whether price is above or below it is one clue to the trend's state.
2 · Upper channel edge
A curve fitted above the centre line using distances of earlier highs. It can be examined as a possible resistance area, but it is not a compulsory turning point.
3 · Lower channel edge
A curve fitted below the centre line using distances of earlier lows. It can be examined as a possible support area, but price can break through it.
Marker 4 shows the closing price of the last completed candle.
How is the channel constructed?
- First, the moving average of the selected prices is calculated. In the example, this is the EMA95 of daily closing prices. The SMA gives equal weight to prices in its window, while the EMA gives more weight to recent data.
- The system looks for local highs and lows among the candles under examination. A pivot is a candidate turning point compared with surrounding candles. A pivot setting of 5 examines 5 candles on each side, so confirmation also requires 5 later candles.
- At highs, it measures the distance between that high and the moving average at that time; at lows, it measures the distance between the moving average at that time and the low. The upper and lower sides are searched separately.
- It groups similar distances and selects the group containing the most points. The offset is the mean of the selected distances. In this code, “Optimizer” means this fitting process, not a backtest that maximises profit.
- The upper edge is the centre line plus the upper offset; the lower edge is the centre line minus the lower offset. The two distances can differ, so the channel is not necessarily symmetrical. The curves follow the shape of the moving average.
The tolerance adapts to recent price movement: the ATR-based value considers both the high–low range and gaps relative to the previous close. By default, it uses the simple average of the last 14 True Range values; this can differ from another platform's smoothed ATR.
More precisely: what does tolerance mean?
The default tolerance multiplier is 0,20. The full width of the selected distance group is at most twice the tolerance. The group's mean determines the offset; this does not imply that every selected point also falls within a tolerance band around the mean line.
The touch count here is the number of points in the selected pivot group. It does not count all candle contacts or successful trades. The channel is not a statistical confidence band or a Bollinger Band.
What does each setting change?
The program defaults to SMA50 calculated from closing prices. The EMA95 shown is a separately chosen example: select EMA and a period of 95 to use it. The value 95 is not advantageous or optimal in every market.
Four average types are available: SMA (simple), EMA (exponential), SMMA (smoothed) and LWMA (linearly weighted). EMA95 also carries the influence of older candles forward with diminishing weight; it is not the same as the simple average of the last 95 closing prices.
| Setting | Default value | What does it affect? |
|---|---|---|
| Moving average | SMA · 50 | The average's type and period. The example uses EMA · 95; on D1, the period means 95 daily candles. |
| Applied price | Closing price | Open, high, low and composite prices are also available. They can produce a different curve even with the same period. |
| Lookback window | 300 candles | It searches this recent segment for pivots usable in the channel; earlier history is also needed to calculate the average. |
| Pivot strength | 5 + 5 candles | A higher value can produce less frequent turning points and a longer confirmation delay. On a daily chart, we count candles rather than calendar days. |
| ATR period | 14 | The average True Range window used to calculate tolerance. |
| Tolerance multiplier | 0,20 | Changes the permitted variation when grouping distances; a higher value allows a looser fit. |
| Minimum pivots | 3 | This many selected points are required to display the relevant channel edge. If there are too few suitable pivots, one edge may be absent. |
| Completed candles only | Enabled | The TradingView version excludes the still-open candle. This does not prevent subsequent channel refitting. |
How should you read price in relation to the lines?
Around the average
A rising average with the closing price above it can be consistent with an uptrend. Repeated crosses around a flat average may instead suggest a sideways, noisy environment. A single cross does not prove a trend reversal.
Near the upper edge
A touch of the upper edge can mark a pause or be part of further gains in a strong trend. A close above it followed by a held retest can support a breakout hypothesis. A return inside the band weakens it. This is an interpretation framework, not an automatic signal generated by the code.
Near the lower edge
Holding the lower edge can indicate a support reaction. A close below it and a failed reclaim can be consistent with a weakening scenario. A touch alone is not a buy signal, and a breakdown alone does not require selling.
If the centre line is 100, the upper offset is 6 and the lower offset is 4, the two edges are 106 and 96. A closing price of 103 is 3% above the average but remains inside the channel. It is therefore not an upper-channel breakout.
Relative to the upper edge of 106 recorded at that moment, a close of 107 would be above it. This still provides no verified future profit; the channel's value may also change at the next calculation. The example contains no actual instrument, return calculation or trading offer.
Why can historical lines change as well?
The channel is always fitted to the latest lookback window. When a new turning point appears or an old point leaves the window, a different distance group may become the largest, changing both offsets. The program also redraws the previously displayed segment using the new offsets.
A line that fits neatly in today's picture therefore does not prove it was in the same place when an earlier decision was made. Using completed candles reduces uncertainty from changes in an open candle, but does not prevent this refitting. Pivots can also only be confirmed after later candles.
For before-and-after analysis, save dated images and the line values at the time. In a backtest, the fit must be recalculated at every historical point using the data available then; projecting today's channel backwards is unsuitable for this.
A practical sequence of checks
- Check the instrument, timeframe, average type, period and whether the candle under examination is completed.
- Look at the average's direction and the closing price's position. Distinguish being above the average from actually crossing the upper channel edge.
- Define the condition and invalidation in advance: what close or return would weaken the hypothesis? Record the levels at the time instead of adapting the old story retrospectively to the new channel.
- Assess the picture in its market context: another timeframe, important news, spreads and execution risk also matter. The indicator does not size positions or replace a complete trading plan.
This tool describes the state of the instrument currently open. Being above the 95-period average and breaking out of a channel are two separate conditions; the indicator alone is not a results list for the entire stock index.
Sources and related material
- Source code of the MA Channel Optimizer available on this website
- MetaQuotes: calculating the moving-average types
- TradingView: understanding historical repainting and pivot confirmation delay
The channel's specific behaviour is based on the source code of the custom indicator; the external documentation explains the general background of moving averages and repainting. The example image is a mathematical illustration, not a trading result obtained by running the script on a platform.


