OPEN-SOURCE SCRIPT
Atualizado Keltner Channels XL

This script plots a Keltner Channel built around a user-selected moving average (EMA or SMA) of price. The upper and lower bands are derived by adding and subtracting a volatility measure, which can be based on ATR, True Range, or a smoothed high–low range.
Trend direction is determined by measuring the percentage change of the basis line over a configurable lookback period. That change is compared against a neutral threshold, which defaults to 0.05%. If the basis rises more than this threshold, it is classified as an uptrend; if it falls more than the threshold, it is classified as a downtrend. If the movement stays within that range, it is treated as neutral, meaning the market is effectively moving sideways.
The basis line is plotted with increased thickness and changes color based on this trend classification. The channel bands and background fill adopt the same color, so the entire channel visually reflects whether the market is trending up, trending down, or consolidating.
Trend direction is determined by measuring the percentage change of the basis line over a configurable lookback period. That change is compared against a neutral threshold, which defaults to 0.05%. If the basis rises more than this threshold, it is classified as an uptrend; if it falls more than the threshold, it is classified as a downtrend. If the movement stays within that range, it is treated as neutral, meaning the market is effectively moving sideways.
The basis line is plotted with increased thickness and changes color based on this trend classification. The channel bands and background fill adopt the same color, so the entire channel visually reflects whether the market is trending up, trending down, or consolidating.
Notas de Lançamento
This version of Keltner Channels adds a trend filter by coloring the moving average based on its slope normalized by ATR. The slope is measured over a lookback period and scaled by volatility, so behavior stays consistent across timeframes.The MA turns green or red when its movement exceeds a threshold, and gray when it does not. The neutral (gray) zone means the MA has moved less than a set fraction of ATR over the lookback, indicating a balanced market with no meaningful directional expansion.
This differs from price being inside the channels. Channel position shows where price is relative to volatility, while MA color shows whether the market is actually trending or not.
Notas de Lançamento
Pine category updated.Notas de Lançamento
**Keltner Channels XL — Change Log**---
**What got removed**
The indicator previously had a timeframe override built into it, which allowed it to calculate on a different timeframe than the chart. This has been removed entirely. The indicator now simply runs on whatever timeframe your chart is set to — no exceptions, no hidden timeframe logic running in the background. This makes the indicator more predictable and transparent in its behavior.
The buy/sell signal labels are also completely gone. This includes the labels themselves, all of their color and text controls, the show/hide toggle, and both alert conditions that fired when a new trend was detected. The decision was to keep this indicator focused purely on the channel itself and let signal logic live elsewhere.
---
**What got added**
**Non-Repainting Mode** is a new boolean toggle sitting at the very top of the settings panel, above every group and every other input. It is on by default. When enabled, the indicator shifts all of its calculations to use the previous bar's confirmed close rather than the current bar's live value. This means the indicator will never change its historical output as a bar develops — what you see painted on past bars is locked in permanently. The tradeoff is a one bar lag on all calculations and color transitions, which is a worthwhile exchange for anyone using this on a live chart where repainting would be a concern. Turning it off restores the original real-time behavior.
The **General group** is new and replaces what was previously called Core Settings. It now contains one additional input that wasn't there before — **Basis Type**, which was previously tucked away in its own separate Basis group. Having length, multiplier, source, and basis type all in one place makes the foundational settings much easier to find and configure together.
The **Trendline Style group** is entirely new and didn't exist in any form previously. It gives you granular control over the appearance of the basis line with the following inputs:
- **Show Basis Line** — a toggle to hide or show the basis line entirely without having to set it to transparent or remove it from the chart. On by default.
- **Trendline Color** — a color picker specifically for the basis line. Defaults to black.
- **Trendline Thickness** — an integer from 1 to 4 controlling how thick the basis line renders. Defaults to 2.
- **Trendline Style** — a dropdown letting you choose between Solid, Dashed, and Dotted. Defaults to Solid.
The **Bands group** has also been expanded significantly beyond what it previously contained. It now includes three new inputs alongside the existing calculation settings:
- **Show Band Lines** — a toggle to hide or show both band lines simultaneously without affecting the basis or the fill. On by default.
- **Band Thickness** — an integer from 1 to 4 controlling the thickness of both the upper and lower band lines. Defaults to 1.
- **Band Line Style** — a dropdown for Solid, Dashed, or Dotted, matching the same option set as the basis line. Defaults to Solid.
---
**How the color system was redesigned**
This is the most significant conceptual change in the entire update and it's worth understanding clearly. In the original version, trend coloring was a single on/off toggle that drove the color of everything at once — the basis line, the band lines, and the background fill all changed color together based on the detected trend direction. This made it impossible to have colored lines without a colored background or vice versa.
The new system separates these concerns completely. The lines — both the basis and the bands — always use whatever color you set in the Trendline Color picker. They never change dynamically. All of the dynamic color behavior has been moved exclusively into the channel fill, which is now controlled by the **Channel Background group** — previously called Trend Coloring — with several updated and new inputs worth walking through:
**Background Mode** replaces the old Enable Basis Trend Coloring boolean toggle. Rather than a simple on/off, it is now a dropdown with three named options:
- **None** means no fill is drawn at all. The channel is defined purely by its lines with a completely transparent interior. This is the cleanest look for traders who find background color distracting.
- **MonoColor** fills the channel with a single static color of your choosing. The fill doesn't react to trend direction at all — it just provides a consistent visual zone. This is useful for marking the channel as a meaningful area without implying any directional bias.
- **Trend Color** is the closest to the original behavior, where the fill color changes based on whether the slope calculation determines the channel is rising, falling, or flat. The key difference from before is that this now only affects the fill — your line colors stay exactly as you set them regardless of what the background is doing.
**MonoColor** is a brand new color input that only applies when Background Mode is set to MonoColor. It defaults to a 50% transparent gray, giving you a neutral unbiased channel fill straight out of the box. You can set this to any color you want — the transparency you set in the color picker is respected directly.
**Background Opacity %** is a new integer input ranging from 0 to 100 that controls how opaque the channel fill appears. It defaults to 30, which gives a subtle but visible fill. Setting it to 0 makes the fill invisible regardless of mode, and setting it to 100 makes it completely solid. This input was designed to be intuitive — higher numbers mean more visible, which is the opposite of how Pine Script handles transparency internally. That inversion is handled automatically under the hood so you never have to think about it.
---
**Smaller but notable tweaks**
The multiplier default was raised from 0.5 to 1.0, which produces a noticeably wider channel out of the box and is more in line with how most traders use Keltner Channels in practice. The trend slope lookback default was doubled from 5 to 10 bars, making the trend detection slightly less reactive on default settings. The flat and neutral color default was softened from solid black to a 50% transparent gray, which reads more naturally as a neutral state rather than a strong directional signal.
Notas de Lançamento
# Keltner Channels XL — Change Log**Version Update | Bug Fix Release**
---
## What Was Broken
The indicator had a silent but frustrating bug hiding in its color system. When you opened the settings and adjusted the transparency of the **Uptrend Color** or **Downtrend Color** using the color picker, absolutely nothing changed on the chart. The colors stayed exactly the same no matter what you did. This wasn't a display glitch — the code was actively ignoring your input and replacing it with its own hardcoded value every single time the chart updated.
---
## What Caused It
Deep inside the indicator's logic, every time it went to paint the channel background, it was taking your chosen color and immediately stripping out whatever transparency you had set, then forcing it to a fixed value of 50% opacity — no exceptions. It didn't matter if you wanted 10% transparency or 90% transparency. The code had the final say, not you. Your settings were being read, then thrown in the bin.
On top of that, the default starting colors for both the uptrend and downtrend were set to **fully opaque** — meaning on a fresh load the channel fill would flood the chart with a solid wall of color, which was clearly never the intended look.
---
## What Was Fixed
- **Uptrend and Downtrend colors now fully respect your transparency setting.** Whatever opacity you dial in through the color picker is exactly what gets painted on the chart. No overrides, no interference.
- **The Flat/Neutral color received the same fix.** It was caught in the same override trap and has been corrected to also honor your chosen transparency.
- **Default transparency for Uptrend and Downtrend colors has been set to 50%.** This means on a fresh installation the channel fill looks clean and balanced right out of the box, without needing to manually fix it before the indicator is usable.
- **MonoColor mode was left intentionally unchanged.** It still applies a consistent 50% transparency by default, which is appropriate behavior for that mode and was not part of the reported issue.
---
## What You'll Notice Now
- Dragging the opacity slider in the color picker will produce an **immediate, visible result** on your chart
- The channel fill will no longer appear as a heavy opaque block when you first add the indicator
- All three trend states — uptrend, downtrend, and neutral — now behave consistently and respect your personal color preferences
- Nothing else about the indicator's behavior, calculations, or signals has changed in any way
Script de código aberto
Em verdadeiro espírito do TradingView, o criador deste script o tornou de código aberto, para que os traders possam revisar e verificar sua funcionalidade. Parabéns ao autor! Embora você possa usá-lo gratuitamente, lembre-se de que a republicação do código está sujeita às nossas Regras da Casa.
Aviso legal
As informações e publicações não se destinam a ser, e não constituem, conselhos ou recomendações financeiras, de investimento, comerciais ou de outro tipo fornecidos ou endossados pela TradingView. Leia mais nos Termos de Uso.
Script de código aberto
Em verdadeiro espírito do TradingView, o criador deste script o tornou de código aberto, para que os traders possam revisar e verificar sua funcionalidade. Parabéns ao autor! Embora você possa usá-lo gratuitamente, lembre-se de que a republicação do código está sujeita às nossas Regras da Casa.
Aviso legal
As informações e publicações não se destinam a ser, e não constituem, conselhos ou recomendações financeiras, de investimento, comerciais ou de outro tipo fornecidos ou endossados pela TradingView. Leia mais nos Termos de Uso.