Help me about def

i want a def about pin pattern and i try coding and i type below:

 

def buypin (DF):

    df=data.copy()

    for i in range(len(data)):

        if df.close[i]>=((df.high[i]-df.low[i])*0.75+df.low[i]) :

            df["buypin"]=1

        elif df.close[i]<((df.high[i]-df.low[i])*0.75+df.low[i]) :

            df["buypin"]=0

    return df ["buypin"]

data["buypin"]=buypin(data)
 

when ı run it "buypin" column is fiiled 1 it ignore 0. I am ensure formula is correct because i check that on excell but def is wrong but i cant figure out where is the problem. 

thanks and with best regard

Hello Aytac,



I think the code should be:

def buypin (data):

    df=data.copy()

    for i in range(len(data)):
        threshold = df.high[i]-df.low[i]*0.75+df.low[i]

        if df.close[i]>=threshold:

            df["buypin"]=1

        else :

            df["buypin"]=0

    return df ["buypin"]

data["buypin"]=buypin(data)

1) The DF (in capital you were importing) wasn't even being used. I think you mean to receive data instead in the function. 
2) Since the value, you're comparing against is the same, you can put it in a variable. Here I named that variable threshold.