[Python] Convert pine script to python with nz function

Discussão em 'Python' iniciado por Stack, Julho 11, 2025.

  1. Stack

    Stack Membro Participativo

    I'm trying to convert a pine script to python but I'm confused about the following code because some results are not same with pine script. For example, at the moment, only last 5 values are right, others are wrong. Please check my code.

    Pine Script:

    up=src-(Multiplier*atr)
    up1 = nz(up[1],up)
    up := close[1] > up1 ? max(up,up1) : up


    converted code:

    up = src - (Multiplier*atr)

    up1 = up.copy()
    for i in range(len(up1)):
    if(i>0):
    up1 = up[i-1]

    for i in range(len(up)):
    if(i > 0 and close[i-1] > up1):
    up = max(up, up1)

    Continue reading...

Compartilhe esta Página