Strategy · Pine Script v6 · On the chart

Doc01 MACD Zero Pullback EMA20 - Project Adapted

by Snappni

This strategy trades long only on the price chart.

View on GitHub

GitHub stars1on the repository
Pine versionv6current
Lines of code47
Settings10inputs
LicenceMIT
Last update4 months ago6 Jun 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 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

47 lines of Pine Script v6 from apps/server/src/pine-corpus/strategy-collection-adapted/01_MACD零轴回踩EMA20_项目适配版.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.

01_MACD零轴回踩EMA20_项目适配版.pine
//@version=6
strategy("Doc01 MACD Zero Pullback EMA20 - Project Adapted", overlay=true, pyramiding=0, initial_capital=10000)

// Source: user-provided strategy collection - strategy 1
// Logic summary:
// 1. Trade long only when price pulls back near EMA20 and then closes back above it.
// 2. MACD must hold above the zero axis.
// 3. Volume should contract during the pullback.
// 4. Avoid obvious high-ADX one-way extension risk.
// 5. Exit when EMA20 support fails, ATR stop/target is hit, or momentum deteriorates.
// Compile confidence: 93/100. Profit confidence: 28/100.

emaLen = input.int(20, "EMA20 length", minval=1)
trendLen = input.int(55, "Trend EMA length", minval=2)
pullbackPct = input.float(0.35, "EMA pullback tolerance %", minval=0.01, step=0.05)
volLen = input.int(20, "Volume average length", minval=2)
volContract = input.float(0.95, "Volume contraction ratio", minval=0.1, step=0.05)
adxLen = input.int(14, "ADX length", minval=2)
maxAdx = input.float(45.0, "Max ADX before no-trade", minval=5.0, step=0.5)
atrLen = input.int(14, "ATR length", minval=1)
stopAtr = input.float(1.8, "Stop ATR", minval=0.1, step=0.1)
targetAtr = input.float(3.0, "Target ATR", minval=0.1, step=0.1)

ema20 = ta.ema(close, emaLen)
emaTrend = ta.ema(close, trendLen)
[macdLine, macdSignal, macdHist] = ta.macd(close, 12, 26, 9)
[pdi, mdi, adx] = ta.dmi(adxLen, adxLen)
atr = ta.atr(atrLen)
volBase = ta.sma(volume, volLen)

trendUp = close > emaTrend and ema20 > emaTrend
nearEma = low <= ema20 * (1 + pullbackPct / 100.0) and close >= ema20
macdHoldsZero = macdLine > 0 and macdSignal > 0 and macdHist >= macdHist[1]
volumeShrinks = volume <= volBase * volContract
stableMarket = adx <= maxAdx

longSignal = strategy.position_size == 0 and trendUp and nearEma and macdHoldsZero and volumeShrinks and stableMarket

if longSignal
    strategy.entry("Long", strategy.long)

if strategy.position_size > 0
    strategy.exit("Long Risk", "Long", stop=strategy.position_avg_price - atr * stopAtr, limit=strategy.position_avg_price + atr * targetAtr)

exitWeak = strategy.position_size > 0 and close < ema20 and macdLine < macdSignal
if exitWeak
    strategy.close("Long")

Overview

Doc01 MACD Zero Pullback EMA20 - Project Adapted enters when price pulls back near the EMA20 and closes back above it, while the MACD line and signal stay above zero and the histogram is not falling. A longer trend EMA must sit below price and the EMA20, volume must contract versus its average, and ADX must stay under a maximum. It exits on an ATR stop or target, or when close falls below the EMA20 while the MACD line is below its signal. It does not add to an open long.

Details

Published by

Snappni on GitHub

Type

Strategy, Pine Script v6

Draws

On the price chart

Category

Trend, Oscillators & momentum, Moving averages, Volume

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.

Settings

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

SettingTypeDefaultVariable
EMA20 lengthint20emaLen
Trend EMA lengthint55trendLen
EMA pullback tolerance %float0.35pullbackPct
Volume average lengthint20volLen
Volume contraction ratiofloat0.95volContract
ADX lengthint14adxLen
Max ADX before no-tradefloat45.0maxAdx
ATR lengthint14atrLen
Stop ATRfloat1.8stopAtr
Target ATRfloat3.0targetAtr
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

Altered OBV On MACD

by hasnocool
106 stars

This strategy calculates and plots 9, 21, 50, 90, and 200-period Simple Moving Averages on the main price chart. It constructs a modified On-Balance Volume (OBV) metric and calculates a MACD oscillator based on this custom volume series rather than price. Long

Strategy v5 Moving averagesVolume
Updated 2 years ago · GPL-3.0 GitHub repository of Altered OBV On MACD
12 stars

This strategy enters long when a fast EMA crosses above a slow EMA and RSI, ADX, and volume all clear their thresholds. It sizes the order from a percentage of equity and an ATR stop distance, then sets a partial profit target at a multiple of that risk. After

Strategy v5 TrendMoving averages
Updated 4 months ago · None stated GitHub repository of BTC 4H Institutional Trend

Combined Strategy

by Dropio12
7 stars

This strategy plots buy and sell markers on the price chart by combining a fast and slow ALMA crossover with a simple close-to-close momentum check. A long marker appears when the fast ALMA crosses above the slow ALMA and momentum is positive. A short marker a

Strategy v5 TrendOscillators & momentum
Updated 2 years ago · None stated GitHub repository of Combined Strategy

Antigravity Superstar

by eltonaguiar
4 stars

This strategy draws on the price chart and combines a triple EMA stack, a volume spike with a minimum price move, and a MACD line-signal crossover. It enters long or short only when at least the chosen number of those three signals agree, with an optional RSI

Strategy v6 TrendMoving averages
Updated today · None stated GitHub repository of Antigravity Superstar

Golden Strategy

by AliAhmadi-Software
3 stars

The Golden Strategy is a Pine Script v6 strategy that overlays EMA and SMA on the price chart to detect crossovers for trend direction. It adds MACD for momentum confirmation and RSI to identify overbought and oversold conditions. Volume average filters out lo

Strategy v6 TrendOscillators & momentum
Updated 1 year ago · None stated GitHub repository of Golden Strategy
2 stars

This strategy is written for Bitcoin and draws on the price chart. It combines moving averages, an SSL channel, ADX, RSI, stochastic, and a volume oscillator with high-volume thresholds to generate buy and sell signals. Users can limit testing to a date range

Strategy v5 TrendOscillators & momentum
Updated 1 year ago · None stated GitHub repository of TLC_STRATEGY_EMARSIADX for BTC

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