Visualizzazione post con etichetta trading. Mostra tutti i post
Visualizzazione post con etichetta trading. Mostra tutti i post

sabato 2 maggio 2020

PYTHON - AI TESTING BOT TRADING SIGNALS

Some signals from the BOT that I am testing. It is not my responsibility to use these signals; the use of these signs is at your own risk. I remember that trading is a high risk investment and it is possible to lose all the capital invested.
BATUSDT Binance

03/05/2020   06:47:01
BATUSDT   DAY   10   1
23-Apr-20
Op:  Buy  Prezzo:  0.1914 
TP1: 0.20450  TP2: 0.19795  TP3: 0.19577
Il prezzo è tra 0.19610  e 0.18680 
The BOT I am testing has calculated an upward trend and proposes a long operation with three possible targets. It also indicates the price between which resistances and support. 

Same reading of the BOT signals on the next pairs 

03/05/2020   06:47:01
LINKUSDT   DAY   10   1
23-Apr-20
Op:  Buy  Prezzo:  3.824 
 TP1: 3.99728  TP2: 3.91064  TP3: 3.88176
Il prezzo è tra 3.83657  e 3.68133  vicino al livello massimo

03/05/2020   06:47:01
TRXUSDT   DAY   10   1
23-Apr-20
Op:  Buy  Prezzo:  0.01642 
 TP1: 0.01762  TP2: 0.01702  TP3: 0.01682
Il prezzo è tra 0.01740  e 0.01630 
03/05/2020   06:47:01
VETUSDT   DAY   10   1
23-Apr-20
Op:  Buy  Prezzo:  0.004557 
 TP1: 0.00484  TP2: 0.00470  TP3: 0.00465
Il prezzo è tra 0.00464  e 0.00439 
 
 
03/05/2020   07:16:54
BTCUSDT   DAY   10   1
23-Apr-20
Op:  Buy  Prezzo:  9101.81 
TP1: 9489.80920  TP2: 9295.80960  TP3: 9231.14307
Il prezzo è tra 9250.95667  e 8480.50333 

domenica 19 aprile 2020

PYTHON - MACD ALGORITHM

MACD is a momentum indicator. This algorithm will search for the divergences between price and indicator independently. It will find the trend automatically and then look for convergence.
Here you can see the script that builds only the MACD.

The vectorMA function builds the two moving average lists that will be used to build the MACD.
def vettoreMA(dati,periodo):
    itad=[]
    vMediaINV=[]
    mediaFinale=[]
    i=len(dati)
    c=0
    prov=0
    conta=0
    while i >0 :
        itad.append(dati[c])
        c+=1
        i-=1
    long1=len(itad)//int(periodo)
    for i in range(len(itad)-int(periodo)):
        for c in range(periodo):
            prov=float(itad[i+c][4])+prov
        vMediaINV.append(prov/periodo)
        prov=0
    i=len(vMediaINV)
    c=0
    while i >0:
        mediaFinale.append(vMediaINV[c])
        c+=1
        i-=1
    return mediaFinale

def vettoreMACD(mediasmall,mediabig):
    macd=[]
    for i in range(len(mediabig)):
        macd.append(mediabig[i]-mediasmall[i])
    return macd

PYTHON IA BINANCE API PIVOT CALCULATOR V.2

In this new version there is the possibility to automatically calculate the Fibonacci levels between the levels where the price is located. 


If you like you can help me continue the research on my AI written in Python by donating crypto currencies or by donating here

You can download the software from this link: PivotCalculator. If you are interested in the sources contact me.

venerdì 17 aprile 2020

PYTHON BINANCE API TRADING IA - EXAMPLE

What is an AI BOT trading? It's a software that trades for you. We must build the logic of the trading system.

If you want to help me you can choose to send me crypto currencies to my addresses indicated on the right of the blog or make a donation on gofundme.
This is a very trivial example of AI for trading. It is based only on book order volumes and two moving averages over a 5 minute time frame. 
I am developing algorithms for the recognition of graphic patterns, the management of the MACD (an example of MACD is already present in this blog). 
The function of the Pivot Point is already automated: my Pivot Point algorithm decides which is the right candle from which to extrapolate all the resistances and supports as well as the p.p.(.exe program for Windows here).

