Hi all, I don’t manage myself or with the IA to modify the original PVO VO indicator to match in color and time the Elder Impulse MACD that I found couple of years back somewhere here. This is what the IA provide that is not working, I have error message when trying to save with something in line with ending with “Return”.
//@version=13
// PVO with Elder Impulse Coloring & Divergence
DefParam DrawOnLastBarOnly = True
// Parameters (Fibonacci-based)
ShortPeriod = 13
LongPeriod = 34
SignalPeriod = 5
TrendPeriod = 13
// Initialize variables for divergence detection (CRITICAL in PRT)
hi = 0
lo = 100000
hico = 0
lowco = 100000
sto1b = 0
sto2b = 0
sto1h = 100000
sto2h = 100000
p1b = 0
p2b = 0
p3b = 0
p4b = 0
p1h = 100000
p2h = 100000
p3h = 100000
p4h = 100000
hico1 = 0
lowco1 = 100000
// Core PVO Calculation
EMAShort = ExponentialAverage[ShortPeriod](Volume)
EMALong = ExponentialAverage[LongPeriod](Volume)
PVO = ((EMAShort – EMALong) / EMALong) * 100
SignalLine = ExponentialAverage[SignalPeriod](PVO)
Histogram = PVO – SignalLine
// Elder Impulse Coloring Logic
TrendEMA = ExponentialAverage[TrendPeriod](Close)
ImpulseUp = 0
ImpulseDown = 0
ImpulseNeutral = 0
IF TrendEMA > TrendEMA[1] AND Histogram > Histogram[1] THEN
ImpulseUp = Histogram
ELSIF TrendEMA < TrendEMA[1] AND Histogram < Histogram[1] THEN
ImpulseDown = Histogram
ELSE
ImpulseNeutral = Histogram
ENDIF
// ZeroLag Volume Divergence Detection
EMAShort1 = ExponentialAverage[ShortPeriod](Volume)
EMAShort2 = ExponentialAverage[ShortPeriod](EMAShort1)
DiffShort = EMAShort1 – EMAShort2
ZeroLagShort = EMAShort1 + DiffShort
EMALong1 = ExponentialAverage[LongPeriod](Volume)
EMALong2 = ExponentialAverage[LongPeriod](EMALong1)
DiffLong = EMALong1 – EMALong2
ZeroLagLong = EMALong1 + DiffLong
ZeroLagPVO = ZeroLagShort – ZeroLagLong
SignalZL1 = ExponentialAverage[SignalPeriod](ZeroLagPVO)
SignalZL2 = ExponentialAverage[SignalPeriod](SignalZL1)
DiffZL = SignalZL1 – SignalZL2
SignalZL = SignalZL1 + DiffZL
// Divergence Logic
x = ZeroLagPVO
y = SignalZL
BullDiv = 0
BearDiv = 0
// BEARISH DIVERGENCES PVO (as in your working MACD code)
hi = max(hi, x)
hico = max(hico, max(High, High[1]))
IF x CROSSES UNDER y THEN
sto2b = sto1b
sto1b = hi
hi = 0
p3b = p1b
p2b = max(p1b, hico1)
p1b = max(Highest[3](High), hico)
IF p2b = p1b THEN
p2b = max(p3b, p4b)
ENDIF
hico = 0
hico1 = 0
ENDIF
IF x < y THEN
p4b = hico1
hico1 = max(hico1, High)
ENDIF
IF p1b > p2b AND sto1b < sto2b AND x CROSSES UNDER y AND x < x[1] THEN
BearDiv = Histogram
ENDIF
// BULLISH PVO DIVERGENCES
lo = min(lo, x)
lowco = min(lowco, min(Low, Low[1]))
IF x CROSSES OVER y THEN
sto2h = sto1h
sto1h = lo
lo = 100000
p3h = p1h
p2h = min(p1h, lowco1)
p1h = min(Lowest[3](Low), lowco)
IF p2h = p1h THEN
p2h = min(p3h, p4h)
ENDIF
lowco = 100000
lowco1 = 100000
ENDIF
IF x > y THEN
p4h = lowco1
lowco1 = min(lowco1, Low)
ENDIF
IF p1h < p2h AND sto1h > sto2h AND x CROSSES OVER y AND x > x[1] THEN
BullDiv = Histogram
ENDIF
// RETURN statement (MUST be the last line)
RETURN ImpulseUp COLOURED(0,255,0) AS “Impulse Up (Green)”,
ImpulseDown COLOURED(255,0,0) AS “Impulse Down (Red)”,
ImpulseNeutral COLOURED(128,128,128) AS “Impulse Neutral (Gray)”,
BullDiv COLOURED(0,180,0) AS “Bullish Divergence”,
BearDiv COLOURED(180,0,0) AS “Bearish Divergence”,
Histogram AS “PVO Histogram”,
0 AS “Zero Line”