I'm trying to create a script that, from standard OHLC data, finds patterns. The specific pattern i'm looking for right now is sideways movement after a move up, here is an example:
So basically my code should detect when price is inside a box like the ones above.
I know this is not easy to do and i'm not looking for someone to give their code, i just need some help finding a general direction or some sources/library on this matter, if there is any.
My idea was the following: detect when price is rising, and if price, after rising, starts moving between an X and Y interval (so without going too much up or down), label it as a range (which is what i'm looking for). I think this should work, but i have no idea how to put that down in code.
Here is what i have:
import copy import urllib import numpy as np import pandas as pd import cfscrape import json import datetime from datetime import datetime as dt BU = cfscrape.create_scraper() URL = "https://api.binance.com/api/v1/klines?&symbol=ADABTC&interval=1h&limit=250" ResultRaw = BU.get(URL, timeout=(10, 15)).content Result = json.loads(ResultRaw) for x in Result: TimeUnix = float(x[0]) / float(1000) K = datetime.datetime.fromtimestamp(TimeUnix) x[0] = K Variation = Result.index(x) Previous = Variation-1 Variation = ((float(x[4])-float(x[1]))/float(x[1]))*100 print(Variation) df = pd.DataFrame([x[:6] for x in Result], columns=['Date', 'Open', 'High', 'Low', 'Close', 'Volume']) format = '%Y-%m-%d %H:%M:%S' df['Date'] = pd.to_datetime(df['Date'], format=format) df = df.set_index(pd.DatetimeIndex(df['Date'])) df["Open"] = pd.to_numeric(df["Open"],errors='coerce') df["High"] = pd.to_numeric(df["High"],errors='coerce') df["Low"] = pd.to_numeric(df["Low"],errors='coerce') df["Close"] = pd.to_numeric(df["Close"],errors='coerce') df["Volume"] = pd.to_numeric(df["Volume"],errors='coerce') Here is what i'm doing:
- Retrieve data
- Make it JSON data
- For every row, determine how much the price changed in terms of percentage, this is what
Variationdoes - Make it a Pandas dataframe
Any kind of help is appreciated!
