mardi 7 décembre 2021

if else condition true it will run until it doesn't false, but when else condition is true it will run continuously until when it false

I have If - else condition,

High = [18365.5, 18979.25, 19297.4, 19874.8, 20288.0, 20504.65, 20398.2] 

Low = [17855.5, 18265.0, 18822.55, 18742.15, 19492.55, 20055.55, 20131.25] 

Close = [18317.05, 18969.95, 18857.6, 19804.0, 20260.15, 20285.0, 20215.7]

length = len(Close) - 1

i = 0
a = 1
Trend = ["No Trend"]
Difference = ["No Trend"]
while i<length:
    if Close[a] > Low[i]:
        trend = "Long"
        Trend.append(trend)
        difference = Close[a] - Low[i]
        Difference.append(difference)
    elif Close[a] < High[i]:
        trend = "Short"
        Trend.append(trend)
        difference = Close[a] - High[i]
        Difference.append(difference)
    i = i + 1
    a = a + 1
df = pd.DataFrame(list(zip(High, Low, Close, Difference, Trend, From_date, End_date)),
               columns =['High', 'Low', 'Close', 'Difference', 'Trend', 'From_date', 'End_date'])
display(df)

So i want if Close[a] > Low[i] condition is true so it will run continuously until it doesn't false, and when if condition will false so else Close[a] < High[i] condition start, so it will run continuously unitll it will not false.

I am showing you the below data frame, which will give you a clear-cut idea. enter image description here

In this Dataframe there are three columns which are High, Low, Close, and the rest of the columns are made by these three column.

So in if - condition is true so it's print "Long" continuously until It doesn't false, but when else condition start so else condition should run, and start checking this condition Close[a] < High[i]. until it doesn't false.

I'm trying my best to explain my question And Sorry, if my explanation is not good.

Aucun commentaire:

Enregistrer un commentaire