samedi 27 février 2021

nested if statement within a for loop doesn't work

I have a nested if statement within a for loop but the first if statement seems not to be progressing onto the rest of the for loop.

for i, x in enumerate(S[start:-1], start):
    if i > max(sma_period1, sma_period2, sma_period3):
        j = i-start
        
        if ma1[i] == x:
            w[j+1] = w[j]
            cash[j+1] = cash[j]

        if ma1[i] < x: 
            w[j+1] = cash[j]/x  + w[j]
            cash[j+1] = 0

        if ma1[i] > x:
            cash[j+1] = w[j]*x + cash[j]
            w[j+1] = 0

tf_strategy_ma1 = [a*b for a,b in zip(w,S[start:])]+ cash

Sorry if this is a very basic question, I am new to coding and completely stuck. Thanks for your help.

Aucun commentaire:

Enregistrer un commentaire