Nov-25-2019, 01:36 AM
Hello everyone,
I'm very new to Python and doing some very basic personal practice and trying to make a function that checks for stock prices and sees if it's a "Cup and Handle" model. Basically, the prices should go down, then up, and then retreat again. Again very basic though as a real cup and handle model is much more complex but it's a start I suppose.
#prices
price1 = 100
price2 = 98
price3 = 97
price4 = 100
price5 = 92
price6 = 93
price7 = 94
price8 = 96
price9 = 97
price10 = 95
price11 = 94
price12 = 93
This set of variable should return "Cup and handle model"
#prices
price1 = 100
price2 = 98
price3 = 97
price4 = 95
price5 = 92
price6 = 93
price7 = 94
price8 = 96
price9 = 97
price10 = 95
price11 = 94
price12 = 93
Whenever I run my function with the first set of variables I always end up returning "Cup and handle model"
PS: I used to do some object oriented programming but I guess I'm really rusty.
I'm very new to Python and doing some very basic personal practice and trying to make a function that checks for stock prices and sees if it's a "Cup and Handle" model. Basically, the prices should go down, then up, and then retreat again. Again very basic though as a real cup and handle model is much more complex but it's a start I suppose.
def cupandhandle(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12): pricelist = [p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12] i = 1 while i < 7 and pricelist[i + 1] > pricelist[1]: return "Not a cup and handle model" i += 1 else: while i > 6 and i < 10 and pricelist[i + 1] < pricelist[1]: return "Not a cup and handle model" i += 1 else: while i > 9 and pricelist[i + 1] > pricelist[1]: return "Not a cup and handle model" i += 1 else: return "Cup and handle model"This set of variables should return "Not a cup and handle model"
#prices
price1 = 100
price2 = 98
price3 = 97
price4 = 100
price5 = 92
price6 = 93
price7 = 94
price8 = 96
price9 = 97
price10 = 95
price11 = 94
price12 = 93
This set of variable should return "Cup and handle model"
#prices
price1 = 100
price2 = 98
price3 = 97
price4 = 95
price5 = 92
price6 = 93
price7 = 94
price8 = 96
price9 = 97
price10 = 95
price11 = 94
price12 = 93
Whenever I run my function with the first set of variables I always end up returning "Cup and handle model"
PS: I used to do some object oriented programming but I guess I'm really rusty.