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
-
-
01/14/2017 at 7:46 PM #21128
Hello to everyone,
before I start, I want to tell everyone that some days ago I wrote this post in the italian forum, in which I was looking for some help because I’ve created an indicator that draws these swing lines that represent resistances and supports and I wanted to improve the algorithm. Nicolas, helped me to make the indicator work for all assets ( I think you all know him ) and he told me that maybe I can find some more help here.
So I wanted to create an indicator that can draw the swing lines that I draw manually (first screenshot).
I wrote the code below:
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273//vars//n = 21 // period for calculating highs and lows//tolleranza = 10 // (needs to be expressed in points )if we have 2 or more lines that are this close then draw a medium line//smoothness = 13 // this variable acts like a smooth factorDEFPARAM CalculateOnLastBars = 350 //per il calcolo delle swing lines prendiamo in considerazione solamente le ultime X candeleonce linear = 0once lineas = 0once newlinear = 0once newlineas = 0once newlinearr = 0once newlineass = 0resistenze = highest[n]((close+high)/2) // resistancessupporti = lowest[n]((close+low)/2) // supportsif resistenze[n-lisciatura] = resistenze[1] thenlinear = (resistenze[1] + linear) / 2elselinear = linearendif//drawhline(linear) coloured(255,0,0)if supporti[n-lisciatura] = supporti[1] thenlineas = (supporti[1] + lineas) / 2elselineas = lineasendif//drawhline(lineas) coloured(0,255,0)if linear[2] = linear[1] and linear[1] = linear then//drawhline(linear) coloured(255,0,0)newlinear = linearendifif lineas[2] = lineas[1] and lineas[1] = lineas then//drawhline(lineas) coloured(0,255,0)newlineas = lineasendifi = 0valsup = newlinear + tolleranza*pointsizevalinf = newlinear - tolleranza*pointsizewhile i <> 350 doif newlinear[i] = 0 then//aiuta ad accorciare il ciclobreakendifcond = (newlinear[i] <= valsup and newlinear[i] >= valinf) or (newlineas[i] <= valsup and newlineas[i] >= valinf)if cond thennewlinearr = (newlinear[i] + newlinear)/2endifi = i+1wendi = 0valsup = newlineas + tolleranza*pointsizevalinf = newlineas - tolleranza*pointsizewhile i <> 350 doif newlineas[i] = 0 then //should help to make the cycle shorterbreakendifcond = (newlineas[i] <= valsup and newlineas[i] >= valinf) or (newlinear[i] <= valsup and newlinear[i] >= valinf)if cond thennewlineass = (newlineas[i] + newlineas)/2endifi = i+1wenddrawhline(newlinearr) coloured(0,125,255)drawhline(newlineass) coloured(0,125,255)return newlinearr as "R", newlineass as "S"The indicator draws the lines like in the second attachment. Now the result is not bad but I would like the reduce the number of the lines. What I would like to do next is to filter the lines using other lines drawn on bigger time frames. Because I’m not that much of an expert with PRT code the algorithm is bit heavy and if I would like to apply the forth filter ( the one based on bigger tf ) I’m afraid it would be much much heavier.
I already know Nicolas has some ideas and I’m looking forward to see what he has in mind 🙂
Thanks
04/11/2017 at 5:13 PM #31745Thanks to the new website search engine, I retrieved this post lost months ago 🙂
Here is the version I made so far (same as the one from the Italian forum)
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788DEFPARAM CalculateOnLastBars = 350 // To calculate the lines swing we take into consideration only the latest X candlesn = 20 // highest and lowest period for support/resistance fetchtolerance = 5 // should be expressed in points) if there are two (or more) lines that are close to me, then you have to draw a center linelookback = 10 // period lookback to confirm support and resistance areasshowSupport = 1//(0=false , 1=true)showResistance = 1 //(0=false , 1=true)once linear = 0once lineas = 0once newlinear = 0once newlineas = 0once newlinearr = 0once newlineass = 0if showResistance thenresistance = highest[n](high) // resistance ( massimi precedenti dove i prezzi sono stati respinti)if resistance[n-lookback] = resistance[1] thenlinear = (resistance[1] + linear) / 2elselinear = linearendifif linear[2] = linear[1] and linear[1] = linear thennewlinear = linearendifi = 0valsup = newlinear + tolerance*pointsizevalinf = newlinear - tolerance*pointsizewhile i <> 350 doif newlinear[i] = 0 then//aiuta ad accorciare il ciclobreakendifcond = (newlinear[i] <= valsup and newlinear[i] >= valinf) or (newlineas[i] <= valsup and newlineas[i] >= valinf)if cond thennewlinearr = (newlinear[i] + newlinear)/2savedbar = barindex//[i]endifi = i+1wenddrawhline(newlinearr) coloured(0,125,255)if newlinearr<>oldtextr thendrawtext("▼ #newlinearr#",savedbar,newlinearr)oldtextr=newlinearrendifendifif showSupport thensupport = lowest[n](low) // support ( minimi precedenti dove i prezzi sono stati rimbalzati)if support[n-lookback] = support[1] thenlineas = (support[1] + lineas) / 2elselineas = lineasendifif lineas[2] = lineas[1] and lineas[1] = lineas thennewlineas = lineasendifi = 0valsup = newlineas + tolerance*pointsizevalinf = newlineas - tolerance*pointsizewhile i <> 350 doif newlineas[i] = 0 then//aiuta ad accorciare il ciclobreakendifcond = (newlineas[i] <= valsup and newlineas[i] >= valinf) or (newlinear[i] <= valsup and newlinear[i] >= valinf)if cond thennewlineass = (newlineas[i] + newlineas)/2savedbar = barindex[i]endifi = i+1wenddrawhline(newlineass) coloured(0,125,255)if newlinearr<>oldtexts thendrawtext("▲ #newlineass#",savedbar,newlineass)oldtexts=newlineassendifendifRETURNI’ll try to make further development on this indicator in the next days/weeks. Subscribe! Thanks to Rorschack for the original code and idea!
1 user thanked author for this post.
04/26/2017 at 12:38 PM #3348604/26/2017 at 2:04 PM #33506Sorry but this indicator use graphical components only available since version 10.3.
You should open a demo account with PRT-CFD! https://www.prorealcode.com/PRT-CFD-english/
1 user thanked author for this post.
04/26/2017 at 2:12 PM #3351004/27/2017 at 8:06 PM #3376604/28/2017 at 6:39 PM #3390705/03/2017 at 5:06 AM #3435705/03/2017 at 7:23 AM #3436805/03/2017 at 10:46 AM #34383You can use this updated code I just made, but only for support lines. Even if we don’t have arrays, it stores and draws last 10 support lines (which become resistance line of course when price is below them). Example attached too.
1 user thanked author for this post.
05/03/2017 at 12:47 PM #3440805/03/2017 at 1:01 PM #34410I don’t know how you do it and keep up with everything else!
This is something I don’t know myself, and you don’t even have any ideas of how many things are currently on the table ..
05/11/2017 at 2:33 PM #35214Thanks Nicholas!
I have the similar way:
123456789101112131415if newlineass<>oldtexts thendrawtext("▲ #newlineass#",savedbar,newlineass,SansSerif,standard,14)Y10 = Y9Y9 = Y8Y8 = Y7Y7 = Y6Y6 = Y5Y5 = Y4Y4 = Y3Y3 = Y2Y2 = Y1Y1 = newlineassoldtexts=newlineassendifendifi do not understand very well the Algorithm, how do i adjust the parameters optimize for past friday R / S for 30m time frame?
1 day = 48 candles (30m)
05/11/2017 at 9:36 PM #3525205/12/2017 at 4:05 AM #35263ah… Sorry Nicholas. It’s 2 different topics
First part of my post is to share i am using following to back up the Past 10 support. Whenever there is a new support, it will be stored as Y1, previous support will back up as Y2 and so on.1234567891011121314if newlineass<>oldtexts thendrawtext("▲ #newlineass#",savedbar,newlineass,SansSerif,standard,14)Y10 = Y9Y9 = Y8Y8 = Y7Y7 = Y6Y6 = Y5Y5 = Y4Y4 = Y3Y3 = Y2Y2 = Y1Y1 = newlineassoldtexts=newlineassendifSecond part of my Post is to get your advice, what is the parameters to adjust (n, lookback, etc) if i need only last 5 days R / S in 30m time frame chart. I do not understand well part of this algorithm.
123456789if resistance[n-lookback] = resistance[1] thenlinear = (resistance[1] + linear) / 2elselinear = linearendifif linear[2] = linear[1] and linear[1] = linear thennewlinear = linearendifBr, CKW
-
AuthorPosts
Find exclusive trading pro-tools on