OPEN-SOURCE SCRIPT
HMA-Kahlman Trend & Trendlines

HMA-Kahlman Trend & Trendlines
Pine Script™ v6 | Overlay Indicator
by NPR21
Publication Description
A professional-grade trend identification and dynamic trendline indicator that combines two powerful analytical modules into a single overlay. The HMA-Kahlman Trend Module applies an optional Kalman filter to the Hull Moving Average for ultra-smooth, low-lag trend detection. The Trendlines Module auto-detects pivot highs and lows, draws connecting support/resistance trendlines, and projects dashed extension lines into the future. Together, they deliver real-time trend direction, precise BUY/SELL crossover signals, and automatically drawn structural trendlines—all from one indicator.
Built for any liquid market—futures, forex, stocks, crypto, and commodities. Works on all timeframes from 1-minute scalping charts to daily swing setups.
What Makes This Indicator Unique
Most trend indicators force you to choose between responsiveness and smoothness. This indicator eliminates that tradeoff by layering a Kalman filter on top of the Hull Moving Average—a combination rarely seen in Pine Script. The Kalman filter is an adaptive smoothing algorithm originally developed for aerospace navigation that dynamically adjusts its output based on incoming price data, removing noise without introducing the lag typical of traditional moving averages.
Key Differentiators
•Dual-engine trend detection: Standard HMA (Line A) and a triple-weighted HMA3 variant (Line B) run simultaneously. Their crossovers generate high-confidence directional signals because each line processes price through a fundamentally different weighting scheme.
•Kalman-filtered smoothing: The optional Kalman filter with adjustable gain lets you dial in exactly how much noise reduction you want—from aggressive scalping responsiveness (high gain) to smooth swing-trade clarity (low gain).
•Auto-drawn structural trendlines: The Trendlines Module detects pivot highs and lows, connects the two most recent pivots with dashed resistance/support lines, and projects extension lines forward—giving you dynamic S/R levels without any manual drawing.
•Integrated signal + structure: Unlike stacking separate indicators, the HMA length parameter drives both the trend engine and the pivot detection, creating a unified analytical framework where signals and structure are inherently synchronized.
Significant Changes from the Original ThinkScript
This indicator was originally developed as a ThinkScript study for the ThinkorSwim platform (HMA-Kahlman concept by capissimo, ported by bvaikunth; Trendlines Module by Joris Duyck). The Pine Script v6 conversion introduces substantial enhancements beyond a straight port:
Visual & UX Upgrades
•Professional BUY/SELL signal labels: Replaced the original single-character “B”/“S” bubbles with stacked directional labels (▲/BUY, SELL/▼) anchored at bar highs and lows for instant visual recognition.
•Fully customizable signal colors: Four new color inputs (Buy background, Buy text, Sell background, Sell text) give complete control over signal appearance. The original had hardcoded white labels.
•Live price balloon captions: HMA-Kahlman A and B lines each display a real-time balloon label in the expansion area showing the current value formatted with dollar sign and comma-separated thousands (e.g., $24,674.25). The original had no price readout.
•Extension bridge lines: A one-bar extension line projects each HMA line into the future so the plotted line seamlessly connects to its balloon label pointer—a polished visual touch absent from the original.
•Z-order signal priority: BUY/SELL labels render on top of all other plot elements (cloud, trendlines, candles) using explicit_plot_zorder, ensuring signals are always visible regardless of chart density.
•Adjustable label sizing: Five size presets (Tiny through Huge) accommodate different screen sizes and visual preferences. The original offered no size control.
Technical & Structural Improvements
•Pine Script v6 native architecture: Complete rewrite using Pine’s built-in ta.pivothigh()/ta.pivotlow() functions instead of ThinkScript’s manual fold-loop pivot detection—more efficient and maintainable.
•Global-scope ta.highest/ta.lowest: Extension clipping boundary calculations moved to global scope for Pine Script consistency compliance (eliminates the “extract from this scope” warning).
•Full color customization: Resistance, support, extension, and signal colors are all user-configurable inputs. The original used hardcoded colors throughout.
•Configurable trendline extensions: Extension length (bars), upper/lower clipping boundaries (%), and visibility toggles are all exposed as inputs. The original had fixed 20-bar extensions with 5% limits and no toggles.
•Built-in alert conditions: Two alertconditions (Buy Signal, Sell Signal) enable push notifications, email, or webhook triggers on crossovers—functionality the ThinkScript version did not include.
•Organized input groups with tooltips: All inputs are grouped into logical sections (HMA-Kahlman Trend, Trendlines) with descriptive tooltips explaining each parameter. The original had flat, unlabeled inputs.
•Optimized opacity defaults: HMA lines default to 90% opacity and the trend cloud to 30% opacity, providing clear visual hierarchy without obscuring price action.
How to Use This Indicator
Adding to Your Chart
1.Open any chart on TradingView (works on all markets and timeframes).
2.Click Indicators and search for “HMA-Kahlman Trend & Trendlines.”
3.Add to chart. The indicator overlays directly on your candlestick/bar chart.
4.Open Settings (gear icon) to customize colors, lengths, and visibility toggles.
Reading the Trend
The indicator plots two HMA-Kahlman lines (A and B) with a shaded cloud between them. When Line B is above Line A, the trend is bullish and the cloud/lines turn aqua/green. When Line A is above Line B, the trend is bearish and everything shifts to red. The balloon labels in the expansion area show the real-time price of each line for quick reference.
Trading the Signals
•▲ BUY signal: Appears below the bar when Line B crosses above Line A (bullish crossover). This indicates momentum shifting to the upside.
•SELL ▼ signal: Appears above the bar when Line A crosses above Line B (bearish crossover). This indicates momentum shifting to the downside.
•Best practice: Use BUY/SELL signals in confluence with the auto-drawn trendlines. A BUY signal near a support trendline or extension carries higher conviction than a signal in open space. Similarly, a SELL signal near resistance reinforces the short bias.
Using the Trendlines
The indicator automatically detects the two most recent pivot highs and pivot lows, connects them with dashed trendlines (resistance in red, support in green by default), and projects dotted extension lines forward. These extensions act as dynamic support/resistance targets. Watch for price reactions at extension levels—bounces confirm the trendline, breaks suggest a structural shift.
Recommended Settings by Style
Trading Style HMA Length Kalman Gain Notes
Scalping (1–5 min) 8–14 0.7–1.0 Higher gain for faster response to micro moves
Day Trading (5–30 min) 14–22 0.5–0.7 Default settings optimized for this range
Swing Trading (1H–Daily) 22–50 0.3–0.5 Lower gain smooths out intraday noise
Setting Up Alerts
Right-click the indicator on your chart and select Add Alert. Two conditions are available: HMA-Kahlman Buy Signal and HMA-Kahlman Sell Signal. Configure for push notifications, email, webhook, or any combination to stay informed of crossover events in real time.
Disclaimer
This indicator is a technical analysis tool for educational and informational purposes. It does not constitute financial advice. No indicator guarantees future results. Always use proper risk management and combine signals with your own analysis and trading plan before entering any trade.
Credits
Original HMA-Kahlman Trend concept by capissimo, ThinkScript port by @bvaikunth. Trendlines Module by Joris Duyck. Pine Script v6 conversion, enhancements, and professional visual upgrades by NPR21.
Pine Script™ v6 | Overlay Indicator
by NPR21
Publication Description
A professional-grade trend identification and dynamic trendline indicator that combines two powerful analytical modules into a single overlay. The HMA-Kahlman Trend Module applies an optional Kalman filter to the Hull Moving Average for ultra-smooth, low-lag trend detection. The Trendlines Module auto-detects pivot highs and lows, draws connecting support/resistance trendlines, and projects dashed extension lines into the future. Together, they deliver real-time trend direction, precise BUY/SELL crossover signals, and automatically drawn structural trendlines—all from one indicator.
Built for any liquid market—futures, forex, stocks, crypto, and commodities. Works on all timeframes from 1-minute scalping charts to daily swing setups.
What Makes This Indicator Unique
Most trend indicators force you to choose between responsiveness and smoothness. This indicator eliminates that tradeoff by layering a Kalman filter on top of the Hull Moving Average—a combination rarely seen in Pine Script. The Kalman filter is an adaptive smoothing algorithm originally developed for aerospace navigation that dynamically adjusts its output based on incoming price data, removing noise without introducing the lag typical of traditional moving averages.
Key Differentiators
•Dual-engine trend detection: Standard HMA (Line A) and a triple-weighted HMA3 variant (Line B) run simultaneously. Their crossovers generate high-confidence directional signals because each line processes price through a fundamentally different weighting scheme.
•Kalman-filtered smoothing: The optional Kalman filter with adjustable gain lets you dial in exactly how much noise reduction you want—from aggressive scalping responsiveness (high gain) to smooth swing-trade clarity (low gain).
•Auto-drawn structural trendlines: The Trendlines Module detects pivot highs and lows, connects the two most recent pivots with dashed resistance/support lines, and projects extension lines forward—giving you dynamic S/R levels without any manual drawing.
•Integrated signal + structure: Unlike stacking separate indicators, the HMA length parameter drives both the trend engine and the pivot detection, creating a unified analytical framework where signals and structure are inherently synchronized.
Significant Changes from the Original ThinkScript
This indicator was originally developed as a ThinkScript study for the ThinkorSwim platform (HMA-Kahlman concept by capissimo, ported by bvaikunth; Trendlines Module by Joris Duyck). The Pine Script v6 conversion introduces substantial enhancements beyond a straight port:
Visual & UX Upgrades
•Professional BUY/SELL signal labels: Replaced the original single-character “B”/“S” bubbles with stacked directional labels (▲/BUY, SELL/▼) anchored at bar highs and lows for instant visual recognition.
•Fully customizable signal colors: Four new color inputs (Buy background, Buy text, Sell background, Sell text) give complete control over signal appearance. The original had hardcoded white labels.
•Live price balloon captions: HMA-Kahlman A and B lines each display a real-time balloon label in the expansion area showing the current value formatted with dollar sign and comma-separated thousands (e.g., $24,674.25). The original had no price readout.
•Extension bridge lines: A one-bar extension line projects each HMA line into the future so the plotted line seamlessly connects to its balloon label pointer—a polished visual touch absent from the original.
•Z-order signal priority: BUY/SELL labels render on top of all other plot elements (cloud, trendlines, candles) using explicit_plot_zorder, ensuring signals are always visible regardless of chart density.
•Adjustable label sizing: Five size presets (Tiny through Huge) accommodate different screen sizes and visual preferences. The original offered no size control.
Technical & Structural Improvements
•Pine Script v6 native architecture: Complete rewrite using Pine’s built-in ta.pivothigh()/ta.pivotlow() functions instead of ThinkScript’s manual fold-loop pivot detection—more efficient and maintainable.
•Global-scope ta.highest/ta.lowest: Extension clipping boundary calculations moved to global scope for Pine Script consistency compliance (eliminates the “extract from this scope” warning).
•Full color customization: Resistance, support, extension, and signal colors are all user-configurable inputs. The original used hardcoded colors throughout.
•Configurable trendline extensions: Extension length (bars), upper/lower clipping boundaries (%), and visibility toggles are all exposed as inputs. The original had fixed 20-bar extensions with 5% limits and no toggles.
•Built-in alert conditions: Two alertconditions (Buy Signal, Sell Signal) enable push notifications, email, or webhook triggers on crossovers—functionality the ThinkScript version did not include.
•Organized input groups with tooltips: All inputs are grouped into logical sections (HMA-Kahlman Trend, Trendlines) with descriptive tooltips explaining each parameter. The original had flat, unlabeled inputs.
•Optimized opacity defaults: HMA lines default to 90% opacity and the trend cloud to 30% opacity, providing clear visual hierarchy without obscuring price action.
How to Use This Indicator
Adding to Your Chart
1.Open any chart on TradingView (works on all markets and timeframes).
2.Click Indicators and search for “HMA-Kahlman Trend & Trendlines.”
3.Add to chart. The indicator overlays directly on your candlestick/bar chart.
4.Open Settings (gear icon) to customize colors, lengths, and visibility toggles.
Reading the Trend
The indicator plots two HMA-Kahlman lines (A and B) with a shaded cloud between them. When Line B is above Line A, the trend is bullish and the cloud/lines turn aqua/green. When Line A is above Line B, the trend is bearish and everything shifts to red. The balloon labels in the expansion area show the real-time price of each line for quick reference.
Trading the Signals
•▲ BUY signal: Appears below the bar when Line B crosses above Line A (bullish crossover). This indicates momentum shifting to the upside.
•SELL ▼ signal: Appears above the bar when Line A crosses above Line B (bearish crossover). This indicates momentum shifting to the downside.
•Best practice: Use BUY/SELL signals in confluence with the auto-drawn trendlines. A BUY signal near a support trendline or extension carries higher conviction than a signal in open space. Similarly, a SELL signal near resistance reinforces the short bias.
Using the Trendlines
The indicator automatically detects the two most recent pivot highs and pivot lows, connects them with dashed trendlines (resistance in red, support in green by default), and projects dotted extension lines forward. These extensions act as dynamic support/resistance targets. Watch for price reactions at extension levels—bounces confirm the trendline, breaks suggest a structural shift.
Recommended Settings by Style
Trading Style HMA Length Kalman Gain Notes
Scalping (1–5 min) 8–14 0.7–1.0 Higher gain for faster response to micro moves
Day Trading (5–30 min) 14–22 0.5–0.7 Default settings optimized for this range
Swing Trading (1H–Daily) 22–50 0.3–0.5 Lower gain smooths out intraday noise
Setting Up Alerts
Right-click the indicator on your chart and select Add Alert. Two conditions are available: HMA-Kahlman Buy Signal and HMA-Kahlman Sell Signal. Configure for push notifications, email, webhook, or any combination to stay informed of crossover events in real time.
Disclaimer
This indicator is a technical analysis tool for educational and informational purposes. It does not constitute financial advice. No indicator guarantees future results. Always use proper risk management and combine signals with your own analysis and trading plan before entering any trade.
Credits
Original HMA-Kahlman Trend concept by capissimo, ThinkScript port by @bvaikunth. Trendlines Module by Joris Duyck. Pine Script v6 conversion, enhancements, and professional visual upgrades by NPR21.
오픈 소스 스크립트
트레이딩뷰의 진정한 정신에 따라, 이 스크립트의 작성자는 이를 오픈소스로 공개하여 트레이더들이 기능을 검토하고 검증할 수 있도록 했습니다. 작성자에게 찬사를 보냅니다! 이 코드는 무료로 사용할 수 있지만, 코드를 재게시하는 경우 하우스 룰이 적용된다는 점을 기억하세요.
NPR21 Premium Indicators | Access all tiers at whop.com/npr21 | DM me on TradingView for questions
면책사항
해당 정보와 게시물은 금융, 투자, 트레이딩 또는 기타 유형의 조언이나 권장 사항으로 간주되지 않으며, 트레이딩뷰에서 제공하거나 보증하는 것이 아닙니다. 자세한 내용은 이용 약관을 참조하세요.
오픈 소스 스크립트
트레이딩뷰의 진정한 정신에 따라, 이 스크립트의 작성자는 이를 오픈소스로 공개하여 트레이더들이 기능을 검토하고 검증할 수 있도록 했습니다. 작성자에게 찬사를 보냅니다! 이 코드는 무료로 사용할 수 있지만, 코드를 재게시하는 경우 하우스 룰이 적용된다는 점을 기억하세요.
NPR21 Premium Indicators | Access all tiers at whop.com/npr21 | DM me on TradingView for questions
면책사항
해당 정보와 게시물은 금융, 투자, 트레이딩 또는 기타 유형의 조언이나 권장 사항으로 간주되지 않으며, 트레이딩뷰에서 제공하거나 보증하는 것이 아닙니다. 자세한 내용은 이용 약관을 참조하세요.