pekipek

Pekipek's PPO Divergence BETA

5889 32 912
Beta divergence indicator, you can exchange the Price Percentage Oscillator ( PPO ) for any oscillator. You can play around with the look-back period if you want to use long term divergences.
WARNING:
Because its impossible to make the look-back period of the lowest/highest functions dynamic, the indicator can plot divergences sometimes at places where there are none, however in my experience this does not occur so much. Also it is impossible to plot isolated lines, so its hard to visually see which divergence(s) exactly is(are) being signaled. Once these features become possible I can really refine the indicator.
Remove from Favorite Scripts Add to Favorite Scripts
study(title = "Pekipek's PPO Divergence BETA", shorttitle = "PP's_PPO_DIV")
source = close
long_term_div = input(true, title="Use long term Divergences?")
div_lookback_period = input(55, minval=1, title="Lookback Period")
fastLength = input(12, minval=1), slowLength=input(26,minval=1)
signalLength=input(9,minval=1)
smoother = input(2,minval=1)
fastMA = ema(source, fastLength)
slowMA = ema(source, slowLength)
macd = fastMA - slowMA
macd2=(macd/slowMA)*100
d = sma(macd2, smoother) // smoothing PPO

bullishPrice = low 

priceMins = bullishPrice > bullishPrice[1] and bullishPrice[1] < bullishPrice[2] or 
            low[1] == low[2] and low[1] < low and low[1] < low[3] or
            low[1] == low[2] and low[1] == low[3] and low[1] < low and low[1] < low[4] or
            low[1] == low[2] and low[1] == low[3] and low[1] and low[1] == low[4] and low[1] < low and low[1] < low[5] // this line identifies bottoms and plateaus in the price
oscMins= d > d[1] and d[1] < d[2] // this line identifies bottoms in the PPO


BottomPointsInPPO = oscMins

bearishPrice = high
priceMax = bearishPrice < bearishPrice[1] and bearishPrice[1] > bearishPrice[2] or 
            high[1] == high[2] and high[1] > high and high[1] > high[3] or
            high[1] == high[2] and high[1] == high[3] and high[1] > high and high[1] > high[4] or
            high[1] == high[2] and high[1] == high[3] and high[1] and high[1] == high[4] and high[1] > high and high[1] > high[5]  // this line identifies tops in the price
oscMax = d < d[1] and d[1] > d[2]   // this line identifies tops in the PPO

TopPointsInPPO = oscMax



currenttrough4=valuewhen (oscMins, d[1], 0) // identifies the value of PPO at the most recent BOTTOM in the PPO
lasttrough4=valuewhen (oscMins, d[1], 1) // NOT USED identifies the value of PPO at the second most recent BOTTOM in the PPO
currenttrough5=valuewhen (oscMax, d[1], 0) // identifies the value of PPO at the most recent TOP in the PPO
lasttrough5=valuewhen (oscMax, d[1], 1) // NOT USED identifies the value of PPO at the second most recent TOP in the PPO

currenttrough6=valuewhen (priceMins, low[1], 0) // this line identifies the low (price) at the most recent bottom in the Price
lasttrough6=valuewhen (priceMins, low[1], 1) // NOT USED this line identifies the low (price) at the second most recent bottom in the Price
currenttrough7=valuewhen (priceMax, high[1], 0) // this line identifies the high (price) at the most recent top in the Price
lasttrough7=valuewhen (priceMax, high[1], 1) // NOT USED this line identifies the high (price) at the second most recent top in the Price


delayedlow = priceMins and barssince(oscMins) < 3 ? low[1] : na
delayedhigh = priceMax and barssince(oscMax) < 3 ? high[1] : na

// only take tops/bottoms in price when tops/bottoms are less than 5 bars away
filter = barssince(priceMins) < 5 ? lowest(currenttrough6, 4) : na
filter2 = barssince(priceMax) < 5 ? highest(currenttrough7, 4) : na

//delayedbottom/top when oscillator bottom/top is earlier than price bottom/top
y11 = valuewhen(oscMins, delayedlow, 0)
y12 = valuewhen(oscMax, delayedhigh, 0)

// only take tops/bottoms in price when tops/bottoms are less than 5 bars away, since 2nd most recent top/bottom in osc
y2=valuewhen(oscMax, filter2, 1) // identifies the highest high in the tops of price with 5 bar lookback period SINCE the SECOND most recent top in PPO
y6=valuewhen(oscMins, filter, 1) // identifies the lowest low in the bottoms of price with 5 bar lookback period SINCE the SECOND most recent bottom in PPO

