‘Swing Failure Pattern
Forums › ProRealTime English forum › ProBuilder support › ‘Swing Failure Pattern
- This topic has 8 replies, 3 voices, and was last updated 1 month ago by
robertogozzi.
-
-
05/03/2025 at 12:29 AM #246734Hi, I’ve found this interesting indicator for trading view. It’s be interesting to use it in a system. somone can help for conversion to PRT? thanks in advanceAlessio// This work is licensed under a Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0) https://creativecommons.org/licenses/by-nc-sa/4.0/// © LuxAlgo//@version=5indicator( ‘Swing Failure Pattern [LuxAlgo]’, ‘LuxAlgo – Swing Failure Pattern’, max_labels_count = 500, max_lines_count = 500, max_boxes_count = 500, overlay = true)//———————————————————————————————————————}//Settings//———————————————————————————————————————{sp = ‘ ‘len = input.int ( 5 , ‘Swings’ , minval= 1 )bull = input.bool ( true , ‘Bullish SFP’ )bear = input.bool ( true , ‘Bearish SFP’ )iVal = input.string (‘None’, ‘Validation’+sp+ ‘ ‘, group=’Volume Validation’, options = [‘Volume outside swing < Threshold’ ,’Volume outside swing > Threshold’,’None’])percent = input.float (25, ‘Volume Threshold %’ , inline=’valy’, group=’Volume Validation’, tooltip = ‘% of Total Volume’ , minval= 0 , maxval=100 )auto = input.bool (true, ” , inline=’auto’, group=’Volume Validation’ )mlt = input.int (50 , ‘ Auto’ + sp , inline=’auto’, group=’Volume Validation’ )res = input.timeframe(‘1′ , sp +’ LTF’ + sp +’ ‘, inline=’ltf’ , group=’Volume Validation’ )prem = input.bool (false ,’ Premium’ , group=’Volume Validation’, tooltip = ‘Premium Plan or higher’ )showDash = input.bool (true , ‘Show Dashboard’ , group= ‘Dashboard’ )dashLoc = input.string ( ‘Top Right’ , ‘Location’, options = [‘Top Right’, ‘Bottom Right’, ‘Bottom Left’] , group= ‘Dashboard’ )textSize = input.string ( ‘Normal’ , ‘Size’, options = [‘Tiny’, ‘Small’, ‘Normal’] , group= ‘Dashboard’ )dSwingLine = input.bool (true , ‘Swing Lines’ , group= ‘Style’ )dOpposLine = input.bool (true , ‘Confirmation Lines’ , group= ‘Style’ )dSFP_Line = input.bool (true , ‘Swing Failure Wick’ , group= ‘Style’ )dSFP_Label = input.bool (true , ‘Swing Failure Label’ , group= ‘Style’ )colBl = input.color (#089981 , ‘Lines / Labels’ , inline=’lin’ , group= ‘Style’ )colBr = input.color (#f23645 , ” , inline=’lin’ , group= ‘Style’, tooltip = ‘Bullish/Bearish’ )colBl2 = input.color (#08998180, ‘SFP Wicks ‘, inline=’wic’ , group= ‘Style’ )colBr2 = input.color (#f2364580, ” , inline=’wic’ , group= ‘Style’, tooltip = ‘Wick outside Swing, Bullish/Bearish’ )//—————————————————————————–}//UDT//—————————————————————————–{type pivfloat swing_prc // priceint swing_bix // bar_indexfloat oppos_prc // priceint oppos_bix // bar_indexbool activebool confirmedline swing_lineline oppos_lineline wicky_linelabel wicky_labeltypeswingint bixfloatprc//—————————————————————————–}//Variables//—————————————————————————–{n =bar_indexINV = color(na)FGc = chart.fg_colortable_position=dashLoc==’Bottom Left’?position.bottom_left:dashLoc==’Top Right’?position.top_right: position.bottom_righttable_size=textSize==’Tiny’?size.tiny:textSize==’Small’?size.small: size.normalvar tb = table.new(table_position, 2, 3, bgcolor = #1e222d, border_color = #373a46, border_width = 1, frame_color = #373a46, frame_width = 1)varswingswingH=swing.new()varswingswingL=swing.new()var piv pivH = piv.new()var piv pivL = piv.new()validate=iVal!=’None’valHigher= iVal == ‘Volume outside swing > Threshold’valLower = iVal == ‘Volume outside swing < Threshold’//———————————————————————————————————————}//Method//———————————————————————————————————————{method n(float piv) => bool out = not na(piv)//———————————————————————————————————————}//Execution//———————————————————————————————————————{tfS = timeframe.in_seconds( res )tfC = timeframe.in_seconds(timeframe.period)rs =auto?tfC/mlt:tfSif not validateres:=timeframe.periodelsers := prem ? rs : math.max(60, rs)res := timeframe.from_seconds(math.min(tfC, rs))ph = ta.pivothigh(len, 1)pl = ta.pivotlow (len, 1)[ltf_close, ltf_volume] = request.security_lower_tf(syminfo.tickerid, res, [close, volume])ltf_size = ltf_close.size()ifvalidateifltf_size>0andltf_size[1]==0line.new(n, close, n, close + syminfo.mintick, color=color.silver, style=line.style_dotted, extend=extend.both)//———————————————————————————————————————}//Bearish Pattern//———————————————————————————————————————{if bearifph.n()swingH.bix:=n-1swingH.prc:=phsw = swingH.prcbx = swingH.bixifhigh>swand open < swand close < swvalid = trueifvalidateifltf_close.size()>0outsideVolume = 0.totalVolume=ltf_volume.sum()forj=0toltf_close.size()-1if ltf_close.get(j) > swoutsideVolume += ltf_volume.get(j)if(valHigher?100/totalVolume*outsideVolume<percent:100/totalVolume*outsideVolume>percent)valid := false//if valid// label.new(n, high, text=str.format(“Total Volume: {0}\nWick Volume: {1}”, totalVolume, outsideVolume))ifvalidopposL=swopposB = nfor i = 1 to n – bx -1iflow[i]<opposLopposL := low [i]opposB := n – iif not pivH.confirmedpivH.swing_line .delete()pivH.oppos_line .delete()pivH.wicky_line .delete()pivH.wicky_label.delete()pivH := piv.new(sw, bx, opposL, opposB, true, false)ifdSwingLinepivH.swing_line := line.new (bx , sw , n, sw , color=colBr)ifdOpposLinepivH.oppos_line := line.new (opposB, opposL, n, opposL, color=colBr, style=line.style_dotted)ifdSFP_LinepivH.wicky_line := line.new (n , high , n, sw , color=colBr2, width=3)if dSFP_LabelpivH.wicky_label := label.new(n , high, style=label.style_label_down, text=’SFP’, textcolor=colBr, color=INV, size=size.normal)ifpivH.activeandnotpivH.confirmedpivH.swing_line.set_x2(n)pivH.oppos_line.set_x2(n)if close < pivH.oppos_prcpivH.confirmed := trueif pivH.wicky_label.get_x() == npivH.wicky_label.set_text(‘SFP\n▼’)elselabel.new(n, high, style=label.style_label_down, text=’▼’, textcolor=colBr, color=INV, size=size.normal)ifn-pivH.swing_bix>500or close > pivH.swing_prcpivH.active:=falseif not pivH.confirmedpivH.swing_line .delete()pivH.oppos_line .delete()pivH.wicky_line .delete()pivH.wicky_label.delete()//———————————————————————————————————————}//Bullish Pattern//———————————————————————————————————————{if bullifpl.n()swingL.bix:=n-1swingL.prc:=plsw = swingL.prcbx = swingL.bixiflow <swand open > swand close > swvalid = trueifvalidateifltf_close.size()>0outsideVolume = 0.totalVolume=ltf_volume.sum()forj=0toltf_close.size()-1if ltf_close.get(j) < swoutsideVolume += ltf_volume.get(j)if(valHigher?100/totalVolume*outsideVolume<percent:100/totalVolume*outsideVolume>percent)valid := falseifvalidopposH=swopposB = nfor i = 1 to n – bx -1ifhigh[i]>opposHopposH := high[i]opposB := n – iif not pivL.confirmedpivL.swing_line .delete()pivL.oppos_line .delete()pivL.wicky_line .delete()pivL.wicky_label.delete()pivL := piv.new(sw, bx, opposH, opposB, true, false)ifdSwingLinepivL.swing_line := line.new (bx , sw , n, sw , color=colBl )ifdOpposLinepivL.oppos_line := line.new (opposB, opposH, n, opposH, color=colBl , style=line.style_dotted)ifdSFP_LinepivL.wicky_line := line.new (n , low , n, sw , color=colBl2, width=3)if dSFP_LabelpivL.wicky_label := label.new(n , low, style=label.style_label_up, text=’SFP’, textcolor=colBl, color=INV, size=size.normal)ifpivL.activeandnotpivL.confirmedpivL.swing_line.set_x2(n)pivL.oppos_line.set_x2(n)if close > pivL.oppos_prcpivL.confirmed := trueif pivL.wicky_label.get_x() == npivL.wicky_label.set_text(‘▲\nSFP’)elselabel.new(n, low, style=label.style_label_up, text=’▲’, textcolor=colBl, color=INV, size=size.normal)ifn-pivL.swing_bix>500or close < pivL.swing_prcpivL.active:=falseif not pivL.confirmedpivL.swing_line .delete()pivL.oppos_line .delete()pivL.wicky_line .delete()pivL.wicky_label.delete()//———————————————————————————————————————}//Dashboard//———————————————————————————————————————{if barstate.islast and validate and showDashtb.cell(0, 0, str.format(“LTF: {0}”, res), text_color=color.white, text_size=table_size)//———————————————————————————————————————}05/03/2025 at 12:35 AM #246735
I add the youtube link where I found it.
thanks
https://www.youtube.com/watch?v=coVXCNjPBm4&ab_channel=TomCrown
05/06/2025 at 10:06 PM #24685505/07/2025 at 10:09 AM #246863You asked for a conversion just 3 days ago, be patient a few more days. Thanks 🙂
05/07/2025 at 1:01 PM #246866Hi, here is the code:
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263//--------------------------------------------------//// PRC_Swing failure Pattern//version = 0//07.05.2025//Iván González @ www.prorealcode.com//Sharing ProRealTime knowledge//--------------------------------------------------//// Inputs//--------------------------------------------------//len=5bull=1bear=1n=barindex//--------------------------------------------------//// Pivot High-Low calculation//--------------------------------------------------//src1 = lowsrc2 = highleftbars=lenrightbars=1//--- Pivots lowif src1 > src1[rightbars] and lowest[rightbars](src1) > src1[rightbars] and src1[rightbars] < lowest[leftbars](src1)[rightbars+1] then$ply[z+1] = src1[rightbars]$plx[z+1] = barindex[rightbars]z=z+1endif//--- Pivots highif src2 < src2[rightbars] and highest[rightbars](src2)<src2[rightbars] and src2[rightbars]>highest[leftbars](src2)[rightbars+1] then$phy[t+1]=src2[rightbars]$phx[t+1]=barindex[rightbars]t=t+1endif//--------------------------------------------------//// Bearish Pattern//--------------------------------------------------//if bear thenif t<>t[1] then$swingHbix[s+1]=$phx[t]$swingHprc[s+1]=$phy[t]s=s+1endifsw=$swingHprc[s]bx=$swingHbix[s]if high>sw and open<sw and close<sw thenopposL=swopposB=nfor i=1 to n-bx-1 doif low[i]<opposL thenopposL=low[i]opposB=n-iendifnextif $pivHconfirmed[w]=0 then$pivHswingbix1[w]=undefined$pivHswingprc1[w]=undefined$pivHswingbix2[w]=undefined$pivHswingprc2[w]=undefined$pivHopposbix1[w]=undefined$pivHopposprc1[w]=undefined$pivHopposbix2[w]=undefined$pivHopposprc2[w]=undefined$pivHwickybix1[w]=undefined$pivHwickyprc1[w]=undefined$pivHwickybix2[w]=undefined$pivHwickyprc2[w]=undefinedendif$pivHswingbix1[w+1]=bx$pivHswingprc1[w+1]=sw$pivHswingbix2[w+1]=n$pivHswingprc2[w+1]=sw$pivHopposbix1[w+1]=opposB$pivHopposprc1[w+1]=opposL$pivHopposbix2[w+1]=n$pivHopposprc2[w+1]=opposL$pivHactive[w+1]=1$pivHconfirmed[w+1]=0$pivHwickybix1[w+1]=n$pivHwickyprc1[w+1]=high$pivHwickybix2[w+1]=n$pivHwickyprc2[w+1]=sww=w+1endifif $pivHactive[w]=1 and $pivHconfirmed[w]=0 then$pivHswingbix2[w]=n$pivHopposbix2[w]=nif close < $pivHopposprc1[w] then$pivHconfirmed[w]=1if $pivHwickybix1[w]=n then$pivHwickyType[w]=1else$pivHwickyType[w]=0endifendifendifif n-$pivHswingbix1[w]>500 or close>$pivHswingprc1[w] then$pivHactive[w]=0if $pivHconfirmed[w]=0 then$pivHswingbix1[w]=undefined$pivHswingprc1[w]=undefined$pivHswingbix2[w]=undefined$pivHswingprc2[w]=undefined$pivHopposbix1[w]=undefined$pivHopposprc1[w]=undefined$pivHopposbix2[w]=undefined$pivHopposprc2[w]=undefined$pivHwickybix1[w]=undefined$pivHwickyprc1[w]=undefined$pivHwickybix2[w]=undefined$pivHwickyprc2[w]=undefinedendifendifendif//--------------------------------------------------//// Bullish Pattern//--------------------------------------------------//if bull thenif z<>z[1] then$swingLbix[q+1]=$plx[z]$swingLprc[q+1]=$ply[z]q=q+1endifsw=$swingLprc[q]bx=$swingLbix[q]if low<sw and open>sw and close>sw thenopposH=swopposBH=nfor i=1 to n-bx-1 doif high[i]>opposH thenopposH=high[i]opposBH=n-iendifnextif $pivLconfirmed[w]=0 then$pivLswingbix1[w]=undefined$pivLswingprc1[w]=undefined$pivLswingbix2[w]=undefined$pivLswingprc2[w]=undefined$pivLopposbix1[w]=undefined$pivLopposprc1[w]=undefined$pivLopposbix2[w]=undefined$pivLopposprc2[w]=undefined$pivLwickybix1[w]=undefined$pivLwickyprc1[w]=undefined$pivLwickybix2[w]=undefined$pivLwickyprc2[w]=undefinedendif$pivLswingbix1[w+1]=bx$pivLswingprc1[w+1]=sw$pivLswingbix2[w+1]=n$pivLswingprc2[w+1]=sw$pivLopposbix1[w+1]=opposBH$pivLopposprc1[w+1]=opposH$pivLopposbix2[w+1]=n$pivLopposprc2[w+1]=opposH$pivLactive[w+1]=1$pivLconfirmed[w+1]=0$pivLwickybix1[w+1]=n$pivLwickyprc1[w+1]=low$pivLwickybix2[w+1]=n$pivLwickyprc2[w+1]=sww=w+1endifif $pivLactive[w]=1 and $pivLconfirmed[w]=0 then$pivLswingbix2[w]=n$pivLopposbix2[w]=nif close > $pivLopposprc1[w] then$pivLconfirmed[w]=1if $pivLwickybix1[w]=n then$pivLwickyType[w]=1else$pivLwickyType[w]=0endifendifendifif n-$pivLswingbix1[w]>500 or close<$pivLswingprc1[w] then$pivLactive[w]=0if $pivLconfirmed[w]=0 then$pivLswingbix1[w]=undefined$pivLswingprc1[w]=undefined$pivLswingbix2[w]=undefined$pivLswingprc2[w]=undefined$pivLopposbix1[w]=undefined$pivLopposprc1[w]=undefined$pivLopposbix2[w]=undefined$pivLopposprc2[w]=undefined$pivLwickybix1[w]=undefined$pivLwickyprc1[w]=undefined$pivLwickybix2[w]=undefined$pivLwickyprc2[w]=undefinedendifendifendifif islastbarupdate thenfor i=w downto 1 doif $pivLwickyType[i]=1 thendrawtext("SFT▲",$pivLopposbix2[i],$pivLopposprc2[i]-0.25*tr)coloured("GREEN")drawsegment($pivLswingbix1[i],$pivLswingprc1[i],$pivLswingbix2[i],$pivLswingprc2[i])style(line)coloured("green")drawsegment($pivLopposbix1[i],$pivLopposprc1[i],$pivLopposbix2[i],$pivLopposprc2[i])style(dottedline)coloured("green")elsif $pivLconfirmed[i]=1 thendrawtext("SFT",$pivLwickybix1[i],$pivLwickyprc1[i]-0.35*tr)coloured("GREEN")drawtext("▲",$pivLopposbix2[i],$pivLopposprc2[i]-0.25*tr)coloured("GREEN")drawsegment($pivLswingbix1[i],$pivLswingprc1[i],$pivLswingbix2[i],$pivLswingprc2[i])style(line)coloured("green")drawsegment($pivLopposbix1[i],$pivLopposprc1[i],$pivLopposbix2[i],$pivLopposprc2[i])style(dottedline)coloured("green")endif//---------------------------------if $pivHwickyType[i]=1 thendrawtext("SFT▼",$pivHopposbix2[i],$pivHopposprc2[i]+0.25*tr)coloured("RED")drawsegment($pivHswingbix1[i],$pivHswingprc1[i],$pivHswingbix2[i],$pivHswingprc2[i])style(line)coloured("red")drawsegment($pivHopposbix1[i],$pivHopposprc1[i],$pivHopposbix2[i],$pivHopposprc2[i])style(dottedline)coloured("red")elsif $pivHconfirmed[i]=1 thendrawtext("SFT",$pivHwickybix1[i],$pivHwickyprc1[i]+0.35*tr)coloured("RED")drawtext("▼",$pivHopposbix2[i],$pivHopposprc2[i]+0.25*tr)coloured("RED")drawsegment($pivHswingbix1[i],$pivHswingprc1[i],$pivHswingbix2[i],$pivHswingprc2[i])style(line)coloured("red")drawsegment($pivHopposbix1[i],$pivHopposprc1[i],$pivHopposbix2[i],$pivHopposprc2[i])style(dottedline)coloured("red")endifnextendif//--------------------------------------------------//return2 users thanked author for this post.
05/07/2025 at 9:29 PM #246883thank you very much, it’s perfect. the code is more complex than I thought. Do you think there is a chance to use vectors ofr automated trading? I tried in the past but I couldn’t develop anything. How do you make a simple strategy on it?
kind regards
Alessio
05/08/2025 at 10:14 AM #246895Arrays can actually be already used in automated strategies.
05/08/2025 at 12:23 PM #24690005/08/2025 at 3:20 PM #246904You can find some useful links at https://www.prorealcode.com/topic/arrays-help-any-documentation/#post-232284.
To build an array you don’t need any declaration, just begin using its elements and they will be added automatically. Their name must have a leading “$” and end with their index in square brackets. I usually start initializing them (when I am sure they have a fixed number of elements) on the very first bar, i.e. bar 0:
Fixed number of elements (10 in this case), initialized1234567// Initialization of the 10 ARRAY elementsONCE MaxElements = 10IF BarIndex = 0 THENFOR i = 1 TO MaxElements //you can start from 0, up to MaxElements - 1, if preferred$myArray[i] = 0NEXTENDIFThis is an array built at runtime, as I can’t predict the number of elements it may contain. LastSet is used to know the number of elements in the array (https://www.prorealcode.com/documentation/lastset/):
12345678910111213// check if there's at least a 10-pip GAP between the OPEN and the prior CLOSE// (within the first 1K bars), assigning its bar number to an array elementDEFPARAM DrawOnLastBarOnly = TruearrayIndex = 0FOR i = 0 TO 999 //let's start fromn 0, the current barIF abs(open[i] - close[i + 1]) >= 10*PipSize THEN$myArray[arrayIndex] = BarIndexarrayIndex = arrayIndex + 1ENDIFNEXTTotalElementsScanned = lastset($myArray) + 1 //add 1 as we started from 0DrawText("#arrayIndex# GAPS found over #TotalElementsScanned# bars scanned",BarIndex + 10, close)RETURN1 user thanked author for this post.
-
AuthorPosts