OPEN-SOURCE SCRIPT
Aggiornato

LineReg Candles with Hma filter

1 696
Overview
Purpose:
The indicator creates “LinReg Candles” by recalculating OHLC values using linear regression (to smooth out noise) and overlays additional features such as a customizable signal line and an HMA (Hull Moving Average) filter for trend detection. It also plots buy/sell signals and supports alerts.

Customization:
Users can adjust settings for signal smoothing (choosing SMA, EMA, or WMA), HMA periods (preset for Scalping/Intraday or custom values), linear regression length, colors, display options, and alert messages. Inputs are organized into groups for clarity.

Input Definitions
Signal Settings:

signal_length and smoothingType define the period and method used to smooth the close price, creating a signal line.
HMA Filter Settings:

A dropdown (t_type) lets you choose between Scalping, Intraday, or Custom. Based on this, three HMA periods (hma1, hma2, hma3) are set either to fixed values or user-defined custom inputs.
LinReg Settings:

Users can toggle linear regression for OHLC values (lin_reg) and set its period (linreg_length) to reduce price noise.
Color and Display Settings:

These control the colors for buy/sell candles, default bullish/bearish candles, markers, and background highlighting. Display toggles decide whether to show the background, signal line, HMA filter, and the recalculated candles.
Alert and Plot Customization:

Alerts can be enabled with custom messages. Additionally, line width and transparency for the plotted signal and HMA lines are adjustable.

Function Definitions
calcOHLC Function:

Computes OHLC values using linear regression if enabled. Otherwise, it returns the raw price values. This helps in reducing noise.
calcSignalLine Function:

Applies the chosen moving average (SMA, EMA, or WMA) to smooth the recalculated close values and generate a signal line.
getBaseCandleColor Function:

Determines the candle’s base color. It assigns buy/sell colors if specific crossover conditions are met; if not, it defaults to bullish (green) or bearish (red) based on the open/close relationship.

HMA Filter Calculations
HMA Computation:
The script calculates three HMAs (ma1, ma2, ma3) for different periods.

Trend Determination:
It sets a bullish condition (bcn) when ma3 is lower than both ma1 and ma2 with ma1 above ma2. Conversely, a bearish condition (scn) is set when ma3 is higher and the order of the HMAs indicates a downtrend.

Color Coding:
The HMA filter line color changes dynamically (green for bullish, red for bearish) based on these conditions.

Main Calculations
LinReg Candles:

Using the calcOHLC function, the script calculates the new open, high, low, and close values that reduce price noise.
Signal Line:

The signal line is computed on the basis of the smoothed close values using the selected moving average.
Buy/Sell Conditions:

Initial conditions are determined by checking if the recalculated close price crosses over (buy) or under (sell) the signal line.

The base candle color is then adjusted: if the HMA filter confirms the trend (bullish for buy or bearish for sell), the respective buy/sell colors are enforced.

A change in candle color compared to the previous bar triggers a buy or sell signal.

Plotting and Alerts
Visual Elements:

Background: Highlights the chart with a custom color when buy or sell conditions are met.
HMA Filter Line: Plotted (if enabled) with the dynamic color determined earlier.
Candles: The recalculated LinReg candles are drawn with colors based on the combined conditions.
Signal Line: Plotted over the candles with adjustable transparency and width.
Markers: Buy and sell markers are added to visually indicate signal points on the chart.
Alerts:

Alert conditions are set to trigger with predefined messages when a buy or sell signal is generated.

Modularity & Flexibility:
The code is structured with modular functions and clear grouping of inputs, making it highly customizable and user-friendly for open-source TradingView users.

Important how to track the real price on chart:

Locate the Chart Type Menu:

At the top of your TradingView chart, you’ll see a button showing the current chart type (likely a candlestick icon).
Select “Line” from the Dropdown:

Click that button and choose “Line” in the dropdown menu. This changes the main chart to a line chart of the real price.

Screenshots:

istantanea
istantanea
istantanea

Note di rilascio
What’s New in This Update?
Here are the key improvements and additions I’ve made in this update, along with explanations of how they improve buy/sell signals and overall functionality:
Adaptive Parameter Calculations
What I Did Extra: The updated indicator now automatically adjusts its settings (like the Linear Regression length) based on market conditions. It uses a volatility-based system (calculated with the Average True Range, ATR) and AI optimization to tweak parameters dynamically.

Why It’s Better:
More Accurate Signals: Unlike the original’s fixed settings, this adaptability reduces false signals by using shorter periods in volatile markets for faster responses and longer periods in stable markets for smoother signals.

