//@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.
The inputs you can change from the gear icon on the chart. Defaults are the author's.
Setting
Type
Default
Variable
EMA20 length
int
20
emaLen
Trend EMA length
int
55
trendLen
EMA pullback tolerance %
float
0.35
pullbackPct
Volume average length
int
20
volLen
Volume contraction ratio
float
0.95
volContract
ADX length
int
14
adxLen
Max ADX before no-trade
float
45.0
maxAdx
ATR length
int
14
atrLen
Stop ATR
float
1.8
stopAtr
Target ATR
float
3.0
targetAtr
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.
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
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
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
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
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
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