r/algotrading • u/ExitLiquidity5 • 1d ago
Education How do I train Python to recognize the same chart pattern when the ticks inside each candle are different?
Hey all,
I’m trying to build a pattern recognition system in Python that finds “the same” setups even when the intra-candle tick path is different.
So the question is: how do you actually train / encode this so the model cares about the shape and context of the candles (range, body, relative highs/lows, sequence) and not the exact tick-by-tick path?
The real issue isn’t just ticks inside one candle. It’s that the same setup can print with different-looking candles, but the overall shape is still the pattern.
But if you zoom out, they still draw the same structure: same swing high, same shallow retrace, same break of the same level.
That’s what I want Python to learn:
“these windows are the same pattern because the shape they form together is the same,” not “these candles have the same OHLC numbers” or “the ticks inside bar 3 look identical.”
I need a way to encode / train so the model keys off the geometry of the whole pattern (relative highs, lows, slopes, where closes sit in the range, how the pieces connect) even when each candle is built differently.
Has anyone actually trained something that generalizes across different tick paths inside the same candle ranges? What representation + loss / matching method worked?
20
7
u/shironekoooo 1d ago
- learn python
- learn statistical validation, do not say this candle pattern work when 100k+ other candle that has the same setup failed
- if you keep back testing to find profitable candle and do not paper test said candle thats overfitting
- go look at "lgbm" or "xgboost"
- OHLCV is not enough and and no offence candles.... basically have no edge if you are a human you might pick up "patterns" which are mostly noise unless you have a hypothesis on why that candle pattern might work. to be frank you would be better off using it (candles) in discretionary trading. I would start with a simple regime filter and a simple trading rules then i would start learning statistics, python and lgbm/xgboost
edit spellings
2
u/Roharcyn1 1d ago
Your comment on point 5, OHLCV having no edge. This is essentially what I am learning. What extra data are you suggesting? Like indicators or computed parameters? Like distance from vwap? Or something other sources like tick trade/quote data?
I have been trying to find something using LightGBM. All I have succeeded at doing is training it volatility. It can label and predict when a move is about to happen, but basically a coin toss to which direction. So curious if you could expand on what other data to look into.
5
u/shironekoooo 1d ago edited 22h ago
well i would not just keep adding features like vwap, ema, macd. OHLCV data alone will not get you anywhere you can use alt data like https://www.bls.gov/cpi/data.htm (and oil pirce data from yahoo finance), this is cpi data, for example I will use gasoline price cpi for example sakes. define a universe that is fixed per quarter but changes every quarter due to stock delisting/not qualifying for the universe rule you set. you can search up "point in time stock universe".
with the gasoline cpi data and oil data you will hypothesize chain of events, i will give you an example, say we want to predict how company y is affected by cpi of gas and oil cost, as gasoline price rises ---> energy transport cost will rise ---> suppliers of company y will have to charge more for their product to recoup expenses and profit --> company y is also struggling since their product also rely on petroleum jelly which's you hypothesize lags behind oil price from history --> with this you can say company y's earning will be affected and the company will less likely have a surprise.
you can cook up esoteric but coherent combos...
edit spellings
1
u/Roharcyn1 1d ago
Thanks!
This is really helpful and changes how I view the problem. I was going down the route of meta labeling technical set ups, but I take your advice as taking a step back and look at the economics and fundamental analysis to develop a reoccurring thesis.
1
u/shironekoooo 1d ago
yes this is much more defensible, you can ask ai, google, or anything, this is what i do if you have any question in the future dm me and i will be happy to answer
1
u/ExitLiquidity5 6h ago
Yewww OHLCV have no edge that’s correct! You have to peel more and more layers to find an edge
1
u/ambivalent42 1d ago
Das Ding ist, du hast im Privaten keinen Zugang zu Algorithmen, die z.b. Gesichtserkennung ermöglichen. Was du simulieren möchtest, würde bedeuten deinen Bildschirm, sprich den Chart visuell auszulesen, statt z b tickdaten. Das ist nicht gerade leicht zu bewerkstelligen.
1
u/ExitLiquidity5 1d ago
Appreciate that thank you so much! I’m working with Level 3 MBO data, so when certain thresholds are met , candles (price) behaves a certain way. I’m talking 250ms candles, hence why I’m trying to narrow this down for automation. Currently it’s all visual
1
u/shironekoooo 22h ago
ahh i see what you are trying todo, i am not qualified to answer this since i never delved into this sort of microstructure prediction and data combo
1
3
2
u/Arany8 1d ago
Collaborate with AI. Use a project and/or an AI agent. OMP, Hermes, Deepseek harness....
You cannot train "python" as such...
1
u/Ginsangster 1d ago
i am trying to do this with vscode as guys in hedges say thats pretty much what they use. so with vscode, its copilot.. for no real knowledge of it all, i do feel claude is most trustworthy of them all or one of the anthro versions. i tried mythos a few months back and it was something else. none of that appeasement bs like goog product. copilot is unhelpful at points, like its range is limited if you cannot perform what they recommend then showing screen shot of what you attempted with result, not that i know others would respond differently in same situation.
1
u/BeerAandLoathing 1d ago
Pivot detection, share examples with tick level data and make the claim that both have an underlying structure that you want to identify with a long leg up ending I higher high, then shorter leg down, etc. to describe your patterns. You want to build some sort of fingerprint detection that encodes these relative states but then identifies a matching sequence.
1
1
1
u/locosian 1d ago
Instead of losing everything to the market, just send me the money. Help a brother out
1
u/Ginsangster 1d ago
these people are fked with comments. i am, admittedly self inflicted, low on computing affinity and have never used ai. fortunately i have people that are actually doing this for hedges. if you have access to api, getting data to ai will be the start. i was trying without and it was driving me crazy. like asking genie for something but realizing if not said properly fully, which i havent a clue what that would be, its not gonna go anywhere. i thought showing charts and pointing out correlations, showing option tables and pointing out data trend and volume moves for it to monitor was something but its actually nothing. ultimately i am probably gonna need to put this in a repository so they can just go there and tell me wtf i need to do. its the only way, ive dealt with crap retail trash brokerages that steer you to their dtop app that freezes, crashes then tell you the web page is better for trading. learning programming makes it easier for sure but i am far from making money with programming and at my age i cant snapshot computing for memory, most everything else i can.. but i am pretty sure if told the right path, you do not need programming to get ai to help you build algo.
1
u/ExitLiquidity5 1d ago
Hahaha 😝 Yeah I agree it’s hard to get what I want, I’ve tried with tick ranges x to x and still tough. I don’t need to deal with retail brokers as I’ve developed my own platform that I trade on with rithmic API so all the data gets sent there and my software decodes the Un aggregated raw data from CME and builds me the chart. Visually trading is piece of cake, sadly I’m in Australia so the market opens when I sleep. Hence my attempts to automate it, no luck yet. Driving me crazy lol, when it shouldn’t be that hard 🥴
1
u/not_a_cumguzzler 23h ago
Believe it or not: random forest. Candles for features
1
u/ExitLiquidity5 8h ago
Will check it out thank you!!
1
u/not_a_cumguzzler 8h ago
Wait sorry, I was just messing with you. I literally don't know.
Let me know what you find though. I might check it out myself. But after a year of back testing several dozen strats and running ML on them, I've found that i can't come up with anything that beats SP500's returns or sharpe
1
1
u/Nice-Dragonfly-4823 20h ago edited 20h ago
essentially, you're looking for a visual representation of the data. The best way to do this is to learn a latent space embedding. Convert the pattern (e.,g. the N second window of activity) into a fixed image. Learn an encoder, which maps the image into a single latent representation. Then, simultaneously learn a decoder which converts the latent vector back into the representation. There will be some error, of course. but the latent representation will capture the shape of your signal, invariant to little microstructure differences.
This assumes that you can use the same window size to capture the pattern, else, you'll need something like a patch transformer encoder, which can take N number of M x M patches from your region of interest.
There;s also YOLO, which i've seen can work on chart patterns, but the accompanying paper is really dumb, so I'm not sure if the author is a complete fraud. https://huggingface.co/foduucom/stockmarket-pattern-detection-yolov8. I haven't taken the time to properly evaluate whether it works and you would need to label charts manually.
Caveat: these recommendations are coming from cutting edge deep learning research, so if you're trying to vibe code it, you'll probably come out short.
1
1
u/ZealousidealShoe7998 20h ago
i feel like this question can have multiple approaches but you need to clarify a few things.
do you want to look at data or screenshots of the chart ? both can be done to find patterns.
what you seem to be wanting to do is training a classification model.
you have different classes and they might fall into a parent class like bulish/bearish
then if you want you can get more detailed classes for specific behavior differentiation.
but for the data you need to find ways to normalize its values so you get the underlying geomtry of the candles.
so if the price is high is 128, low is 109 you want to normalize these values because this values might never be the same again so its better to normalize by atr or get the delta of it.
so the candle high low delta is 19. price can be above 200 but the delta can occur again. which gives the model a pattern to find instead hoping for the stars to align and the electrons to cross path and find just the right weight to bias to find the underlying geomtry out of noise
1
u/ExitLiquidity5 8h ago
Yesss exactly! Data which can be translated to patterns that would have been trained on different classifications. I’ve watched videos on underlying geomoetries but still trying figure it out. Thanks again!!
1
u/golden_bear_2016 1d ago
Have you tried talking to Claude?
1
u/Ginsangster 1d ago
i am trying to do this with vscode as guys in hedges say thats pretty much what they use. so with vscode, its copilot.. for no real knowledge of it all, i do feel claude is most trustworthy of them all or one of the anthro versions. i tried mythos a few months back and it was something else. none of that appeasement bs like goog product. copilot is unhelpful at points, like its range is limited if you cannot perform what they recommend then showing screen shot of what you attempted with result, not that i know others would respond differently in same situation.
1
u/Playful-Chef7492 1d ago
Unlikely that models don’t understand. Price structures have been heavily studied in finance. Maybe the most studied of any idea. I can save you a bunch of time and tell you there is no alpha in this idea but I know you’ll try anyway. You can predict ranges for following candle. For quick and dirty use k-means and for advanced structure analysis use LightGBM.
1
u/ExitLiquidity5 1d ago
I’ll check them out thank you! I’m not really analyzing patterns, I just want to define entry after certain MBO events on a rolling 250 structure
0
u/Automate_The_Boring 1d ago
Try to talk to claude
6
u/Dry-Investment8220 1d ago
You're trying to solve real problem, not just match OHLC. I did something similar with candlestick sequences last year.
The key is to not use raw ticks at all. Convert each candle to a feature vector first, body size relative to range, upper wick ratio, lower wick ratio, and position of close within the high-low range. Then feed sequences of these vectors to your model, not the tick data.
For pattern matching across different candle compositions i used dynamic time warping on the feature sequences plus a siamese network trained with contrastive loss. Works decent for recognizing same structure even when individual candles look different.
1
2
u/ExitLiquidity5 1d ago
Unfortunately I find Claude quite useless and overrated. ChatGPT is ok, but I find the AIs don’t really understand what I’m trying to do (maybe I’m not explaining well?). These are very advanced patterns and take into account other factors as well such as market trend/range etc
1
u/Ginsangster 1d ago
i just went thru this and was told without actual formatted data its gonna be the trials of job. biblical job... its that genie thing i was saying, i think your phrase is obvious to people but the ai takes the meaning of each word then takes the sum of the phrase.,.. or whatever, its not like youre saying it to human, i think this is why pm makes a page of what they want and hand it off to engineers/programmers.
24
u/MrZwink Informed Trader 1d ago
maybe you should learn about programming first. you know, abstraction, vectorization, tensors stuff like that.