Joining last 2 swing highs and last 2 swing lows
Forums › ProRealTime English forum › ProBuilder support › Joining last 2 swing highs and last 2 swing lows
- This topic has 19 replies, 7 voices, and was last updated 1 year ago by Nicolas.
-
-
12/10/2020 at 12:43 PM #153209
Hello, with Nicolas’s help the following initial code was generated to draw trend lines.
Now, I want it to draw only 2 trend lines in the chart- one up trend line joining the last 2 swing lows (2nd swing low must be higher than 1st swing low) and one down trend line joining the last 2 swing highs (2nd swing high must be lower than 1st swing high) as shown in the chart.
Can any one help me on this please.
Regards,
Trend line through last 2 swing highs/ swing lows12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879//VARIABLES//x 255 y 0 z 0 , u 0 v 255 w0// ----------------------H2=high[2]H1=HIGH[1]H0=HIGH[0]L2=LOW[2]L1=LOW[1]L0=LOW[0]// Swing High and Swing Low separationiF h1>=h2 AND h1>h0 THENT=-3elset=0endifIF l1<=l2 AND l1<l0 THENT1=3ELSET1=0ENDIF// Swing Highif t=-3 AND T1=0 thensh=h1ELSif t=-3 AND T1=3 thensh=h1ELSESH=0ENDIF// Swing LowIf t1=3 AND T=0 thensl=l1elsif t1=3 AND T=-3 thensl=l1elsesl=0endif//Down trend segment/ lineiF SH=h1 THENdrawtext("●",barindex[1],sh,dialog,bold,2) coloured(u,v,w)lastbar=1//IF TIME>ST AND TIME<ET and date=today THENlasthtt = httlasthttbar = httbarhtt=H1httbar = barindex[1]if lasthttbar <> lasthttbar[1] and lastbar[1]=-1 then//IF TIME>ST AND TIME<ET and date=today THENIF htt<Htt[1] then//and ltt<htt and ltt<htt[1] THENDRAWLINE(lasthttbar,lasthtt,httbar,htt) COLOURED(X,Y,Z)//(205,0,0)endifENDIFendif//ENDIF ENDIF//Up trend segment/ lineiF SL=l1 THENdrawtext("●",barindex[1],sl,dialog,bold,2) coloured(x,y,z)lastbar=-1//IF TIME>ST AND TIME<ET and date=today THENlastltt = lttlastlttbar = lttbarltt=L1lttbar = barindex[1]if lastlttbar <> lastlttbar[1] and lastbar[1]=1 then//IF TIME>ST AND TIME<ET and date=today THENIF Ltt>Ltt[1] then//and htt>ltt and htt>ltt[1] THENDRAWLINE(lastlttbar,lastltt,lttbar,ltt) COLOURED(U,V,W)//(0,205,0)endifENDIFendif//ENDIF ENDIFreturn12/10/2020 at 11:36 PM #153293Any help to identify the dynamic and latest 2 swing highs/ lows to draw the line would be appreciated.
12/11/2020 at 7:16 PM #15342912/12/2020 at 12:46 PM #153493I think Nicolas, Vonasi and others can help.
12/12/2020 at 3:59 PM #153505If you are using PRT v11 then you can just use my indicator:
https://www.prorealcode.com/prorealtime-indicators/every-fractal-trend-lines/
12/14/2020 at 5:09 AM #153628Thank you Vonasi, however IG Markets are still with PRT v10. And most importantly I want only 2 lines on my chart continuously updating itself based on my dynamic requirement as given earlier and below also:
Trend line joining latest 2 swing highs and latest 2 swing lows to draw the dynamic line
Regards,
12/14/2020 at 10:51 AM #153653I just reread your first post and I see that there is the additional criteria that the most recent swing low is higher than the second most recent and the opposite for swing highs.
In v10 we would need to use loops to search back and find each swing high/low and then exit the loop when we find two that meet our criteria – either that or store a mass of individual variables which is all a bit slow and cumbersome. In v11 everything is much easier with the availability of arrays as we can store every swing high/low that there has ever been in a single variable name. The code would be quite simple except if ever there has not been a lower swing low than the latest one or a higher swing high than the latest one because then we need to check back comparing to the second latest swing high/low and so on and so on. If a market has bottomed out at an all time low and formed a swing high there then we won’t be able to find a lower swing low further back in the data.
v11 also has the ability to draw into the future which v10.3 does not which makes projecting lines forward much easier.
IG are rolling out v11 country by country at the moment so I can’t imagine that it will be long before Australia gets it.
I’m a little bit busy with other things at the moment to get started on a new code and I am only coding in v11 now rather than struggle to achieve things I want in v10.3. Hopefully someone else can help you with v10.3 code or let me know when you get v11 and I will try to find some time to code something.
12/14/2020 at 12:30 PM #153675Many thanks dear Vonasi for your detailed response. Appreciate the same. It seems we need to stay in hope that IG will roll v11 sooner than later. I will let you know then.
Regards,
12/14/2020 at 12:32 PM #153676Yes Vonasi, your understanding is correct, “most recent swing low is higher than the second most recent and the opposite for swing highs”.
12/16/2020 at 12:23 PM #153947Hello Vonasi, Great news. I got the version 11 today and now only. Hence I am requesting you to please help me to draw only 2 trend lines in the chart- one up trend line joining the last 2 swing lows (2nd swing low must be higher than 1st swing low) and one down trend line joining the last 2 swing highs (2nd swing high must be lower than 1st swing high). the line should be extended to the right only.
Can you help me on this please.
Regards,
12/17/2020 at 10:43 AM #154086Here you go:
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980//parthapersonal Fractals v1.0//PRT v11//By Vonasi//Date: 20201217defparam drawonlastbaronly = true//Settings//BarsBefore = 1//BarsAfter = 1//Support = 1//Resistance = 1//Points = 1//Make sure all settings are valid onesBarsBefore = max(BarsBefore,1)BarsAfter = max(BarsAfter,1)StartBack = max(0,startback)if barindex >= barsbefore + barsafter then//Look for a low fractalBarLookBack = BarsAfter + 1if low[BarsAfter] < lowest[BarsBefore](low)[BarLookBack] THENif low[BarsAfter] = lowest[BarLookBack](low) THENa = a + 1$supportbar[a] = barindex[barsafter]$supportvalue[a] = low[barsafter]endifendif//Look for a high fractalif high[BarsAfter] > highest[BarsBefore](high)[BarLookBack] THENif high[BarsAfter] = highest[BarLookBack](high) THENb = b + 1$resistancebar[b] = barindex[barsafter]$resistancevalue[b] = high[barsafter]endifendifif islastbarupdate then//support lineif a >= 2 thenif support thenzz = 1for z = a-zz downto 0if $supportvalue[z] < $supportvalue[z+1] thendrawray($supportbar[z],$supportvalue[z],$supportbar[z+1],$supportvalue[z+1]) coloured(128,0,0)if points thendrawpoint($supportbar[z],$supportvalue[z],2) coloured(128,0,0)drawpoint($supportbar[z+1],$supportvalue[z+1],2) coloured(128,0,0)endifbreakendifzz = zz + 1nextendifendif//Resistance lineif b >= 2 thenif resistance thenzz = 1for z = b-zz downto 0if $resistancevalue[z] > $resistancevalue[z+1] thendrawray($resistancebar[z],$resistancevalue[z],$resistancebar[z+1],$resistancevalue[z+1]) coloured(0,128,0)if points thendrawpoint($resistancebar[z],$resistancevalue[z],2) coloured(0,128,0)drawpoint($resistancebar[z+1],$resistancevalue[z+1],2) coloured(0,128,0)endifbreakendifzz = zz + 1nextendifendifendifendifreturn12/17/2020 at 10:49 AM #154089The above is my first attempt at it. It looks at the latest pair of Fractals and if they are in the correct order (rising or falling) then it uses them. If not in the correct order it moves on to the next pair and checks them until it finds a pair that meets the criteria. This may not be exactly what you want and it will take a while for me to get my head around how to check the latest fractal with all previous fractals before moving to the second latest and checking that against all previous fractals until we find a suitable pairing.
I’m a bit busy with other stuff right now but will try to find time at some point.
Personally I think that trend lines are pretty useless as you can draw a line through any two values on a chart and then persuade yourself that it is a valid trend!
12/17/2020 at 11:23 AM #154092It didn’t need much time! Here is a version that checks the latest fractal and looks back for a fractal that meets the criteria. If there isn’t one then it uses the second last fractal and does the same checks. Not extensively tested!
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596//parthapersonal Fractals v1.1//PRT v11//By Vonasi//Date: 20201217defparam drawonlastbaronly = true//Settings//BarsBefore = 1//BarsAfter = 1//Support = 1//Resistance = 1//Points = 1//Make sure all settings are valid onesBarsBefore = max(BarsBefore,1)BarsAfter = max(BarsAfter,1)StartBack = max(0,startback)if barindex >= barsbefore + barsafter then//Look for a low fractalBarLookBack = BarsAfter + 1if low[BarsAfter] < lowest[BarsBefore](low)[BarLookBack] THENif low[BarsAfter] = lowest[BarLookBack](low) THENa = a + 1$supportbar[a] = barindex[barsafter]$supportvalue[a] = low[barsafter]endifendif//Look for a high fractalif high[BarsAfter] > highest[BarsBefore](high)[BarLookBack] THENif high[BarsAfter] = highest[BarLookBack](high) THENb = b + 1$resistancebar[b] = barindex[barsafter]$resistancevalue[b] = high[barsafter]endifendifif islastbarupdate then//support lineif a >= 2 thenif support thenflag = 0zz = 0for z = a-zz downto 0for xx = 1 to aif $supportvalue[z] > $supportvalue[z-xx] thendrawray($supportbar[z-xx],$supportvalue[z-xx],$supportbar[z],$supportvalue[z]) coloured(128,0,0)if points thendrawpoint($supportbar[z],$supportvalue[z],2) coloured(128,0,0)drawpoint($supportbar[z-xx],$supportvalue[z-xx],2) coloured(128,0,0)endifflag = 1breakendifzz = zz + 1nextif flag = 1 thenbreakendifzz = 0nextendifendif//resistance lineif b >= 2 thenif resistance thenflag = 0zz = 0for z = b-zz downto 0for xx = 1 to bif $resistancevalue[z] < $resistancevalue[z-xx] thendrawray($resistancebar[z-xx],$resistancevalue[z-xx],$resistancebar[z],$resistancevalue[z]) coloured(0,128,0)if points thendrawpoint($resistancebar[z],$resistancevalue[z],2) coloured(0,128,0)drawpoint($resistancebar[z-xx],$resistancevalue[z-xx],2) coloured(0,128,0)endifflag = 1breakendifzz = zz + 1nextif flag = 1 thenbreakendifzz = 0nextendifendifendifendifreturn1 user thanked author for this post.
12/17/2020 at 4:25 PM #154174Minor bug fix on the last bit of code that stops some crashes if it can’t find a pair of fractals to use:
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102//parthapersonal Fractals v1.2//PRT v11//By Vonasi//Date: 20201217defparam drawonlastbaronly = true//Settings//BarsBefore = 1//BarsAfter = 1//Support = 1//Resistance = 1//Points = 1//Make sure all settings are valid onesBarsBefore = max(BarsBefore,1)BarsAfter = max(BarsAfter,1)StartBack = max(0,startback)if barindex >= barsbefore + barsafter then//Look for a low fractalBarLookBack = BarsAfter + 1if low[BarsAfter] < lowest[BarsBefore](low)[BarLookBack] THENif low[BarsAfter] = lowest[BarLookBack](low) THENa = a + 1$supportbar[a] = barindex[barsafter]$supportvalue[a] = low[barsafter]endifendif//Look for a high fractalif high[BarsAfter] > highest[BarsBefore](high)[BarLookBack] THENif high[BarsAfter] = highest[BarLookBack](high) THENb = b + 1$resistancebar[b] = barindex[barsafter]$resistancevalue[b] = high[barsafter]endifendifif islastbarupdate then//support lineif a >= 2 thenif support thenflag = 0zz = 0for z = a-zz downto 1for xx = 1 to aif z-xx < 1 thenbreakendifif $supportvalue[z] > $supportvalue[z-xx] thendrawray($supportbar[z-xx],$supportvalue[z-xx],$supportbar[z],$supportvalue[z]) coloured(128,0,0)if points thendrawpoint($supportbar[z],$supportvalue[z],2) coloured(128,0,0)drawpoint($supportbar[z-xx],$supportvalue[z-xx],2) coloured(128,0,0)endifflag = 1breakendifzz = zz + 1nextif flag = 1 thenbreakendifzz = 0nextendifendif//resistance lineif b >= 2 thenif resistance thenflag = 0zz = 0for z = b-zz downto 1for xx = 1 to bif z-xx < 1 thenbreakendifif $resistancevalue[z] < $resistancevalue[z-xx] thendrawray($resistancebar[z-xx],$resistancevalue[z-xx],$resistancebar[z],$resistancevalue[z]) coloured(0,128,0)if points thendrawpoint($resistancebar[z],$resistancevalue[z],2) coloured(0,128,0)drawpoint($resistancebar[z-xx],$resistancevalue[z-xx],2) coloured(0,128,0)endifflag = 1breakendifzz = zz + 1nextif flag = 1 thenbreakendifzz = 0nextendifendifendifendifreturn12/18/2020 at 1:01 PM #154271This is just magic at your finger tips. Bravo, my dear. I could not praise more, your helping attitude and un-parallel zest to code something very new. I exactly got what was looking for. I was drawing all these manually. Many thanks dear Vonasi. You are just brilliant.
On your personal note, I beg to differ with you. Actually it can be extremely helpful if it is used properly in intra-day as enclosed.
Again, thanks a lot dear.
Best regards,
-
AuthorPosts
Find exclusive trading pro-tools on