from binance.client import Client
from binance.enums import *
import string
import time
import dateparser
import sys

def accesso():
    f=open('chiavi.dat','r') #text file : pubblicAPIkey-privateAPIkey
    rawkeys=f.read()
    f.close()
    k=rawkeys.split('-')
    cl=Client(api_key=k[0], api_secret=k[1])
    return cl

def ultimoPrezzo(cl,coppia):
    lP=0.0
    while True:
        try:
            vPrz=cl.get_all_tickers()
            break
        except:
            print("Ticker connection - error")
    for i in range(len(vPrz)):
        if vPrz[i]['symbol']==coppia.upper():
            lP=vPrz[i]['price']
    return lP

def verificaTF(cl,tf):
    ok=False
    while True:
        try:
            t = cl.get_server_time()
            break
        except:
            print("Server Time Error")
    ms=str(t['serverTime'])
    data=dateparser.parse(ms)
    data=str(data)
    oD=data.split(" ")
    orario=oD[1].split(":")
    if tf=='4H':
        i=0
        d=4
    elif tf=='30M':
        i=1
        d=30
    elif tf=='15M':
        i=1
        d=15
    elif tf=='5M':
        i=1
        d=5
    resto=float(orario[i])%d
    if resto==0 and (int(orario[2])==0):
        ok=True
        time.sleep(10)
    return ok,oD[1]

def book(cl,cp):
    bidsPrice=[]
    asksPrice=[]
    while True:
        try:
            libro = cl.get_order_book(symbol=cp.upper())
            break
        except:
            print("book connection - error")
    for i in range(len(libro)):
        sumBidsVol=float(libro['bids'][i][1])
        sumAsksVol=float(libro['asks'][i][1])
    for i in range(30):
        bidsPrice.append(float(libro['bids'][i][0]))
        asksPrice.append(float(libro['asks'][i][0]))
    return bidsPrice, asksPrice,sumBidsVol,sumAsksVol

def MA(dati,periodo):
    prezzi=[]
    for i in range(len(dati)):
        prezzi.append(float(dati[i]))
    ris=0
    for i in range(periodo):
        ris=ris+prezzi[i]
    ris=ris/periodo
    return ris

def recuperoPrezzi(cl,coppia):
    vPrezzi=[]
    while True:
        try:
            vTot=cl.get_klines(symbol=coppia.upper(), interval=Client.KLINE_INTERVAL_5MINUTE)
            break
        except:
            print("kLines errore")
    for i in range(len(vTot)):
        vPrezzi.append(vTot[i][4])
    return vPrezzi

def main(coppia,diff):
    cl=accesso()
    vP=recuperoPrezzi(cl,coppia)
    buy=False
    sell=False
    inOp=False
    while True:
        stampa,ora=verificaTF(cl,'5M')#5M 15M 30M 4H
        prezzo = ultimoPrezzo(cl,coppia)
        if stampa:
            print("Prezzo ",prezzo," - ",ora)
            ma3=MA(vP,3)
            ma14=MA(vP,14)
            print("MA3 ",ma3,"\nMA14 ",ma14)
            vP.append(prezzo)
            bidsP,asksP,sumBV,sumAV=book(cl,coppia)#asset name
            f=open("dati.dat","a")
            stringa=str(prezzo)+","+str(ma3)+","+str(ma14)+","+str(ora)+"\n"
            f.write(stringa)
            f.close()
            if ((float(sumBV)-float(sumAV)) > 0) and (ma3>ma14) and not(inOp):
                print("BUY ",prezzo," ",ora)
                prezzoB=prezzo
                buy=True
                inOp=True
                sell=False
            elif ((float(sumBV)-float(sumAV)) < 0) and (ma3<ma14) and not(inOp):
                prezzoS=prezzo
                print("SELL ",prezzo," ",ora)
                buy=False
                inOp=True
                sell=True
        if buy:
            prezzo=ultimoPrezzo(cl,coppia)
            if float(prezzo)>(float(prezzoB)+float(diff)) :
                print("Preso Buy ",prezzoB," ",prezzo," ",ora)
                f=open("operazioni.dat","a")
                stringa="Prezzo Buy "+str(prezzoB)+" uscita: "+str(float(prezzoB)+float(diff))+"\n"
                f.write(stringa)
                f.close()
                buy=False
                inOp=False
        if sell:
            prezzo=ultimoPrezzo(cl,coppia)
            if float(prezzo)<(float(prezzoS)-float(diff)):
                print("Preso sell ",prezzoS," ",prezzo," ",ora)
                f=open("operazioni.dat","a")
                stringa="Prezzo Sell "+str(prezzoS)+" uscita: "+str(float(prezzoS)-float(diff))+"\n"
                f.write(stringa)
                f.close()
                sell=False
                inOp=False
