martedì 12 maggio 2020

PYTHON - AI SEE THE GRAPHIC PATTERNS

A prototype script that "sees" the configuration of graphic patterns. For now it only works on the pattern cup.
Download the data from Binance, draw the price line and compare it with the standard cup image.

#Riconoscimento pattern grafici tramite AI
#Porcari Daniele's code

from PIL import Image, ImageFilter
import imagehash
import matplotlib.pyplot as plt
import requests
import json

def binanceList(coppia,intervallo,limite):
    coppia=coppia.upper()
    indirizzo='https://fapi.binance.com/fapi/v1/klines?symbol='+coppia+'&interval='+intervallo+'&limit='+limite
    r=requests.get(indirizzo)
    file=r.text
    lista=json.loads(file)
    x=[]
    y=[]
    for i in range(len(lista)):
        x.append(lista[i][0])
        y.append(float(lista[i][4]))
    return x,y

def disegnaGrafico(x,y,asset):
    ok=False
    fig=plt.figure(figsize=(14,14))
    plt.plot(x,y,color='black')
    nome=asset+".png"
    plt.savefig(nome)
    return nome

def togliCornice(immagine,asset):
    ok=False
    img=Image.open(immagine)
    w,h=img.size
    l=180
    t=172
    r=w-159
    b=h-163
    nome=asset+"pronta.png"
    img.crop((l, t, r, b)).save(nome)
    img.close()
    return nome

def confronto(attuale,base,base2):
    tazza=True
    img = Image.open(base)
    image_one_hash = imagehash.whash(img)
    img2 = Image.open(attuale)
    image_two_hash = imagehash.whash(img2)
    similarity = image_one_hash - image_two_hash
    img.close()
    if similarity>20:
        img=Image.open(base2)
        image_one_hash = imagehash.whash(img)
        similarity2 = image_one_hash - image_two_hash
        if similarity>similarity2:
            similarity=similarity2
        tazza=False
    img.close()
    img2.close()
    return similarity,tazza

def confrontoTestaSpalle():
    ok=False
    return ok


linea=['BTCUSDT',
'LINKUSDT',
'BATUSDT',
'VETUSDT',
'TRXUSDT',
'ETHUSDT',
'BCHUSDT',
'LTCUSDT',
'XRPUSDT',
'EOSUSDT',
'ETCUSDT',
'XTZUSDT',
'BNBUSDT',
'ADAUSDT',
'NEOUSDT',
'XLMUSDT',
'DASHUSDT',
'ZECUSDT',
'XMRUSDT',
'ATOMUSDT',
'ONTUSDT',
'IOTAUSDT',
'QTUMUSDT',
'IOSTUSDT']

for i in range(len(linea)):
    print(linea[i])
    x,y=binanceList(linea[i],'4h','50')
    nomeGraf=disegnaGrafico(x,y,linea[i])
    grafOk=togliCornice(nomeGraf,linea[i])
    similarity,cup=confronto(grafOk,'tazza.png','tazza2.png')
    if cup==True:
        print("Possibile tazza ",similarity," - ",linea[i])
    else:
        print(similarity," - ",linea[i])

Copy and save the following images with the name of: cup.png and cup2.png
If you like the blog remember that you can support my work by donating cryptocurrencies to the addresses at the top right or at this link go fund me



Nessun commento:

Posta un commento