Indicator · Pine Script v6 · On the chart

Complete Trendline + MACD Divergence System

by MuhammadHassanC

The Complete Trendline + MACD Divergence System identifies swing high and low pivots to detect MACD divergences and plot support or resistance trendlines directly on the price chart.

View on GitHub

Repaints

GitHub stars1on the repository
Pine versionv6current
Lines of code280
Settings17inputs
LicenceNone stated
Last update1 year ago28 Sep 2025

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above. It reads the file straight from GitHub.
  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

The code stays on GitHub. The author has not published this script under an open licence, so ForexR does not show its code. Copy script reads the file straight from GitHub into your clipboard, so you can still try it on your own chart. Ask the author before reusing the code anywhere else.

Overview

Complete Trendline + MACD Divergence System calculates MACD values, tracks price extremes over customizable lookback periods, and displays visual divergence markers alongside suggested stop-loss reference levels. Key inputs allow users to adjust MACD parameters, swing detection sensitivity, lookback distances, and risk buffer percentages. Divergence signals and trendlines appear retrospectively once pivot points are confirmed after the designated swing period.

Details

Published by

MuhammadHassanC on GitHub

Draws

On the price chart

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

  • Signals can change on the live bar or after it closes (repainting)

Settings

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

SettingTypeDefaultVariable
MACD Fast Lengthint12macdFastLength
MACD Slow Lengthint26macdSlowLength
MACD Signal Lengthint9macdSignalLength
Swing Detection Periodint5swingPeriod
Trendline Extension Lengthint50trendlineLength
Divergence Lookback Periodint40divergenceLookback
Show DivergencesbooltrueshowDivergences
Divergence Line Widthint2divergenceLineWidth
Stop Loss Buffer %float0.2stopLossBuffer
Stop Loss Lookback Barsint10stopLossLookback
Show TrendlinesbooltrueshowTrendlines
Show MACD PanelbooltrueshowMacdPanel
Show all 17 settings
SettingTypeDefaultVariable
Show Stop Loss LevelsbooltrueshowStopLoss
Bullish Divergence Colorcolorcolor.new(color.green, 0)bullDivColor
Bearish Divergence Colorcolorcolor.new(color.red, 0)bearDivColor
Resistance Trendline Colorcolorcolor.new(color.red, 30)trendlineResColor
Support Trendline Colorcolorcolor.new(color.blue, 30)trendlineSupColor
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

2 stars

This indicator plots a momentum-based ZigZag on the price chart from a QQE calculation driven by a multi-timeframe RSI. It marks bullish and bearish ZigZag segments, optional divergence and convergence between price and that RSI, and an optional Supertrend lin

Indicator v5 Oscillators & momentumDivergence
Updated 3 years ago · None stated GitHub repository of Modified Momentum QQE-ZigZag
1 stars

A large all-in-one overlay built for the 30-minute chart that bundles many tools in one script. It includes the Williams Alligator and fractal reversal setups, divergence detection, RSI, an ATR-ADX trend gauge, EMA crosses on 30-minute, 4-hour and daily frames

Indicator v5 TrendOscillators & momentum Repaints
Updated 7 months ago · None stated GitHub repository of ARPS Ultimate Trading Solution (A)

The indicator scores whether a counter-move against the dominant structure is maturing and whether price has started turning back. It plots a composite score in a separate pane from weighted context, correction maturity, and exhaustion, scaled by trigger and a

Indicator v6 TrendOscillators & momentum
Updated 4 weeks ago · MIT GitHub repository of Directional Probability Engine v2 [WavesUnchained]
114 stars

This indicator calculates key support and resistance levels by analyzing the first and second momentum derivatives of a Double Exponential Moving Average (DEMA). When the second derivative (momentum of momentum) crosses zero, it identifies local turning points

Indicator v4 Support & resistanceOscillators & momentum
Updated 2 years ago · None stated GitHub repository of Support and Resistance Levels

More Oscillators & momentum scripts

Related on ForexR

Trade Your Charts With a Regulated Broker

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

Compare brokers