samedi 6 juillet 2019

if-elif change value being checked once condition is met?

I am trying to wrap my brain around this and am pretty confident that the following will cause a problem. Looking for confirmation

if row['High'] < sl_c:    # Check if SL is being hit
    sl_ci = row['Low'] + sl
    # sl_ci = row['High'] - sl  # chenge sl which is being looked for.
    if sl_ci < sl_c:  # Verify sl_ci is greater than current
          sl_c = sl_ci
          buy_l[key].at[e, 'sl'] = sl_c  # Input sl to dfent
          buy_l[key].at[e, 'sltime'] = row['Time']  # Input time of sl modification
          # buy_l[key].at[e,'sl'] = sl_c
elif row['High'] > sl_c:  # If SL is hit
     buy_l[key].at[e,'Buy'] = sl_c  # input the sl_c as exit
     buy_l[key].at[e, 'CloseTime'] = row['Time'] # input the time of exit

As you can see sl_c is being checked in the first if statement and the nested if is checking it against the second condition sl_ci. When both conditions are met we change a certain value.

The elif is checking for sl_c which I believe is being modified above and might meet/reject the condition based on the new value?

This might be clearer

if x == -1:
     y= -2
   if y < x:
      x=y
elif x<-1:      # Will the value be checked even though above if condition is met? 
                # if it will be, then will the x value being checked be -2?


Aucun commentaire:

Enregistrer un commentaire