Stays Relevant: Signals match the current market behavior, making buy/sell decisions more reliable.

How It Helps You: You don’t need to guess the right settings— the indicator tunes itself to give you the best signals possible.

Advanced Signal Generation
What I Did Extra: I’ve upgraded the signal logic with multiple confirmation layers:
Slope direction check to confirm the trend.

Volume confirmation to prioritize high-volume moves.

An anti-whipsaw filter to cut noise in choppy markets.

Optional bar confirmation to ensure signals hold on the next bar.

Why It’s Better:
Fewer False Signals: These filters weed out weak signals, so you’re not misled into bad trades. The original relied on simple crossovers, which could fail in volatile conditions.

Customizable: You can pick your signal line (SMA, EMA, or VWMA) and turn confirmation features on or off to fit your trading style.

How It Helps You: You get cleaner, more trustworthy buy/sell signals, especially in tricky markets.

Divergence Detection
What I Did Extra: I added a feature to detect bullish and bearish divergences between price and the Linear Regression slope. It uses a dynamic lookback period and smoothed slope for accuracy.

Why It’s Better:
Spots Reversals Early: Divergences often signal trend changes before they happen, something the original couldn’t do.

More Precise: The adaptive lookback reduces false positives, giving you clearer reversal warnings.

How It Helps You: You can catch potential trend shifts (e.g., a bullish divergence for a buy) that the original missed, improving your timing.

Improved Visualization
What I Did Extra: I added new visual tools:
Background highlights during signals or divergences.

Optional slope plotting with color coding (green for up, red for down).

Gradient coloring on candles/markers to show signal strength.

Why It’s Better:
Easier to Read: Stronger signals get bolder colors, so you can quickly spot high-confidence trades.

Customizable: Toggle visuals or change colors to suit your preferences.

How It Helps You: You can interpret signals at a glance and focus on the strongest opportunities.

Alerts
What I Did Extra: I built in a customizable alert system for buy/sell signals and divergences, with a debouncing feature to avoid spamming you with notifications.

Why It’s Better:
Stay on Top of Trades: Get real-time alerts so you never miss a key moment.

Less Noise: Alerts only trigger when it matters, keeping your focus sharp.

How It Helps You: Set it up your way and trade with confidence, knowing you’ll be notified instantly.

Additional Features
What I Did Extra: I included some bonus enhancements:
Custom moving averages (SMA, EMA, VWMA) for the signal line.

Hidden plots showing volatility and adaptive lengths for advanced users.

Why It’s Better:
More Flexibility: Choose the moving average that works best for you.

Insightful: See how the indicator adapts, helping you fine-tune it if needed.

How It Helps You: Tailor the indicator further and understand its inner workings for better results.

Why This Update is Better for Buy/Sell Signals and Everything Else
More Accurate Buy/Sell Signals: Adaptive parameters, layered confirmation, and divergence detection cut down false signals and make every buy/sell call more reliable. The original’s simpler approach struggled in volatile or choppy markets, but this version thrives.

Better Trend and Reversal Insights: With divergence detection and slope visuals, you can track trends and spot reversals— a huge step up from the original’s basic trend-following.

Enhanced Usability: Custom visuals, alerts, and structured inputs make it easier to use and fit into your trading routine.

Future-Ready: AI optimization keeps the indicator sharp as markets evolve, no manual tweaking required.

How to Use These New Features
For Better Buy/Sell Signals:
Turn on volatility_adaptation for market-tuned settings.

Use confirm_signals and anti_whipsaw to filter noise.

Pick your signal line (e.g., sma_signal) and tweak with use_volume_weight.

For Divergence Detection:
Enable divergence_detection and watch for markers (⋓ for bullish, ⋒ for bearish).

For Visualization:
Use show_bg for highlights and use_gradient for strength-based colors.

For Alerts:
Enable alert_enabled and set alert_rearm_bars to control timing.

This update makes the indicator a more powerful and user-friendly tool. You’ll get sharper signals, better trend insights, and a smoother experience. Let me know if you need help setting it up or have questions!

Note di rilascio
Added:
COMPREHENSIVE EXPLANATION & SETUP GUIDE Inside code small bug fix.

Declinazione di responsabilità

Le informazioni ed i contenuti pubblicati non costituiscono in alcun modo una sollecitazione ad investire o ad operare nei mercati finanziari. Non sono inoltre fornite o supportate da TradingView. Maggiori dettagli nelle Condizioni d'uso.