#name asset takeprofit
main(sys.argv[1],sys.argv[2])

Sorry, alittle mistake in def MA: replace this with the one in the main listing.
def MA(dati,periodo):
    ris=0
    i=len(dati)-1
    for c in range(periodo):
        prezzo=(float(dati[i]))
        ris=ris+prezzo
        i-=1
    ris=ris/periodo
    return ris

PYTHON - BINANCE API - PRINT THE LATEST PRICE AT EACH TIME FRAME

This Python script print the last price for each time frame. 
TIME FRAME: 4H 30M 15M 5M
COUPLE: all those on spot Binance

from binance.client import Client
from twisted.internet import reactor
from binance.enums import *
import string
import time
import dateparser
import sys

def accesso():
    f=open('chiavi.dat','r') #text file : pubblicAPIkey-privateAPIkey
    rawkeys=f.read()
    f.close()
    k=rawkeys.split('-')
    cl=Client(api_key=k[0], api_secret=k[1])
    return cl

def ultimoPrezzo(cl,coppia):
    lP=0.0
    vPrz=cl.get_all_tickers()
    for i in range(len(vPrz)):
        if vPrz[i]['symbol']==coppia.upper():
            lP=vPrz[i]['price']
    return lP

def verificaTF(cl,tf):
    ok=False
    t = cl.get_server_time()
    ms=str(t['serverTime'])
    data=dateparser.parse(ms)
    data=str(data)
    oD=data.split(" ")
    orario=oD[1].split(":")
    if tf=='4H':
        i=0
        d=4
    elif tf=='30M':
        i=1
        d=30
    elif tf=='15M':
        i=1
        d=15
    elif tf=='5M':
        i=1
        d=5
    resto=float(orario[i])%d
    if resto==0 and (int(orario[2])==0):
        ok=True
        time.sleep(10)
    return ok,oD[1]

client=accesso()
while True:
    stampa,ora=verificaTF(client,sys.argv[2])#5M 15M 30M 4H
    if stampa:
        prezzo = ultimoPrezzo(client,sys.argv[1])#asset name
        print(prezzo," ",ora)

You must make a text file containing: public key API binance (dash) -private key API binance. You don't have to type send at the end of the line. You have to save it as: chiavi.dat .
This program is part of the next AI Signal Bot that I am programming.

martedì 14 aprile 2020

PYTHON - TELEGRAM IA TRADING SIGNAL INDICATOR CRYPTOCOINS -

The first BOT written in Python for Telegram is ready. Currently it communicates the trend of the couple, the pivot point with graph, and the maximum lows (in the test phase). 
 If you want to be inserted in the Telegram channel you can write me an email. 
If you want to help me you can support me with gofundme, or by sending me BTC, BAT or LINK to the addresses on the side. 
Send me an email for more information. 
I hope soon to be able to leave the BOT active 24 hours a day 7 days a week. The next features will be: entry and exit prices for scalping, recognition of graphic patterns such as cup and head and shoulders, recognition of differences. 
Here is the list of the main program of the bot with the Telegram API.
import time
import telepot
from pprint import pprint
import trFunz
import utils
import os
import sys
import keys