long_term_bull_filt = valuewhen(priceMins, lowest(div_lookback_period), 1)
long_term_bear_filt = valuewhen(priceMax, highest(div_lookback_period), 1)

y3=valuewhen(oscMax, currenttrough5, 0) // identifies the value of PPO in the most recent top of PPO 
y4=valuewhen(oscMax, currenttrough5, 1) // identifies the value of PPO in the second most recent top of PPO 




y7=valuewhen(oscMins, currenttrough4, 0) // identifies the value of PPO in the most recent bottom of PPO
y8=valuewhen(oscMins, currenttrough4, 1) // identifies the value of PPO in the SECOND most recent bottom of PPO

y9=valuewhen(oscMins, currenttrough6, 0)
y10=valuewhen(oscMax, currenttrough7, 0)

bulldiv= BottomPointsInPPO ? d[1] : na // plots dots at bottoms in the PPO
beardiv= TopPointsInPPO ? d[1]: na // plots dots at tops in the PPO


i = currenttrough5 < highest(d, div_lookback_period) // long term bearish oscilator divergence
i2 = y10 > long_term_bear_filt // long term bearish top divergence
i3 = delayedhigh > long_term_bear_filt // long term bearish delayedhigh divergence

i4 = currenttrough4 > lowest(d, div_lookback_period) // long term bullish osc divergence
i5 = y9 < long_term_bull_filt // long term bullish bottom div
i6 = delayedlow < long_term_bull_filt // long term bullish delayedbottom div



plot(d, color=white)
plot(bulldiv, title = "Tops", color=aqua, style=circles, linewidth=4, offset= -1)
plot(beardiv, title = "Bottoms", color=red, style=circles, linewidth=4, offset= -1)


plot(y10>y2 and oscMax and y3 < y4 ? d :na, title = "Bearish Divergence2", color=orange, style= circles, linewidth=4)
plot(y9<y6 and oscMins and y7 > y8 ? d :na, title = "Bullish Divergence2", color=purple, style=circles, linewidth=4)
plot(delayedlow<y6 and y7 > y8 ? d :na, title = "Bullish Divergence2", color=purple, style=circles, linewidth=4)
plot(delayedhigh>y2 and y3 < y4 ? d :na, title = "Bearish Divergence2", color=orange, style= circles, linewidth=4)

plot(long_term_div and oscMax and i and i2 ? d :na, title = "Bearish Divergence2", color=orange, style= circles, linewidth=4)
plot(long_term_div and oscMins and i4 and i5 ? d : na, title = "Bullish Divergence2", color=purple, style=circles, linewidth=4)
plot(long_term_div and i and i3 ? d :na, title = "Bearish Divergence2", color=orange, style= circles, linewidth=4)
plot(long_term_div and i4 and i6 ? d : na, title = "Bullish Divergence2", color=purple, style=circles, linewidth=4)
orange dot = bearish, purple dot = bullish
+1 Reply
What do cyan and red dots represent?
Reply
pekipek Koko FitclubSandy, Utah
bottoms/tops
+1 Reply
I really like your indicator. When their is new "circle" posted, is it added to chart at end of a bar or at end of the next bar?
Reply
pekipek vinsoj1
That's good, hope it will help you in making decisions! I'm not sure what you mean, the divergence dot is added to the indicator immediately once a divergence is located. And that is based on tops/bottoms in price and oscilator (PPO), Could you explain a bit more detailed what you mean?
Reply
vinsoj1 pekipek
In looking at various price charts with your indicator, I see the past history of the indicator's noting divergence. However, I have not been able to discern when a divergence changes. In other words, does a new signal occur in real time (within a given bar), or does a new signal show up at the end of a bar? Or, does the signal show up in a post-dated manner - does today's new high/low mean that yesterday's bar was the change in trend?

I have tried to read through the script to understand the logic. While I understand the PPO indicator and the concept of divergence, I must admit the script language is not easy for me to follow. Any thoughts you could share about the assumptions regarding the indicator are appreciated. Thanks!
Reply
pekipek vinsoj1
Think I get what you mean now. A signal definitely can occur in real time, but as you know to determine whether a bar is a top (or bottom), the bar next of the potential top must complete. In this way it is possible that at some point during the lifetime of the bar right after the potential top, this bar was lower then the potential top, making the potential top look like a real top. The indicator will plot the divergence dot at that point. However if, during the lifetime of the the bar right after the potential top (now looking like a real top), this bar goes higher, the divergence gets cancelled and the indicator will repaint (delete) the divergence dot.

