ProRealCode - Trading & Coding with ProRealTime™
////////////////////////////////////////////////////
//
// Wing's Prophecy Boot version 0.1 - (Pattern Matching indicator)
//
// Made by user "Wing" of ProRealCode.com
// https://www.prorealcode.com/user/wing/
//
//////////////////////////////////////////////////
//
// Parameters:
sep=92 // Number of bars between each pattern match. Should be equivalent to the amount of bars per day. Roughly 47 for 30m TF, 92 for 15m etc
starttime=090000 // What time each day to compare current pattern to previous days
fut= 16 // How many bars from best pattern match to look forward and see if pattern results in price increase/decrease. Must be less than 'sep'.
hindsight=95 // Number of days to look back. DO NOT CHANGE THIS PARAMETER unless you receive an error message. Generally, it can't look back more than 100 days.
//////////////////////////////////////////////////
best=0
waw=barindex
tbest=100000
tbest2=100000
tbest3=100000
lo=lowest[10](close)
cl=close
if time=starttime then
sep2=sep
if time[(sep-4)]=starttime then
sep2=sep-4
elsif time[(sep-3)]=starttime then
sep2=sep-3
elsif time[(sep-2)]=starttime then
sep2=sep-2
elsif time[(sep-1)]=starttime then
sep2=sep-1
elsif time[(sep+1)]=starttime then
sep2=sep+1
elsif time[(sep+2)]=starttime then
sep2=sep+2
elsif time[(sep+3)]=starttime then
sep2=sep+3
elsif time[(sep+4)]=starttime then
sep2=sep+4
endif
waw=waw-sep2
FOR i = hindsight DOWNTO 0 DO
best=(0.01*(square((cl-lo)-(cl[barindex-waw]-lo[barindex-waw]))+square((cl[1]-lo)-(cl[barindex-waw+1]-lo[barindex-waw]))+square((cl[2]-lo)-(cl[barindex-waw+2]-lo[barindex-waw]))+square((cl[3]-lo)-(cl[barindex-waw+3]-lo[barindex-waw]))+square((cl[4]-lo)-(cl[barindex-waw+4]-lo[barindex-waw]))+square((cl[5]-lo)-(cl[barindex-waw+5]-lo[barindex-waw]))+square((cl[6]-lo)-(cl[barindex-waw+6]-lo[barindex-waw]))+square((cl[7]-lo)-(cl[barindex-waw+7]-lo[barindex-waw]))+square((cl[8]-lo)-(cl[barindex-waw+8]-lo[barindex-waw]))+square((cl[9]-lo)-(cl[barindex-waw+9]-lo[barindex-waw]))))
if best<tbest then
tbest=best
ind=cl[barindex-waw-fut]-cl[barindex-waw]
elsif best<tbest2 then
tbest2=best
ind2=cl[barindex-waw-fut]-cl[barindex-waw]
elsif best<tbest3 then
tbest3=best
ind3=cl[barindex-waw-fut]-cl[barindex-waw]
endif
sep2=sep
if time[barindex-(waw-(sep-4))]=starttime then
sep2=sep-4
elsif time[barindex-(waw-(sep-3))]=starttime then
sep2=sep-3
elsif time[barindex-(waw-(sep-2))]=starttime then
sep2=sep-2
elsif time[barindex-(waw-(sep-1))]=starttime then
sep2=sep-1
elsif time[barindex-(waw-(sep+1))]=starttime then
sep2=sep+1
elsif time[barindex-(waw-(sep+2))]=starttime then
sep2=sep+2
elsif time[barindex-(waw-(sep+3))]=starttime then
sep2=sep+3
elsif time[barindex-(waw-(sep+4))]=starttime then
sep2=sep+4
endif
waw=waw-sep2
if waw<200 then
i=0
endif
next
endif
goer1=0
goer2=0
goer3=0
goer1=(ind/square(tbest))
goer2=(ind2/square(tbest2))
goer3=(ind3/square(tbest3))
goerz=goer1+goer2+goer3
return goerz
////////////////////////////////////////////////////
//
// Wing's Prophecy Boot version 0.1 - (Pattern Matching indicator)
//
// Made by user "Wing" of ProRealCode.com
// https://www.prorealcode.com/user/wing/
//
//////////////////////////////////////////////////
//
// Parameters:
sep=92 // Number of bars between each pattern match. Should be equivalent to the amount of bars per day. Roughly 47 for 30m TF, 92 for 15m etc
starttime=090000 // What time each day to compare current pattern to previous days
fut= 16 // How many bars from best pattern match to look forward and see if pattern results in price increase/decrease. Must be less than 'sep'.
hindsight=95 // Number of days to look back. DO NOT CHANGE THIS PARAMETER unless you receive an error message. Generally, it can't look back more than 100 days.
//////////////////////////////////////////////////
best=0
waw=barindex
tbest=100000
tbest2=100000
tbest3=100000
lo=lowest[10](close) // Set a base line. Each sequence is compared by placing their lowest close on the same level.
cl=close
if time=starttime then
// correct the day separator, so the right time is compared. Some days can have 98 bars, others 96 bars etc.
sep2=sep
if time[(sep-4)]=starttime then
sep2=sep-4
elsif time[(sep-3)]=starttime then
sep2=sep-3
elsif time[(sep-2)]=starttime then
sep2=sep-2
elsif time[(sep-1)]=starttime then
sep2=sep-1
elsif time[(sep+1)]=starttime then
sep2=sep+1
elsif time[(sep+2)]=starttime then
sep2=sep+2
elsif time[(sep+3)]=starttime then
sep2=sep+3
elsif time[(sep+4)]=starttime then
sep2=sep+4
endif
waw=waw-sep2
// Check each day
FOR i = hindsight DOWNTO 0 DO
// compare each sequence to the current one, and create an accuracy score. The lower score the better
best=(0.01*(square((cl-lo)-(cl[barindex-waw]-lo[barindex-waw]))+square((cl[1]-lo)-(cl[barindex-waw+1]-lo[barindex-waw]))+square((cl[2]-lo)-(cl[barindex-waw+2]-lo[barindex-waw]))+square((cl[3]-lo)-(cl[barindex-waw+3]-lo[barindex-waw]))+square((cl[4]-lo)-(cl[barindex-waw+4]-lo[barindex-waw]))+square((cl[5]-lo)-(cl[barindex-waw+5]-lo[barindex-waw]))+square((cl[6]-lo)-(cl[barindex-waw+6]-lo[barindex-waw]))+square((cl[7]-lo)-(cl[barindex-waw+7]-lo[barindex-waw]))+square((cl[8]-lo)-(cl[barindex-waw+8]-lo[barindex-waw]))+square((cl[9]-lo)-(cl[barindex-waw+9]-lo[barindex-waw]))))
// save the three best matches
if best<tbest then
tbest=best
ind=cl[barindex-waw-fut]-cl[barindex-waw]
elsif best<tbest2 then
tbest2=best
ind2=cl[barindex-waw-fut]-cl[barindex-waw]
elsif best<tbest3 then
tbest3=best
ind3=cl[barindex-waw-fut]-cl[barindex-waw]
endif
sep2=sep
if time[barindex-(waw-(sep-4))]=starttime then
sep2=sep-4
elsif time[barindex-(waw-(sep-3))]=starttime then
sep2=sep-3
elsif time[barindex-(waw-(sep-2))]=starttime then
sep2=sep-2
elsif time[barindex-(waw-(sep-1))]=starttime then
sep2=sep-1
elsif time[barindex-(waw-(sep+1))]=starttime then
sep2=sep+1
elsif time[barindex-(waw-(sep+2))]=starttime then
sep2=sep+2
elsif time[barindex-(waw-(sep+3))]=starttime then
sep2=sep+3
elsif time[barindex-(waw-(sep+4))]=starttime then
sep2=sep+4
endif
waw=waw-sep2
if waw<200 then
i=0
endif
next
endif
goer1=0
goer2=0
goer3=0
// the three best matches. the price change is divided by the preceding sequence's similarity to current sequence. A low similarity score means more similarity, which results in a stronger signal.
goer1=(ind/square(tbest))
goer2=(ind2/square(tbest2))
goer3=(ind3/square(tbest3))
// add the three best matches together, for a better prediction
goerz=goer1+goer2+goer3
return goerz
// compare each sequence to the current one, and create an accuracy score. The lower score the better
//best=(0.01*(square((cl-lo)-(cl[barindex-waw]-lo[barindex-waw]))+square((cl[1]-lo)-(cl[barindex-waw+1]-lo[barindex-waw]))+square((cl[2]-lo)-(cl[barindex-waw+2]-lo[barindex-waw]))+square((cl[3]-lo)-(cl[barindex-waw+3]-lo[barindex-waw]))+square((cl[4]-lo)-(cl[barindex-waw+4]-lo[barindex-waw]))+square((cl[5]-lo)-(cl[barindex-waw+5]-lo[barindex-waw]))+square((cl[6]-lo)-(cl[barindex-waw+6]-lo[barindex-waw]))+square((cl[7]-lo)-(cl[barindex-waw+7]-lo[barindex-waw]))+square((cl[8]-lo)-(cl[barindex-waw+8]-lo[barindex-waw]))+square((cl[9]-lo)-(cl[barindex-waw+9]-lo[barindex-waw]))))
barstocompare=11
result=0
for a = 0 to barstocompare do
result = result+square((cl[a]-lo)-(cl[barindex-waw+a]-lo[barindex-waw]))
next
best = 0.01*result
I fell into the infinite loop bug of the platform if I set “barstocompare” to 20, only tested 11, currently testing more bars. Is it still accurate for you? Maybe adding this code into an external indicator as a function would reduce the phenomena.
edit: 15 bars is workings ok.
So far I am unsure if pattern matching works. On the 15/30m timeframe I can create an edge in DAX. But the system has many moving parts (variables) that make biases and over-optimization a risk. It seems it works best on indices though. My next move will be to investigate if it can perform in equities and maybe on new timeframes.
Describe what this topic is trying to build, in plain English, and ProRealAI writes the ProRealTime™ indicator, screener or system for you.
Pattern matching price movements in PRT – machine learning
This topic contains 18 replies,
has 1 voice, and was last updated by Khaled
4 years, 8 months ago.
| Forum: | ProBuilder: Indicators & Custom Tools |
| Language: | English |
| Started: | 02/03/2017 |
| Status: | Active |
| Attachments: | 1 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.