Strategy · Pine Script v4 · Own pane

MACD + Divergences [Alorse]

by Alorse

This strategy plots a MACD line, signal line, and colored histogram in a separate pane.

View on GitHub

GitHub stars330on the repository
Pine versionv4older, still runs
Lines of code146
Settings26inputs
LicenceNone stated
Last update2 months ago25 Aug 2026

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 strategy, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart. The trades and results appear in the Strategy Tester tab; adjust the settings with the gear icon.

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

The fast and slow averages and the signal line can each use SMA or EMA. Optional markers show MACD and signal crosses. Pivot lookbacks scan the oscillator for regular and hidden bullish and bearish divergences, with a toggle for each type. Two EMAs compare a faster and slower trend. A take-profit factor and bars-back setting are present, but the supplied code ends before entry, exit, and stop rules are defined.

Details

Published by

Alorse on GitHub

Type

Strategy, Pine Script v4

Draws

Separate pane below the chart

Category

Oscillators & momentum, Divergence, Moving averages

Markets

Any symbol

Timeframes

Any timeframe

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

pinescriptpinescript-indicatorspinescript-strategiestrading-strategiestradingviewtradingview-alerttradingview-strategy

Settings

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

SettingTypeDefaultVariable
Sourcesourceclosesrc
Fast Lengthint12fast_length
Slow Lengthint26slow_length
Signal Smoothingint9signal_length
Oscillator MA TypestringEMAsma_source
Signal Line MA TypestringEMAsma_signal
MACD Line  color#2962FFcol_macd
Signal Line  color#FF6D00col_signal
Show Signals&MACD CrossbooltrueshowCross
Above   Growcolor#00796bcol_grow_above
Fallcolor#26a69acol_fall_above
Below Growcolor#ef5350col_grow_below
Show all 26 settings
SettingTypeDefaultVariable
Fallcolor#b71c1ccol_fall_below
Don't touch the zero line?booltruedonttouchzero
Pivot Lookback Rightint5lbR
Pivot Lookback Leftint5lbL
Max of Lookback Rangeint60rangeUpper
Min of Lookback Rangeint5rangeLower
Plot BullishbooltrueplotBull
Plot BearishbooltrueplotBear
Plot Hidden BullishboolfalseplotHiddenBull
Plot Hidden BearishboolfalseplotHiddenBear
EMA 1int150maA
EMA 2int600maB
Bars backint10barsBack
Take profit factorfloat1.5tpFactor
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

Awesome Oscillator - Eterna MCP

by EternaHybridExchange
9 stars

This strategy implements Bill Williams' Awesome Oscillator (AO) calculated as the difference between two simple moving averages of the median price. It generates long and short entries using three classic signal triggers: zero-line crossovers, twin peaks diver

Strategy v5 Oscillators & momentumMoving averages
Updated 7 months ago · MIT GitHub repository of Awesome Oscillator - Eterna MCP
24 stars

This overlay strategy combines a Cipher B WaveTrend oscillator with two optional moving averages on the price chart. It exposes WaveTrend channel and average lengths, overbought and oversold levels, buy, sell and gold dots, and regular or hidden divergence mar

Strategy v5 Oscillators & momentumMoving averages
Updated 4 years ago · MPL-2.0 GitHub repository of Cipher B + EMAs Strategy

Divergenced B004

by ruckard
13 stars

Divergenced B004 is a Pine Script strategy that plots on the price chart and looks for divergences in the Squeeze Momentum Indicator. It shorts when a green-section squeeze value falls while price rises, and longs when a red-section squeeze value rises while p

Strategy v5 DivergenceOscillators & momentum
Updated 1 year ago · None stated GitHub repository of Divergenced B004

This strategy executes long positions by combining a 200-period EMA trend filter, Stochastic RSI oversold crosses, and Williams Alligator retracements, supplemented by RSI divergence detection. It triggers long entries when the price trades above the 200 EMA w

Strategy v4 TrendOscillators & momentum
Updated 3 years ago · Apache-2.0 GitHub repository of 200 EMA + Alligator + Stochastic Long Strategy

MACD Crossover (tutorial)

by pineforge-4pass
193 stars

This strategy calculates the Moving Average Convergence Divergence indicator and plots the MACD line, signal line, and histogram in a separate pane. It enters long positions when the MACD line crosses above the signal line and enters short positions when it cr

Strategy v6 Oscillators & momentumMoving averages
Updated today · Apache-2.0 GitHub repository of MACD Crossover (tutorial)

8D Run

by hasnocool
106 stars

8D Run is a Pine Script momentum strategy inspired by Linda Bradford Raschke. It tracks consecutive price closes relative to a 5-period Simple Moving Average (SMA). When price remains above the SMA for 8 or more bars and then dips below it, the strategy enters

Strategy v5 Oscillators & momentumMoving averages
Updated 2 years ago · GPL-3.0 GitHub repository of 8D Run

More strategys

Trade Your Charts With a Regulated Broker

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

Compare brokers