The indicator does not repaint if the divergence gets immediately cancelled 2 bars after the top ( so 2 bars after the top the price goes higher and the divergence does not play out).

Sometimes, the top in price will be a tiny bit later the than the top in the PPO, that's what the:

delayedlow = priceMins and barssince(oscMins) < 3 ? low : na
delayedhigh = priceMax and barssince(oscMax) < 3 ? high : na

variables are for. So if the top in PRICE is less than 3 bars after the top in PPO, it is still able top plot such a divergence. If it is 3 or more bars later, it is not a divergence in my opinion. If you think otherwise you could change that, but I think you will get weird results.

Hope this helps! If not keep shooting.
+1 Reply
Nice indicator! This is very useful. Thanks pekipek
Reply
You're welcome, hope it will be of help and make u rich!
Reply
can someone help me to about how can i instal this indicator to my metatrader?
Reply
That's the most awesome indicator for me so far: thanks a lot pekipek
+1 Reply
pekipek Kilgore
Youre welcome!
Reply
In spite of some deficiencies yourself point out , I find this indicator very useful as regards changing trends. Thank you in the name of the chartist community.

Javier Spain
+1 Reply
Another question pekipek: in my chart, apart from cyan & red , I get GRAY dots (no orange nor purple) . Is this standard? or something abnormal to my chart ?. If normal, how should I interpret my gray dots?. Thanks in advance
Reply
pekipek javier.gonzalezgarcia.3388
I have no clue why you get gray dots, you shouldn't :P. Also if you combine the PPO divergence with PPO Histogram and Stochastics divergences and they all 3 point to a divergence at the same bar, you will get very high probability reversals
Reply
By abrakadabra reasons I have back my dots purple/orange (mysteries of Technics) . Thank you for your PPO suggestions, I'll try it and through it, to confirm if longer lookbacks periods (100 vs 55) really perfom better
Reply
Nice one...thanks for sharing whit us
Reply
I hate to sound stupid but how does a person create a Alert when the tops and bottom dots show up?
+3 Reply
I know how to create alerts but when i do on this one , tops/greater than/.99 it does not work.. any ideas?
Reply
dha PRO binaryking
you might have worked it out in meantime, but >0 should do the trick.
Reply
is there a way to know in advance what closing price at the end of day will trigger a buy or sell dot?
Reply
Fantastic indicator - v clever - esp when used with the usual other stuff - i use smoother 3 - no line and tops/btms as columns - so pure signal
Many Thanks for sharing
Question - have you considered turning into a 'Strategy' on TV?
Reply
scarf PRO LuckyMouse
I made a strategy, in case you're still interested:
PPO Bull/Bear Divergence to High/Low Strategy
Reply
Very nice Indicator ! simple to use for beginners.....!
Reply
Huge fan of this indicator, Pekipek. Thanks!

I did a version with alerts and slightly remixed visuals:
PPO Divergence Alerts
Reply
kris00l scarf
Thanks Pekipek ... probably can you update and bring this out of BETA? :) ... Hey Scarf .. thanks for sharing your code.
Reply
@scarf, Run into this indicator, looks promising. Question I have, does it repaint?
Reply
An excellent indicator, simple and true. With many thanks.
Reply
This is great. I use it ontop of UCS Murrey's Math Oscillator, as well as CMW's Vix Fix.
Reply
Would it be possible to program your study to indicate at what closing price the study will trigger a change?

Example: would like to know in advance what the closing price would need to be when your average indicator crossed its threshold level for direction change.
Reply
Is there any possible way to have this coded for MT4 ?
Reply
so it repaints ... that basically it, the signals im seeing arent there in real time
Reply
Ideas Scripts Chart
United States
United Kingdom
India
España
France
Italia
Polska
Brasil
Россия
Türkiye
Indonesia
日本
한국
Home Stock Screener Forex Signal Finder Economic Calendar How It Works Chart Features House Rules Moderators For the WEB Widgets Stock Charting Library Priority Support Feature Request Blog & News FAQ Help & Wiki Twitter
Private Messages Chat Ideas Published Followers Following Priority Support Public Profile Profile Settings Account and Billing Sign Out