Python Forum
Struggling with several while loops
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Struggling with several while loops
#1
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.

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.
Reply
#2
If you're interested in stock market analysis with python, this may interest you: https://medium.com/automation-generation...77b3a396ed
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Struggling with Juggling JSON Data SamWatt 7 1,884 May-09-2022, 02:49 AM
Last Post: snippsat
  Syntax errors: Struggling to setup enviroment and load packages AH56 5 2,777 Jun-30-2021, 01:01 PM
Last Post: AH56
  Struggling for the past hour to define function and call it back godlyredwall 2 2,210 Oct-29-2020, 02:45 PM
Last Post: deanhystad
  struggling with != statements CallumRoberts2004 2 1,538 Aug-18-2020, 03:01 PM
Last Post: GOTO10
  I’m Flat out struggling to understand list indexes gr3yali3n 7 2,900 Jul-20-2020, 07:18 PM
Last Post: princetonits
  Struggling with nested list gr3yali3n 3 2,301 Jul-09-2020, 05:30 PM
Last Post: DPaul
  Struggling to exit this while loop fatherted99 5 2,474 Feb-08-2020, 07:46 PM
Last Post: fatherted99
  struggling with loop/webscrape zarize 4 2,476 Sep-27-2019, 08:44 AM
Last Post: zarize
  Still struggling with np.where... pberrett 1 1,843 May-10-2019, 11:30 AM
Last Post: scidam
  Struggling To Work With Anti-Captcha API digitalmatic7 1 5,710 Oct-09-2017, 09:51 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020