Ehlers' Sinewave Indicator
Forums › ProRealTime English forum › ProBuilder support › Ehlers' Sinewave Indicator
- This topic has 26 replies, 1 voice, and was last updated 3 years ago by Suzu Yuk.
-
-
03/25/2020 at 6:04 PM #123303
Hi there, can anyone figure out how to get the Fractal indicator to take trades in a system?
I tried writing it out manually (including adding the indicator in the system as I’m not sure if calling it is the fastest, cleanest way to use it?), but it only takes one trade. The first one.It’d be really interesting to backtest this with differnt types of stops (Kase Dev Stop, Kaufman, Trailing Stops etc) because the enrties already look like they’re way beyond 50% accurate on direction.
Cheers for any help,
Fractal Reversal Point System1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950// Definition of code parametersDEFPARAM CumulateOrders = False // Cumulating positions deactivated//Shouldersize = 3 //size of shouldersShoulderSize = 5r = ShoulderSize*2once SwingH = 0once SwingL = 0once FractalD = 0For i = 0 to r DoIf high[ShoulderSize] > high[i] or i = ShoulderSize ThenSwingH = SwingH + 1EndIfIf low[ShoulderSize] < low[i] or i = ShoulderSize ThenSwingL = SwingL + 1EndIfNextIf SwingH = (r+1) and (FractalD = 0 or FractalD = -1) ThenFractalH = high[ShoulderSize]FractalD = 1EndIfIf SwingL = (r+1) and (FractalD = 0 or FractalD = 1) ThenFractalD = -1EndIfSwingH = 0SwingL = 0// Conditions to enter long positionsIf SwingL = (r+1) and (FractalD = 0 or FractalD = -1) ThenFractalL = low[ShoulderSize]EndifIf FractalL thenBuy 10 Perpoint at MarketEndif// Conditions to enter short positionsIf SwingH = (r+1) and (FractalD = 0 or FractalD = 1) ThenFractalH = high[ShoulderSize]EndifIf FractalH thenSellshort 10 Perpoint at MarketEndif03/26/2020 at 6:07 PM #123489Spotted my mistake, the Fractal conditions weren’t complete. Here’s the correct Fractal System code:
Fractal triangles in the screenshot are yellow and blue.3.8 spread. £/$ Daily. 01/11/17-29/01/19
200% return, 40% Drawdown.123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051// Definition of code parametersDEFPARAM CumulateOrders = False // Cumulating positions deactivated//Shouldersize = 3 //size of shouldersShoulderSize = 2r = ShoulderSize*2once SwingH = 0once SwingL = 0once FractalD = 0For i = 0 to r DoIf high[ShoulderSize] > high[i] or i = ShoulderSize ThenSwingH = SwingH + 1EndIfIf low[ShoulderSize] < low[i] or i = ShoulderSize ThenSwingL = SwingL + 1EndIfNextIf SwingH = (r+1) and (FractalD = 0 or FractalD = -1) ThenFractalH = high[ShoulderSize]FractalD = 1EndIfIf SwingL = (r+1) and (FractalD = 0 or FractalD = 1) ThenFractalL = low[ShoulderSize]FractalD = -1EndIfSwingH = 0SwingL = 0// Conditions to enter long positionsIf SwingL = (r+1) and (FractalD = 0 or FractalD = -1) ThenFractalL = low[ShoulderSize]EndifIf FractalD = -1 and FractalL thenBuy 10 Perpoint at MarketEndif// Conditions to enter short positionsIf SwingH = (r+1) and (FractalD = 0 or FractalD = 1) ThenFractalH = high[ShoulderSize]EndifIf FractalD = 1 and FractalH thenSellshort 10 Perpoint at MarketEndif03/26/2020 at 6:34 PM #123494Fractal + Kase Dev Stop
Fractal triangles in the screenshot are yellow and blue.
3.8 spread. £/$ Daily. 01/11/17-29/01/19 (randomly chosen dates)
200% return, 32% Drawdown.
Shouldersize = 5 randomly chosen. Please adjust these and the Dev Stop for different markets.Kase Dev Stop code: https://www.prorealcode.com/prorealtime-indicators/kase-dev-stop-v3
Fractal Reversal Point+DevStop123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869// Definition of code parametersDEFPARAM CumulateOrders = False // Cumulating positions deactivated//Shouldersize = 3 //size of shouldersShoulderSize = 5r = ShoulderSize*2once SwingH = 0once SwingL = 0once FractalD = 0For i = 0 to r DoIf high[ShoulderSize] > high[i] or i = ShoulderSize ThenSwingH = SwingH + 1EndIfIf low[ShoulderSize] < low[i] or i = ShoulderSize ThenSwingL = SwingL + 1EndIfNextIf SwingH = (r+1) and (FractalD = 0 or FractalD = -1) ThenFractalH = high[ShoulderSize]FractalD = 1EndIfIf SwingL = (r+1) and (FractalD = 0 or FractalD = 1) ThenFractalL = low[ShoulderSize]FractalD = -1EndIfSwingH = 0SwingL = 0// Conditions to enter long positionsIf SwingL = (r+1) and (FractalD = 0 or FractalD = -1) ThenFractalL = low[ShoulderSize]EndifIf FractalD = -1 and FractalL thenBuy 10 Perpoint at MarketEndif// Conditions to exit long positionsignored, ignored, ignored, Dev,ignored, ignored = CALL "Kase Dev Stop Lisse+SAR+4.5/6"c1 = (close CROSSES UNDER Dev)IF c1 THENSELL AT MARKETENDIF//-------------------------//// Conditions to enter short positionsIf SwingH = (r+1) and (FractalD = 0 or FractalD = 1) ThenFractalH = high[ShoulderSize]EndifIf FractalD = 1 and FractalH thenSellshort 10 Perpoint at MarketEndif// Conditions to exit short positionsignored, ignored, ignored, Dev, ignored, ignored = CALL "Kase Dev Stop Lisse+SAR+4.5/6"c2 = (close CROSSES OVER Dev)IF c2 THENEXITSHORT AT MARKETENDIFKase Dev Stop with SAR123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112//Voici le code en version SAR : plus WITH DEV STOP 4.5 + 6.0//Settingsn=30p1=1.0p2=2.2p3=3.6p4=4.5p5=6.0difference=0Hg=highest[2](high)Lw=lowest[2](low)DTR=max(max(Hg-Lw,abs(Hg-close[2])),abs(Lw-close[2]))aDTR=average[n](DTR)for i=0 to n-1 dodifference=difference+square(DTR[i]-aDTR)nextdifference=difference/nsdev=sqrt(difference)dev0=close-aDTRdev1=close-aDTR-p1*sdevdev2=close-aDTR-p2*sdevdev3=close-aDTR-p3*sdevdev4=close-aDTR-p4*sdevdev5=close-aDTR-p5*sdevif dev0<dev0[1] and close>dev5[1] thendev0=dev0[1]endifif dev1<dev1[1] and close>dev5[1] thendev1=dev1[1]endifif dev2<dev2[1] and close>dev5[1] thendev2=dev2[1]endifif dev3<dev3[1] and close>dev5[1] thendev3=dev3[1]endifif dev4<dev4[1] and close>dev5[1] thendev4=dev4[1]endifif dev5<dev5[1] and close>dev5[1] thendev5=dev5[1]endifdev6=close+aDTRdev7=close+aDTR+p1*sdevdev8=close+aDTR+p2*sdevdev9=close+aDTR+p3*sdevdev10=close+aDTR+p4*sdevdev11=close+aDTR+p5*sdevif dev6>dev6[1] and close<dev11[1] thendev6=dev6[1]endifif dev7>dev7[1] and close<dev11[1] thendev7=dev7[1]endifif dev8>dev8[1] and close<dev11[1] thendev8=dev8[1]endifif dev9>dev9[1] and close<dev11[1] thendev9=dev9[1]endifif dev10>dev10[1] and close<dev11[1] thendev10=dev10[1]endifif dev11>dev11[1] and close<dev11[1] thendev11=dev11[1]endifif close>dev11[1] thenflag=-1elseif close<dev5[1] thenflag=1endifendifif flag=-1 thenind0=dev0ind1=dev1ind2=dev2ind3=dev3ind4=dev4ind5=dev5//k=1 Bluer=0g=191b=255elseind0=dev6ind1=dev7ind2=dev8ind3=dev9ind4=dev10ind5=dev11//k=-1 Oranger=255g=128b=0endif//ORIG return ind0 COLOURED BY k,ind1 coloured by k,ind2 coloured by k,ind3 coloured by k////ORANGE AND LIGHT BLUEreturn ind0 coloured(r,g,b) style(dottedline,2) as "Warning Line", ind1 coloured(r,g,b) style(dottedline,2) as "Dev Stop 1.0",ind2 coloured(r,g,b) style(dottedline,2) as "Dev Stop 2.2", ind3 coloured(r,g,b) style(line,2) as "Dev Stop 3.6", ind4 coloured(r,g,b)style(dottedline,2) as "Dev Stop 4.5", ind5 coloured(r,g,b) style(line,2) as "Dev Stop 6.0"03/26/2020 at 7:49 PM #123517Hi @Nicolas, I was wondering could you please figure out why the buy signal occurred when it did and also why the sell signal is late? This applies to all the trades. Pls see my screenshot.
The Trading System code is actually directly above this comment. I was trying to get this Fractal System to trade on the next bar after those yellow and blue fractal triangle signals appeared. Any ideas? This is a great indicator that Juanj has coded!
Cheers and Stay safe,
Bard03/27/2020 at 9:47 AM #123555Usual debugging routine:
- verify that you are using the same exact settings in both the strategy and the indicator applied on the chart
- GRAPH / GRAPHONEPRICE the variables (lines of your indicator) to verify they are the same as the one used on the price chart
03/27/2020 at 5:17 PM #123628Thanks @Nicolas, I double checked indicator and system code, they’re both working off a shouldersize =5 variable. I have included the graphing function in the code using: https://www.prorealcode.com/blog/debugging-probuilder-graph-instruction/
So I’ve tried many different attempts using different parts of the code like “FractalH” or “FractalD = -1 and FractalL ” in the graphing code (and my buy/sell code) — pls see code below — but I can never get the graph to line up with the blue and yellow triangles (or more importantly get the system to actually take trades AT those triangles! This is because I don’t understand the code well enough to be able to program it to take those trades and graph it at those exact blue and yellow triangle signals.
I guess to a coder/programmer it is probably obvious. I get the basic premise that the code is searching for 5 day highs and lows dependent upon that “shouldersize = 5” variable, but don’t understand the line:
SwingH = (r+1 (i.e. 11) ) and (FractalD = 0 or FractalD = -1) particularly the FractalD part?Graph123456If FractalH (I also tried FractalH = high[ShoulderSize]) thensignals = 1ELSEsignals = -1ENDIFGRAPH signals AS "Fractal Signals"What code needs to be placed before that “buy 10 at market” command to get it to enter the next bar after a blue or yellow triangle signal?
Thanks again,
03/28/2020 at 5:14 PM #12373603/28/2020 at 10:17 PM #123763No worries, here you go @Florian: https://www.prorealcode.com/prorealtime-indicators/kase-dev-stop-v3/|
It doesn’t matter if you add and use the non SAR version to the code because the issue I have isn’t the Exit it’s the Entry. Btw, what happens when you copy the SAR version I posted above?
03/30/2020 at 9:35 AM #123888The fractals are marking tops and bottoms in the past. These points are obviously detected afterwards, that’s why your entries are “late”, they just open at the exact moment of when the fractals points are confirmed (later after the top or the bottom). I suggest you read about how the fractal are formed 😉
1 user thanked author for this post.
03/30/2020 at 12:00 PM #123937“In order for a fractal to form, there should be a series of 5 consecutive bars where the middle bar will be the highest preceded and followed by two lower neighbouring bars on each side.” https://www.prorealcode.com/prorealtime-indicators/bill-williams-fractals/
Right, got it! Thanks @Nicolas, I clearly need to take my Government prescribed daily dose of fresh air and exercise! 🤪
The shouldersize might be = 5, but “r” = shouldersize *2, so there is a 10 + 1 day formation with the highest or lowest candle in the middle of that pattern and not confirmed until the end of the last bar. I guess the only “solution” might be to go from the daily time frame and look at a 4 hour or 2 hour time frame to see if there is any “advance warning” of a top or bottom being formed but that’s not exactly going to always spot a daily formation.I still don’t understand the line:
SwingH = (r+1) and (FractalD = 0 or FractalD = -1) particularly the FractalD part?That’s from Line 22 in this post: https://www.prorealcode.com/topic/ehlers-sinewave-indicator/page/2/#post-123494
How does the Fractal code know what FractalD = -1 is yet? It’s not been defined in the lines of code before line 22? Obviously it’s a conditionality (-1 or 1), so if, in Line 22, the Fractal identity is either 0 or -1 then a new high can be classified as FractalD = 1 but could you please explain this FractalD = -1 despite — not being defined yet — in layman’s terms though?
Cheers,03/30/2020 at 12:46 PM #123945In this code, the FractalD variable is the “direction” of the fractal, aka a top or a bottom. The code keep in memory the last formed fractal. In the first run the FractalD is not yet known, that’s why it also test if it is equal to 0 or 1/-1.
1 user thanked author for this post.
09/26/2021 at 6:41 PM #178483The link is no longer working….
https://www.pro-indicators.com/pro-indicators—sinewave—momentum-on-tradingview-en.html
-
AuthorPosts
Find exclusive trading pro-tools on