def handle(msg):
    content_type, chat_type, chat_id = telepot.glance(msg)
    if content_type == 'text':
        txt=msg['text']
        if txt.startswith('/help'):
            bot.sendMessage(chat_id,'Bot analizzatore di trading su crypto valute presenti sull\'exchange Binance')
            help=utils.archivioR("txt/help.bot")
            bot.sendMessage(chat_id,help)
        if txt.startswith('/email'):
            params=txt.split()
            if len(params) == 1:
                bot.sendMessage(chat_id,'Ti saranno inviate email con segnali di trading sulla coppia voluta\n/email  ')
            else:
                try:
                    dati=params[1]+","+params[2]+"\n"
                    utils.archivio('txt/email.bot','a',dati)
                    bot.sendMessage(chat_id,'Eseguito')
                except:
                    bot.sendMessage(chat_id,'Errore nel passaggio dei parametri')
        if txt.startswith('/pivot'):
            params = txt.split()
            if len(params) == 1:
                bot.sendMessage(chat_id, 'Uso: /pivot    Calcola il Pivot Point in automatico  DAY/4H')
            else:
                try:
                    client=utils.accesso()
                    print (params[1])
                    print (params[2])
                    coppia=params[1].upper()
                    periodo=int(params[2])
                    tf=params[3].upper()
                    print(tf)
                    bot.sendMessage(chat_id,(trFunz.calcPP(client,coppia,periodo,tf)))
                    bot.sendPhoto(chat_id, photo=open('img/pp.png', 'rb'))
                except:
                    bot.sendMessage(chat_id, 'Errore nei parametri')
        if txt.startswith('/trend'):
            params = txt.split()
            if len(params) == 1:
                bot.sendMessage(chat_id,'Uso: /trend   rileva il trend con le medie mobili')
            else:
                try:
                    client=utils.accesso()
                    coppia=params[1].upper()
                    term=params[2].upper()
                    trend=trFunz.scopriTrend(client,coppia,term,200)
                    trend=coppia+" "+trend
                    bot.sendMessage(chat_id,trend)
                except:
                    bot.sendMessage(chat_id,'Errore nei parametri')
        if txt.startswith('/ph'):
            bot.sendPhoto(chat_id, photo=open('img/test.png', 'rb'))
        if txt.startswith('/mm'):
            params = txt.split()
            if len(params) == 1:
                bot.sendMessage(chat_id,'Uso: /mm      Trova i massimi ed i minimi nel periodo n.giorni indicato. MAXVAL: il valore di soglia sotto il quale si vogliono trovare i minimi oppure per scelta automatica digitare \'a\'. N.DEC numero di decimali desiderati dopo la virgola.\nACorHL: 0 per lavorare su prezzi apertura/chiusura, 1 per lavorare su prezzi high/low')
            else:
                try:
                    client=utils.accesso()
                    giorni=int(params[1])
                    print(giorni)
                    coppia=params[2].upper()
                    print(coppia)
                    maxval=params[3]
                    print(maxval)
                    ndec=params[4]
                    print(ndec)
                    ACHL=int(params[5])
                    vMax,vmin=trFunz.minemax(client,giorni,coppia,maxval,ndec,ACHL)
                    bot.sendMessage(chat_id,'Massimi:'+str(vMax))
                    bot.sendMessage(chat_id,'Minimi:'+str(vmin))
                except:
                    bot.sendMessage(chat_id,'Errore nei parametri')

TOKEN = keys.Token
bot = telepot.Bot(TOKEN)
response = bot.getUpdates()
pprint(response)
bot.message_loop(handle)
print ('Listening ...')
while 1:
    time.sleep(20)

sabato 11 aprile 2020

PYTHON BINANCE API - HOW TO MAKE: A LIST OF SMA and MACD

This little python script uses the Binance API.
The customer position is opened to access the data.
Data on the chosen pair are retrieved in the chosen time frame.
The moving average vector is constructed.
The macd vector is constructed.
The macd vector is drawn.
As always if you like the blog you can help me by going on by donating BTC, Link, BAT or by donating through gofundme.
from binance.client import Client
from twisted.internet import reactor
from binance.enums import *
import matplotlib.pyplot as plt
import dateparser

def recuperoDati(coppia,tf):
    f=open('chiavi.dat')
    #esempio di chiavi.dat file: chiavepubblicabinance-chiaveprivatabinance
    #tra le due chiavi deve esserci '-' senza spazi, alla fine della riga non
    #deve essere battuto invio
    rawkeys=f.read()
    f.close()
    k=rawkeys.split('-')
    client=Client(api_key=k[0], api_secret=k[1])
    if tf=='DAY':
        rawData=client.get_klines(symbol=coppia, interval=client.KLINE_INTERVAL_1DAY)
    elif tf=='4H':
        rawData=client.get_klines(symbol=coppia, interval=client.KLINE_INTERVAL_4HOUR)
    elif tf=='30M':
        rawData=client.get_klines(symbol=coppia, interval=client.KLINE_INTERVAL_30MINUTE)
    elif tf=='15M':
        rawData=client.get_klines(symbol=coppia, interval=client.KLINE_INTERVAL_15MINUTE)
    elif tf=='5M':
        rawData=client.get_klines(symbol=coppia, interval=client.KLINE_INTERVAL_5MINUTE)
    return rawData

