ProRealCode - Trading & Coding with ProRealTime™
I add the youtube link where I found it.
thanks
Hi Ivan, Hi JS,
anyone can help me?please!
You asked for a conversion just 3 days ago, be patient a few more days. Thanks 🙂
Hi, here is the code:
//--------------------------------------------------//
// PRC_Swing failure Pattern
//version = 0
//07.05.2025
//Iván González @ www.prorealcode.com
//Sharing ProRealTime knowledge
//--------------------------------------------------//
// Inputs
//--------------------------------------------------//
len=5
bull=1
bear=1
n=barindex
//--------------------------------------------------//
// Pivot High-Low calculation
//--------------------------------------------------//
src1 = low
src2 = high
leftbars=len
rightbars=1
//--- Pivots low
if 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+1
endif
//--- Pivots high
if 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+1
endif
//--------------------------------------------------//
// Bearish Pattern
//--------------------------------------------------//
if bear then
if t<>t[1] then
$swingHbix[s+1]=$phx[t]
$swingHprc[s+1]=$phy[t]
s=s+1
endif
sw=$swingHprc[s]
bx=$swingHbix[s]
if high>sw and open<sw and close<sw then
opposL=sw
opposB=n
for i=1 to n-bx-1 do
if low[i]<opposL then
opposL=low[i]
opposB=n-i
endif
next
if $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]=undefined
endif
$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]=sw
w=w+1
endif
if $pivHactive[w]=1 and $pivHconfirmed[w]=0 then
$pivHswingbix2[w]=n
$pivHopposbix2[w]=n
if close < $pivHopposprc1[w] then
$pivHconfirmed[w]=1
if $pivHwickybix1[w]=n then
$pivHwickyType[w]=1
else
$pivHwickyType[w]=0
endif
endif
endif
if n-$pivHswingbix1[w]>500 or close>$pivHswingprc1[w] then
$pivHactive[w]=0
if $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]=undefined
endif
endif
endif
//--------------------------------------------------//
// Bullish Pattern
//--------------------------------------------------//
if bull then
if z<>z[1] then
$swingLbix[q+1]=$plx[z]
$swingLprc[q+1]=$ply[z]
q=q+1
endif
sw=$swingLprc[q]
bx=$swingLbix[q]
if low<sw and open>sw and close>sw then
opposH=sw
opposBH=n
for i=1 to n-bx-1 do
if high[i]>opposH then
opposH=high[i]
opposBH=n-i
endif
next
if $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]=undefined
endif
$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]=sw
w=w+1
endif
if $pivLactive[w]=1 and $pivLconfirmed[w]=0 then
$pivLswingbix2[w]=n
$pivLopposbix2[w]=n
if close > $pivLopposprc1[w] then
$pivLconfirmed[w]=1
if $pivLwickybix1[w]=n then
$pivLwickyType[w]=1
else
$pivLwickyType[w]=0
endif
endif
endif
if n-$pivLswingbix1[w]>500 or close<$pivLswingprc1[w] then
$pivLactive[w]=0
if $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]=undefined
endif
endif
endif
if islastbarupdate then
for i=w downto 1 do
if $pivLwickyType[i]=1 then
drawtext("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 then
drawtext("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 then
drawtext("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 then
drawtext("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")
endif
next
endif
//--------------------------------------------------//
return
thank 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
Arrays can actually be already used in automated strategies.
Can I please ask an example here how to use it? I’ve developed in general strategies but with arrays I’m still struggling.
thanks in advance
You 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:
// Initialization of the 10 ARRAY elements
ONCE MaxElements = 10
IF BarIndex = 0 THEN
FOR i = 1 TO MaxElements //you can start from 0, up to MaxElements - 1, if preferred
$myArray[i] = 0
NEXT
ENDIF
This 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/):
// 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 element
DEFPARAM DrawOnLastBarOnly = True
arrayIndex = 0
FOR i = 0 TO 999 //let's start fromn 0, the current bar
IF abs(open[i] - close[i + 1]) >= 10*PipSize THEN
$myArray[arrayIndex] = BarIndex
arrayIndex = arrayIndex + 1
ENDIF
NEXT
TotalElementsScanned = lastset($myArray) + 1 //add 1 as we started from 0
DrawText("#arrayIndex# GAPS found over #TotalElementsScanned# bars scanned",BarIndex + 10, close)
RETURN
‘Swing Failure Pattern
This topic contains 8 replies,
has 3 voices, and was last updated by
robertogozzi
9 months ago.
| Forum: | ProBuilder: Indicators & Custom Tools |
| Language: | English |
| Started: | 05/03/2025 |
| Status: | Active |
| Attachments: | No files |
The information collected on this form is stored in a computer file by ProRealCode to create and access your ProRealCode profile. This data is kept in a secure database for the duration of the member's membership. They will be kept as long as you use our services and will be automatically deleted after 3 years of inactivity. Your personal data is used to create your private profile on ProRealCode. This data is maintained by SAS ProRealCode, 407 rue Freycinet, 59151 Arleux, France. If you subscribe to our newsletters, your email address is provided to our service provider "MailChimp" located in the United States, with whom we have signed a confidentiality agreement. This company is also compliant with the EU/Swiss Privacy Shield, and the GDPR. For any request for correction or deletion concerning your data, you can directly contact the ProRealCode team by email at privacy@prorealcode.com If you would like to lodge a complaint regarding the use of your personal data, you can contact your data protection supervisory authority.