TradingView
racer8
Jan 18, 2021 11:24 PM

Pattern Recognition Probabilities [racer8]Β 

E-mini S&P 500 FuturesCME

Description

β‹…
Brief 🌟
Pattern Recognition Probabilities (PRP) is a REALLY smart indicator. It uses the correlation coefficient formula to determine if the current set of bars resembles that of past patterns. It counts the number of times the current pattern has occurred in the past and looks at how it performed historically to determine the probability of an up move, down move, or neutral move.

I'd like to say, I'm proud of this indicator πŸ˜†πŸ€™ This is the SMARTEST indicator I have ever made 🧠🧠🧠

Note: PRP doesn't give you actual probabilities, but gives you instead the historical occurrences of up, down, and neutral moves that resulted after the pattern. So you can calculate probabilities based on these valuable statistics. So for example, PRP can tell you this pattern has historically resulted in 55 up moves, 20 down moves, and 60 neutral moves.

Parameters 🌟
You can adjust the Pattern length, Minimum correlation, Statistics lookback, Exit after time, and Atr multiplier parameters.
Pattern length - determines how long the pattern is
Minimum correlation - determines the minimum correlation coefficient needed to pass as a similiar enough pattern.
Statistics lookback - lookback period for gathering all the patterns in the past.
Exit after time - determines when exit occurred (number of periods after pattern) ; is the point that represents the pattern's result.
Atr multiplier - determines minimum atr move needed to qualify whether result was an up/down move or a neutral move. If a particular historical pattern resulted in a move that was less than the min atr, then it is recorded as a neutral move in the statistics.

Thanks for reading! πŸ™
Good luck πŸ€ Stay safe 😷 Drink lots of waterπŸ’§
Enjoy! πŸ₯³ and Hit the like button! πŸ‘

Release Notes

β‹…
After receiving feedback about how slow the script loads, I've decided to change the default parameters so that it loads faster. Enjoy ;)
Comments
burgercrisis
β‹…
Hope you know how amazing this is! I made a small conversion to your code -
My mod checks for predictive capability of both a source input and closing price, then checks the correlation between those two predictive capabilities. Sort of like very basic machine learning! Its like an auto-adjusting backtest! Slapped strategy stuff on it - amazing work. Really. And I've so far only tested it on "Function Geometric Moving Average" (500 length) so far haha... and it already looks good. Ridiculous. Kudos. If this makes me not poor you get a chunk, sir!

THIS MAY BE A MONEY PRINTER IN THE RIGHT HANDS
haddy7
β‹…
@burgercrisis, have you published it? thanks
burgercrisis
β‹…
@haddy7, I have not, I think the idea has potential but what I realized is that either need more lookback length then TV allows to have truly lasting results, or the ability to do a few more comparison calculations, but TV script caps out before it gets really good. So rather, someone with Python skill should apply the concept there with thousands of bars of 5min charts IMO. I suppose any time some (especially me) is this excited about something, take it with a grain of salt... TV would not allow anything so amazing on their platform ;)
I want to learn Python... So many of my best ideas were beyond TVs ability in terms of how much computation TV is capable of, or how much of that code limit I had to waste on teaching it things it should know, thus limiting the actual strategy or at the very least slowing load time down considerably.

Also I only publish editted scripts if the OP grants access, per TV rules. I didn't PM him but he probably wasn't too enthused when he saw my comment cause he knew that TV has limits and I was in a pipedream ahaha, happens
racer8
β‹…
@burgercrisis, ahaha :D May your luck persist!
burgercrisis
β‹…
@racer8, Hahaha, turns out TV simply doesn't have enough power to have a lasting and self-regulating "machine learning" strategy on here lmao... It is a great concept though and if I ever learn Python I will apply it there. Who says machine learning and TA can't get along?

Since then I've gone back to my old bot work lol. I'm basically running several basic single-indicator strats right now while I build a filter library that I will apply to them. Right now they're doing pretty good though! I have 7 running on BTC and 7 running on LINK, and right now almost all of them are at or near peaking profit and when some of them are weaker the rest tend to do a good job hedging against that.

I think if we could graph our "luck" as traders, it would probably look much like the charts we trade! hahah, sometimes I think the most important thing for a trader is just knowing when to retire :P
stevenwalter0
β‹…
So creative, looks great!
racer8
β‹…
@stevenwalter0, always a pleasure :)
lukricky
β‹…
dear racer, i personally further amend your great code , Pattern Recognition Probabilities the smart indicator so far and i add the buy sell signal, volume threshold parameter
i am trying to fit into the lower time frame scalping usage, any comments you can make ?

Pattern Recognition Probabilites

//@version=4
study("Pattern Recognition Probabilities with Volume Threshold", "PRP πŸ’™", precision=0)

n = input(12, "Pattern length")
mc = input(0.50, "Minimum correlation")
sl = input(500, "Statistics lookback")
re = input(6, "Exit after time")
m = input(1.0, "ATR multiplier")
v = input(100000, "Volume threshold") // Set the volume threshold value here

sum = 0.0
up = 0.0
dn = 0.0
no = 0.0
cc = 0.0
pt2 = 0.0
pta = 0.0
ptb = 0.0
ch = 0.0
cl = 0.0
vol = 0.0 // Define the 'vol' variable here

for i = n to sl
cc := correlation(close, close, n)
ch := correlation(high, high, n)
cl := correlation(low, low, n)
pt2 := hl2
pta := hl2 + m * atr(8)
ptb := hl2 - m * atr(8)
vol := volume // Get the current volume value

if cc >= mc and ch >= mc and cl >= mc and vol >= v // Check if the current volume is greater than or equal to the volume threshold
sum := sum + 1
if cc >= mc and ch >= mc and cl >= mc and vol >= v and pt2 >= pta
up := up + 1
if cc >= mc and ch >= mc and cl >= mc and vol >= v and pt2 <= ptb
dn := dn + 1
if cc >= mc and ch >= mc and cl >= mc and vol >= v and pt2 < pta and pt2 > ptb
no := no + 1

buy = crossover(up, dn)
sell = crossover(dn, up)

alertcondition(buy, title="Buy Alert", message="Buy Alert")
alertcondition(sell, title="Sell Alert", message="Sell Alert")

plot(up, "Up", color=color.green)
plot(dn, "Dn", color=color.red)
plot(no, "Neutral", color=color.gray)

bgcolor(buy ? color.green : sell ? color.red : na, transp=70)

Reply
lukricky
β‹…
can it work on the lower time frame such as 5 mins or 15 mins ?
rakesh2574
β‹…
This is absolutely an amazing concept.
I have been thinking in same pattern for a while ..
Great
More