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

Nessun commento:

Posta un commento