OPEN-SOURCE SCRIPT

LineReg Candles with Hma filter

427
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:

snapshot
snapshot
snapshot

Wyłączenie odpowiedzialności

Informacje i publikacje przygotowane przez TradingView lub jego użytkowników, prezentowane na tej stronie, nie stanowią rekomendacji ani porad handlowych, inwestycyjnych i finansowych i nie powinny być w ten sposób traktowane ani wykorzystywane. Więcej informacji na ten temat znajdziesz w naszym Regulaminie.