Head and Shoulders equity curve stop loss
Forums › ProRealTime English forum › ProOrder support › Head and Shoulders equity curve stop loss
- This topic has 11 replies, 9 voices, and was last updated 5 years ago by Crillezz.
-
-
04/26/2017 at 5:19 PM #33532
Hi,
I put together a quick and dirty H&S pattern detection for PRT and thought to share it here, in case it’s of use to anyone, or in case someone would like to improve or contribute. I am sure you are probably aware of the head and shoulders pattern and its uses – but if not then take a look here.
Below is the raw beginnings of a module that can be plugged into a trading system. It looks roughly for head and shoulders patterns with the equity curve when your system is onMarket. If a head and shoulders pattern is found within your equity curve, a trigger will happen (“hsDone”) and you can then perform an action (such as exit the open trade to lock in profits, or any other action).
The code should be pretty self explanatory but it’s by no means a finished product. I don’t have time to go though all the logic cases, filters and variables at the moment but thought to share in case someone would like to pick it up and contribute. Open to all ideas of improving the H&S detection algo. Will pick up on it myself when I have more time.
123456789101112131415161718192021222324252627282930313233343536373839404142// -- equity curve head and shoulders detection ----once useHSPatterStop = 1if useHSPatterStop then// Variabls ------------------------D = positionPerf // data = ie usually current trade performancehsMinWidth = 4 // minimum shoulder-head width in barsrightShoulderMinDepth = 0.5 // minimum % of left shoulder that right shoulder must retrace to for a valid setup//-----------------------------------maxD = max(maxD, D)findL = (not hsLeft) and (not hsHead) and (d >= maxD) and (d > hsLeft)restL = d > hsLeft and (barIndex < hsLeftIndex+round(hsMinWidth/2) or d > hsLeft*2)findH = hsLeft and (not hsRight) and d > hsLeft //and d > hsHeadfindH = findH and d > hsHead and barIndex > hsLeftIndex+hsMinWidthfindR = (not hsRight) and hsHead and hsLeft and (d >= hsLeft)findR = findR and ( barIndex-hsHeadIndex >= hsMinWidth )findR = findR and lowest[barIndex-hsHeadIndex](d) <= hsLeft-(hsLeft-lowest[barIndex-hsLeftIndex](d))*rightShoulderMinDepthhsDone = hsRight and d <= hsLeft - lowest[barIndex-hsLeftIndex](d)graph hsDoneif findL or restL then // We found possible left shoulderhsLeft = dhsLeftIndex = barIndexhsHead = 0hsRight = 0elsif findH and not findR then // We found possible headhsHead = dhsHeadIndex = barIndexelsif findR then // We found possible right shoulderhsRight = delsif hsDone then // Pattern completed below left shoulder low// INSERT YOUR H&S CONDITION HANDLER HEREcanExitMyTrade = 1 // for exampleendifif hsDone or (not onMarket) then // reset to clear HS patternhsLeft = 0hsHead = 0hsRight = 0endifendifAll the best,
M
04/26/2017 at 5:37 PM #3353704/26/2017 at 7:17 PM #33548Why are you using Positionperf instead of High or Close of candlesticks? Since Positionperf is updated only once per bar, I presume the pattern found result should be the same.
But it’s a great idea and good share, thanks a lot Maz.
1 user thanked author for this post.
04/26/2017 at 7:45 PM #3357104/27/2017 at 3:54 PM #3369807/21/2017 at 3:06 PM #4128810/11/2017 at 3:56 PM #4905110/11/2017 at 9:45 PM #4906510/13/2017 at 7:03 AM #49230This is very cool, thanks Maz. Great work. Ill definitly try to adapt this into some of my strats and see if it would make a difference for my equity 🙂 Right off the bat this was fun to see! Attached screenshot of the clear difference, although in this example, holding it would actually give me a few pips extra haha.
11/16/2019 at 2:56 PM #11292511/16/2019 at 3:03 PM #11292711/17/2019 at 1:15 PM #112966Yes I am aware that it is not possible to see head and shplders until it is shaped.
I am posting a new image of a Quasimodo pattern. The difference is that it does a lower low before the right shoulder.
It would not be impossible to do a screener of such in an early stage.
So a screener when price forms a higher high => higher kow => higher high => lower low.
Before the right shoulder is formed.
The idea is to go short on the top of the left shoulder when the right shoulder is formed.
Hope you understand what I mean
-
AuthorPosts
Find exclusive trading pro-tools on