Python Forum

Full Version: Logic is not working as it should work
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
    if ((SPREAD >= 2 and SPREAD < 20) and not Long_On_Spread):
        Long_On_Spread = True
        print ('Buy  Mini - Sell  Mega')
        
    elif ((SPREAD <=-2 and SPREAD > 20) and not Shorting_Spread):
        Shorting_Spread = True
        print ('Sell  Mini - Buy Mega')
        
    elif (abs(SPREAD) < 0.1 and (Long_On_Spread or Shorting_Spread)):
        Long_On_Spread = False
        Shorting_Spread = False
        print ('Exit Position')
        
The second and third condition is not working. While the condition is satisfying.
(SPREAD <=-2 and SPREAD > 20): how could SPREAD be less or equal to -2 and in the same more than 20?