TradingView
scarf
12 Th08 2016 10:21

PPO Bull/Bear Divergence to High/Low Strategy 

U.S. Dollar/Japanese YenFXCM

Mô tả

A simple strategy that uses the PPO divergences to open trades and the highs/lows to close them. Credit to Pekipek for this PPO Divergence indicator (I changed the visuals a bit)

STRATEGY
Purple circle - bullish divergence - enter LONG
Orange circle - bearish divergence - enter SHORT
Green dot - high point - exit LONG
Red dot - low point - exit SHORT

That's it. Not very profitable, but I like Pekipek's indicator a lot so figured I'd see what a strategy was like. Would love to see any variations.
Bình luận
kakola
That's funny, as soon as I saw this PPO indicator, I made a strategy out of it as well, but for some reason it doesn't do well.
scarf
I think it can be more effective on a higher timeframe with a secondary indicator to manage false signals. Here are some examples: tradingview.com/script/cwuXC9xQ-PPO-Divergence-Alerts/
djmc
@scarf, is there any repainting in the indicator? are the purple and orange dots shown there moved in any how in the test.
yolo12
Hi Folks! Would anyone be able to help me?
I'd like to change the long/short entry points to the green and red dots.
Is that possible?
Thanks in advance!!
scarf
@yolo12, Change the last few lines to this: pastebin.com/raw/e74ZDQsr

Haven't tested it, but it should work
oosthuizenp
Hi scarf, I see there’s some code that has been commented out that alerts you , how can I setup alerts on big purple circles?
bmc12345
@oosthuizenp, I'm new to Pine but/so I will help you (I think the long-term traders who code get overwhelmed and stop replying (fair enough too - they've been generous with their code in the first place)). You may have already worked this out but I'll answer it anyway. Since I don't know your experience / proficiency with coding, I'll take you through the logic/deductive process (I hope you don't find it patronising (not intended)) - this may help with future Pine "hacking" you may want to undertake.

First, the alertcondition is on line 102; but line 100 states: "//Used for alerts when this is an indicator, not a strategy". So I assume (I'm new here) that alerts cannot be used in strategies, only in indicators (just checked, and that seems to be the case). This "strategy" is derived from "Pekipek's PPO Divergence BETA" (an indicator), so you would have to run that simultaneously with the same settings as the strategy.

Now, just for fun... if this were an indicator sans alerts, this is how you'd add one...

=====

First, you will need to create a copy of the indicator in Pine Editor before you can hack at it - good time to change its name too. It will show up in "My Scripts" in "Indicators and Strategies".

"Big purple circles" :: ok, look in the code for the line which "plots" purple circles ==> line 84:

plot(bulldiv, title = "Bottoms", color=maroon, style=circles, linewidth=3, offset= -1)

(Maroon is kind of purple - although "Maroon Haze" is just missing that certain something...)

The first value after "plot(" is the series ==> bulldiv
In normalspeak: Every time bulldiv is true, Pine will stick a "big purple circle" in the appropriate place on the chart (it "plots" it).

So, somewhere prior to this, bulldiv must have been declared and defined so Pine can calculate its value later, so find where bulldiv has been declared ==> line 69:

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

Translating that: bulldiv means = Is "BottomPointsInPPO" true for this bar ? If yes, calculate d[1 bar back] : if untrue, na / forget about it
(where 'BottomPointsInPPO', and 'd' are other previously declared statements which Pine will have already calculated)

So, since Pine is using 'bulldiv" to decide when to plot "maroon circles", you can use "bulldiv" to tell Pine to create an alert-shortcut using the same condition ==>

syntax for that is: alertcondition(condition, title, message) ==>

alertcondion(bulldiv, title="Bullish divergence is true", message="Purple Haze all around, don't know if I'm coming up or down.")

Tack that on to the end of the script - it must appear after the series has been defined (the series must be defined first - tacking it on the end is safest).

Now, you can create a new alert easily:
- In alerts section, create new alert, under the "condition" dropdown, select "Pekipek's PPO Divergence BETA" (or whatever is the name of the indicator)
- In the dropdown selector directly beneath that will be the option "Bullish divergence is true" - select that (nothing else - no "crossing", "greater than", etc.)
- This will create an alert which will go off every time the maroon circle is plotted; the pop-up the message will say "Purple Haze all around, don't know if I'm coming up or down." (which you should change before you tack it onto the end of the script BTW.)

BUT... wait, there's more:

Maroon/purple circles are being plotted at multiple locations ==> lines 84, 105, 107, 110 & 112.

If you only wanted the one, you'd have to work out for which one you wanted an alert, and follow the process above. If you wanted an alert whenever ANY maroon/purple circle was plotted...

Following the same process above: Track back to where they are being first declared, if they have not already been declared in one statement, declare them all on one line using the "or" Boolean operator (you want to know when ANY of them are true at any time, not when ALL of them are true at once), then use that statement as a "series" in an alertcondition statement. Like this...

Take line 105 to start: Its "series" is "y9<y6 and oscMins and y7 > y8 ? d :na" - ignore everything after the "?" (? = "if true" operator).
Look for a line earlier where "y9<y6 and oscMins and y7 > y8" may have already been declared and named ==> yep, line 92 - "bullishdiv1".
If it wasn't already named/declared, use line 92 as a guide on how it should look if you needed to add it.

In fact the series for all the maroon/purple circles have been declared previously:
Line 84 ==> line 69 = bulldiv
Line 105 ==> line 92 = bullishdiv1
Line 107 ==> line 93 = bullishdiv2
Line 110 ==> line 94 = bullishdiv3
Line 112 ==> line 95 = bullishdiv4

And, conveniently, bullishdiv1 to bullishdiv4 have all been declared together at line 98 = "bullish"

(Trigger warning!)
So, assuming you want Line 84's "maroon" circle to be included as a trigger for the alert, then you'd need to create a new line at 99 to add "bulldiv" (maroon circles) to "bullish" (the already group-declared purple circles), like this:

bullish_all = bulldiv or bullish // statement is true if a maroon circle is plotted OR if any purple circle is plotted

Then, tack the alertcondition statement to the end of the script, using bullish_all as the series:

alertcondition(bullish_all, title="Bullish divergence is true", message="Purple Haze all around, don't know if I'm coming up or down.")

Now, (once you've set the alert) an alert will sound whenever ANY maroon/purple circle is plotted (ie. bullish divergence is true).

====

Anyway, hope I didn't bore you; that this wasn't "too much"; and I hope it helped you (or helps someone, at some point in the future).

Bye.

(You know, you start something thinking it will be easy, and then... you realise there's no turning back).
bmc12345

**bulldiv= BottomPointsInPPO ? d(square-bracket)1(square-bracket) : na // plots dots at bottoms in the PPO

** Translating that: bulldiv means = Is "BottomPointsInPPO" true for this bar ? If yes, calculate d(square-bracket) one bar back (square-bracket) : if untrue, na / forget about it

I keep forgetting that square brackets are not allowed on this message-board.
oosthuizenp
@bmc12345, in the true DOTA2 style I can only say ‘God-like!!’ What a monster reply thanks dude this is fantastic!! Appreciate the effort
bmc12345
@oosthuizenp, You're welcome.

Another tip:
Re: "If you only wanted the one (purple circle), you'd have to work out for which one you wanted an alert, and follow the process above."

The easiest way to ID the right one would be to check the "data window" - 3rd selection on the right hand "tools menu". It shows the values for every plot on every indicator, for each bar. So hold your cursor over the bar triggering the big purple circle, see which purple "plot" is triggered, and note down its title to find the right line in the code.
Thêm nữa