Swing lines indicator
Forums › ProRealTime English forum › ProBuilder support › Swing lines indicator
- This topic has 24 replies, 10 voices, and was last updated 5 years ago by stefou102.
Tagged: resistance, support, swing
-
-
05/12/2017 at 2:36 PM #35333
if you only want to search through the last 5 days in a 30 minutes, you need to count how much 30 minutes bars there are in 5 days: (24 hours * 2 bars * 5 days) = 240 bars and change the first line to only fetch through this bar quantity:
1DEFPARAM CalculateOnLastBars = 240 // To calculate the lines swing we take into consideration only the latest X candles05/20/2017 at 6:27 PM #3617505/20/2017 at 7:05 PM #3617905/23/2017 at 12:10 PM #36401Hi @Nicolas,
Yes it is Ninjatrader, but i don’t have source code, Ninjatrader has an internal function .SwingHigh and .SwingLow that I do not think Prorealtime have on.
I’ve read that you’ve started doing something like that in the discussion:
https://www.prorealcode.com/topic/punti-di-swing-statici/
but I thought that with the new design tools of version 10.3 you could draw segments and not horizontal lines.
Regards
Gabriele
05/23/2017 at 8:34 PM #3648006/03/2017 at 9:15 AM #37335Thanks Rorschack & Nicolas
Anyway to make the levels not originate or start at zero so that you don’t have to adjust the price axis scaling when changing timeframes?
Thanks
Copperwave
02/25/2019 at 10:43 PM #92305Hello,
I reuse the original code, but used the William’s 3 bar indicator in order to identify the high/low acting as support/resistance in order to filter out the number of lines drawn. The outcome is better than the original version in my opinion, at least for daily/weekly charts on stock (what I was focus on). Code can still be optimized though, I’m not a pro coder.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254DEFPARAM CalculateOnLastBars = 100Maxbars=100if barindex=0 thenHIL=0LOL=close*10refbar=0endif//William's indicatorcounter=1ii=0jj=ii+1total=0while counter<4 dototal=total+1if (low[jj]>=low[ii]) and (high[jj]<=high[ii]) then//inside barjj=jj+1elsecounter=counter+1ii=ii+1JJ=ii+1endifwendbas=lowest[total](low)haut=highest[total](high)if close crosses over haut[1] thenreff=basendifif close crosses under bas[1] thenreff=hautendif//Finding the low/high when the indicator changes of directionIf close crosses over reff thenrefbar=barindexif refbar[1]<>0 thenlookbackL=max(1,refbar-refbar[1]+1)LOL=lowest[lookbackL](low)for i=0 to lookbackLif low[i]=LOL thensavedbarL=barindex[i]endifnextendifelsif close crosses under reff thenrefbar=barindexif refbar[1]<>0 thenlookbackH=max(1,refbar-refbar[1]+1)HIL=highest[lookbackH](high)for i=0 to lookbackHif high[i]=HIL thensavedbarH=barindex[i]endifnextendifendif//For the latest data on the chart, finding the high/low since the indicator change of direction for the last time, and only if this isn't the last bar which makes new high/lowLastBarOnChart=date=todayif LastBarOnChart thenlookbackH=max(1,barindex-refbar+1)lookbackL=max(1,barindex-refbar+1)if high<>highest[lookbackH](high) thenHIL=highest[lookbackH](high)for i=0 to lookbackHif high[i]=HIL thensavedbarH=barindex[i]endifnextendifif low<>lowest[lookbackL](low) thenLOL=lowest[lookbackL](low)for i=0 to lookbackLif low[i]=LOL thensavedbarL=barindex[i]endifnextendifendif//deleting support/resistance which are too closej = 0valsup = HIL + tolerance*HIL/100valinf = HIL - tolerance*HIL/100while j <> maxbars doif HIL[j] = 0 then//aiuta ad accorciare il ciclobreakendifcond1 = (HIL[j] <= valsup and HIL[j] >= valinf)cond2= (LOL[j] <= valsup and LOL[j] >= valinf)if cond1 and HIL>HIL[j] thenHIL = HILelsif cond1 and HIL<=HIL[j] thenHIL=HIL[j]endifif cond2 and HIL>LOL[j] thenHIL = HILelsif cond2 and HIL<=LOL[j] thenHIL=LOL[j]endifj = j+1wendj = 0valsup = LOL + tolerance*LOL/100valinf = LOL - tolerance*LOL/100while j <> maxbars doif LOL[j] = 0 then//aiuta ad accorciare il ciclobreakendifcond1 = (LOL[j] <= valsup and LOL[j] >= valinf)cond2= (HIL[j] <= valsup and HIL[j] >= valinf)if cond1 and LOL<LOL[j] thenLOL = LOLelsif cond1 and LOL>=LOL[j] thenLOL=LOL[j]endifif cond2 and LOL<HIL[j] thenLOL = LOLelsif cond2 and LOL>=HIL[j] thenLOL=HIL[j]endifj = j+1wend//keeping in memeory the latest support/resistanceonce resistancecount=1if HIL<>lastresistance then //barindex>lastdrawn andresistancecount=resistancecount+1if resistancecount=1 thenresistance1=HILlastresistance=resistance1endifif resistancecount=2 thenresistance2=HILlastresistance=resistance2endifif resistancecount=3 thenresistance3=HILlastresistance=resistance3endifif resistancecount=4 thenresistance4=HILlastresistance=resistance4endifif resistancecount=5 thenresistance5=HILlastresistance=resistance5endifif resistancecount=6 thenresistance6=HILlastresistance=resistance6endifif resistancecount=7 thenresistance7=HILlastresistance=resistance7endifif resistancecount=8 thenresistance8=HILlastresistance=resistance8endifendifonce supportcount=1if LOL<>lastsupport thensupportcount=supportcount+1if supportcount=1 thensupport1=LOLlastsupport=support1endifif supportcount=2 thensupport2=LOLlastsupport=support2endifif supportcount=3 thensupport3=LOLlastsupport=support3endifif supportcount=4 thensupport4=LOLlastsupport=support4endifif supportcount=5 thensupport5=LOLlastsupport=support5endifif supportcount=6 thensupport6=LOLlastsupport=support6endifif supportcount=7 thensupport7=LOLlastsupport=support7endifif supportcount=8 thensupport8=LOLlastsupport=support8endifendifdrawHline(resistance1) coloured(0,200,0)drawHline(resistance2) coloured(0,200,0)drawHline(resistance3) coloured(0,200,0)drawHline(resistance4) coloured(0,200,0)drawHline(resistance5) coloured(0,200,0)drawHline(resistance6) coloured(0,200,0)drawHline(resistance7) coloured(0,200,0)drawHline(resistance8) coloured(0,200,0)drawHline(support1) coloured(200,0,0)drawHline(support2) coloured(200,0,0)drawHline(support3) coloured(200,0,0)drawHline(support4) coloured(200,0,0)drawHline(support5) coloured(200,0,0)drawHline(support6) coloured(200,0,0)drawHline(support7) coloured(200,0,0)drawHline(support8) coloured(200,0,0)drawtext("▼",savedbarH,HIL+HIL*1/100)drawtext("▲",savedbarL,LOL-LOL*1/100)return1 user thanked author for this post.
02/26/2019 at 8:05 AM #92312Sorry, you have to add the term “tolerance” as parameter for the indicator, or add it at the beginning of the code. It is express here in percentage, and not in point. Depending on the TF, you can use like 0.2 (for intraday) to 3 for weekly
1 user thanked author for this post.
02/26/2019 at 10:29 AM #9233302/26/2019 at 11:23 AM #92345Normally, if two lines acting as support are resistance are too close (by the definition of the tolerance), one of them disappear. In the code before, I think you took the average of the two, but I prefer keeping the highest/lowest of the two depending on the case. But indeed, I have noticed that in a few cases, it doesn’t work as intended. So there are still a few bugs in the code, but overall work very well (for me at least). I hope someone can still improve it.
-
AuthorPosts
Find exclusive trading pro-tools on