Indicator · Pine Script v5 · On the chart

Daily Trend Filter

by agutinbaigo28

Calculates market regime conditions by combining RSI, MACD, and ADX/DMI indicators.

View on GitHub

GitHub stars147on the repository
Pine versionv5runs as is
Lines of code57
Settings8inputs
LicenceMIT
Last update6 weeks ago14 Sep 2026

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new indicator, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart, then adjust the settings with the gear icon next to its name.

Source Code

57 lines of Pine Script v5 from packages/sidekick/content/config/source/timeframe_4h.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.

timeframe_4h.pine
//@version=5
indicator("Daily Trend Filter", overlay=true)

plotcandle(open, high, low, close, 
     color=close > open ? color.new(color.green, 70) : color.new(color.red, 70),
     wickcolor=color.new(color.gray, 70),
     bordercolor=color.new(color.gray, 70))

// === INPUTS ===
rsi_len = input.int(14, "RSI Length", minval=2)
macd_fast = input.int(12, "MACD Fast", minval=1)
macd_slow = input.int(26, "MACD Slow", minval=1)
macd_signal = input.int(9, "MACD Signal", minval=1)
adx_len = input.int(14, "ADX Length", minval=1)
adx_threshold = input.int(25, "ADX Threshold", minval=10)

rsi_bull_threshold = input.int(50, "RSI Bull Threshold", minval=50, maxval=70)
rsi_bear_threshold = input.int(50, "RSI Bear Threshold", minval=30, maxval=50)

// === INDICATORS ===
rsi = ta.rsi(close, rsi_len)
[macd_line, signal_line, macd_hist] = ta.macd(close, macd_fast, macd_slow, macd_signal)
[di_plus, di_minus, adx] = ta.dmi(adx_len, adx_len)

// === TREND FILTER LOGIC ===
strong_trend = adx > adx_threshold

bull_regime = strong_trend and macd_hist > 0 and di_plus > di_minus and rsi > rsi_bull_threshold

bear_regime = strong_trend and macd_hist < 0 and di_minus > di_plus and rsi < rsi_bear_threshold

both_allowed = strong_trend and not bull_regime and not bear_regime
no_trades = not strong_trend

// === VISUALIZATION ===
line_color = bull_regime ? color.green : 
             bear_regime ? color.red : 
             both_allowed ? color.gray :
             color.orange

plot(close, "Active Signal", color=line_color, linewidth=6)

// === OUTPUTS FOR BOT ===
plot(bull_regime ? 1 : 0, "AllowLong", display=display.data_window)
plot(bear_regime ? 1 : 0, "AllowShort", display=display.data_window)
plot(both_allowed ? 1 : 0, "AllowBoth", display=display.data_window)
plot(no_trades ? 1 : 0, "NoTrades", display=display.data_window)
plot(rsi, "RSI", display=display.data_window)
plot(adx, "ADX", display=display.data_window)

// === DEBUG: INDICATOR DUMP ===
plot(macd_line, "d_MACDLine", display=display.data_window)
plot(signal_line, "d_SignalLine", display=display.data_window)
plot(macd_hist, "d_MACDHist", display=display.data_window)
plot(di_plus, "d_DIPlus", display=display.data_window)
plot(di_minus, "d_DIMinus", display=display.data_window)
plot(strong_trend ? 1 : 0, "d_StrongTrend", display=display.data_window)

Overview

Daily Trend Filter evaluates whether the market is in a strong bullish, strong bearish, neutral, or non-trending regime. The script plots a colored line overlaying the close price to reflect the current active trend state and outputs numerical boolean flags to the Data Window for integration with external automated trading bots. Settings allow users to customize indicator periods, ADX trend thresholds, and RSI regime boundaries.

Details

Published by

agutinbaigo28 on GitHub

Type

Indicator, Pine Script v5

Draws

On the price chart

Category

Trend, Oscillators & momentum, Moving averages

Markets

Any symbol

Timeframes

M15-H1, H4 and above

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Topics

agent-kitbacktestbacktest-kittradingtrading-backtesttrading-kit

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
RSI Lengthint14rsi_len
MACD Fastint12macd_fast
MACD Slowint26macd_slow
MACD Signalint9macd_signal
ADX Lengthint14adx_len
ADX Thresholdint25adx_threshold
RSI Bull Thresholdint50rsi_bull_threshold
RSI Bear Thresholdint50rsi_bear_threshold
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

948 stars

The Adaptive RSI Moving Average (ARSIMA) is an overlay indicator that dynamically adjusts its smoothing factor based on the Relative Strength Index (RSI). When the RSI moves toward extreme overbought or oversold conditions, the smoothing factor increases to ma

Indicator v4 Moving averagesOscillators & momentum
Updated 10 days ago · GPL-3.0 GitHub repository of Adaptive RSI Moving Average
218 stars

TradersPost Trading Checklist is an overlay indicator that evaluates a suite of popular technical conditions for long and short trade setups. It checks session-anchored VWAP, fast and slow EMA alignments and crosses, 200 SMA, RSI overbought or oversold conditi

Indicator v6 Screeners & dashboardsTrend
Updated 3 months ago · None stated GitHub repository of TradersPost Trading Checklist

AAPP

by capissimo
114 stars

This indicator plots an adaptive moving average or scaled RSI divergence line directly on the price chart. It calculates dual RSI series to measure momentum divergence, scales the values to the chart's price range, and constructs an adaptive average filtered b

Indicator v4 Moving averagesTrend
Updated 1 year ago · None stated GitHub repository of AAPP

Signal Strategy 15m

by tripolskypetr
72 stars

This indicator generates trend-following trade signals on the price chart by combining moving average crossovers with multi-factor filters. It triggers entry alerts when fast and slow EMAs cross in the direction of a baseline trend EMA, confirmed by non-extrem

Indicator v5 TrendMoving averages
Updated 3 days ago · MIT GitHub repository of Signal Strategy 15m
56 stars

Double Screened Decision is a multi-timeframe trend and momentum indicator overlaid directly on the price chart. It dynamically selects a higher timeframe based on the active chart resolution to evaluate higher-timeframe MACD, Bollinger Bands, RSI, and Stochas

Indicator v5 TrendMoving averages Repaints
Updated 4 months ago · None stated GitHub repository of Double Screened Decision

Trend Analysis

by dcaoyuan
55 stars

Trend Analysis plots a 20-period and a 50-period exponential moving average on the price chart. It marks bars whose close is above the faster average with a green square below the bar and marks other bars with a red square above the bar. It also calculates a 1

Indicator v6 TrendMoving averages
Updated 6 months ago · Apache-2.0 GitHub repository of Trend Analysis

More indicators

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers