Python Forum
Why is the if construct not calculating correctly?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Why is the if construct not calculating correctly?
#1
Why is the result wrong in the if structure below, it gives 1 every time, but it should be 2 in my checks (python 3.1)

bars = exchange.fetch_ohlcv(symbol, timeframe=zamanAraligi, since=None, limit=500)
        df = pd.DataFrame(bars, columns=["timestamp", "open", "high", "low", "close", "volume"])

        #ema control
        e8 = ta.ma("ema", df.close, length=8)
        e13 = ta.ma('ema', df.close, length=13)
        e21 = ta.ma('ema', df.close, length=21)
        e55 = ta.ma('ema', df.close, length=55)

        #ema rating
        sum = 0
        if any(e8 > e13):
            sum = 1
        elif any(e8 < e13):
            sum = 0
        elif any(e13 > e21):
            sum = 1
        elif any(e13 < e21):
            sum = 0
        elif any(e21 > e55):
            sum = 1
        else:
            sum = 0

        print(e8, e13, e21, e55)
        print(sum)
Yoriz write Mar-19-2022, 10:00 AM:
Please post all code, output and errors (in their entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Reply


Messages In This Thread
Why is the if construct not calculating correctly? - by egemynet - Mar-19-2022, 10:10 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
Information Is it possible to multi line a Basic Function Construct line statement? If so how? BrandonKastning 7 466 May-23-2024, 03:02 PM
Last Post: deanhystad
  Building command in a looping construct DennisT 3 2,027 Sep-08-2020, 06:32 PM
Last Post: DennisT
  shortening an elif construct Skaperen 10 5,686 Jul-24-2018, 07:06 AM
Last Post: Skaperen
  Best construct? Array, class, other? PappaBear 1 3,054 May-10-2017, 06:02 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