def vettoreMA(dati,periodo):
    itad=[]
    vMediaINV=[]
    mediaFinale=[]
    i=len(dati)
    c=0
    prov=0
    conta=0
    while i >0 :
        itad.append(dati[c])
        c+=1
        i-=1
    long1=len(itad)//int(periodo)
    for i in range(len(itad)-int(periodo)):
        for c in range(periodo):
            prov=float(itad[i+c][4])+prov
        vMediaINV.append(prov/periodo)
        prov=0
    i=len(vMediaINV)
    c=0
    while i >0:
        mediaFinale.append(vMediaINV[c])
        c+=1
        i-=1
    return mediaFinale

def vettoreMACD(mediasmall,mediabig):
    macd=[]
    for i in range(len(mediabig)):
        macd.append(mediabig[i]-mediasmall[i])
    return macd

def asseX(l,dati):
    x=[]
    for i in range(l):
        data=dateparser.parse(str(dati[i][0]))
        data=str(data)
        oD=data.split(" ")
        x.append(oD[0])
    return x

rawData=recuperoDati('BATUSDT','DAY')
ms=vettoreMA(rawData,12)
mb=vettoreMA(rawData,26)
macd=vettoreMACD(ms,mb)
x=asseX(len(macd),rawData)
fig=plt.figure(figsize=(20,17))
plt.plot(x, macd, color = 'black')
plt.show()

giovedì 9 aprile 2020

PYTHON API BINANCE - IA - PIVOT POINT AUTOMATIC -

BOT trading for crypto currencies based on Binance API. The pivot point is automatically calculated on the last important candle of the selected time frame, over the chosen days. The candle is selected based on its amplitude and volume. The results are printed on the monitor and on a graph.


BOT di trading per crypto valute basato su Binance API. Il pivot point viene calcolato in automatico sull'ultima candela importante del time frame selezionato, nell'arco dei giorni scelti. La candela viene selezionata in base all'ampiezza e il volume. I risultati sono stampati a monitor e su grafico.


You can download the zip of the executable file on windows from this link
Puoi scaricare lo zip del file eseguibile su windows da questo link:  Pivot Calc






mercoledì 1 aprile 2020

PYTHON - MASSIMI MASSIMI e MINIMI MINIMI - PROGRAMMAZIONE TRADING

Avevo bisogno di scoprire i MASSIMI di una serie di dati disordinati e tutti i MINIMI della stessa serie. Nel trading l'individuazione dei massimi e dei minimi è di fondamentale importanza. 

'''
RICERCA DEI MASSIMI IN UN VETTORE DISORDINATO
RICERCA DEI MINIMI IN UN VETTORE DISORDINATO
di PORCARI DANIELE
'''
import sys

def trovaMassimi(v):
    m=[]
    max=0
    for i in range(len(v)):
        try:
            if v[i]>max and v[i]>v[i+1]:
                m.append(v[i])
                max=v[i+1]
        except:
            if v[i]>max:
                m.append(v[i])
    return m

def trovaMinimi(v,min):
    m=[]
    for i in range(len(v)):
        try:
            if v[i]<min and v[i]<v[i+1]:
                m.append(v[i])
                min=v[i+1]
        except:
            if v[i]<min:
                m.append(v[i])
    return m

v=[10,2,5,3,3,1,2,1,4,6,2,3,2,7,13]
if len(sys.argv)>0:
    min=float(sys.argv[1])
else:
    min=20
m=trovaMassimi(v)
print (m)
m=trovaMinimi(v,min)
print (m)
L'output sono due liste: una contenente tutti i MASSIMI, l'altra tutti i MINIMI. Un MASSIMO è un dato contenuto tra almeno due dati più bassi. Un MINIMO è un dato contenuto tra almeno due dati più alti. Se vi piace il blog e le soluzioni le donazioni in BTC,USDT o LINK sono le benvenute.