Python Forum

Full Version: Python Trading Engine
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
So I am trying to code a python script to assist me with my stock trading. here's my code so far.
def buy():
   datr = float(input("Daily ATR: "))
   dzd = float(input("Demand Zone Distal: "))
   dzp = float(input("Demand Zone Proximal: "))
   szp = float(input("Supply Zone Proximal: "))
   szd = float(input("Supply Zone Distal: "))
   wr = (datr * 0.02)
   sl = (dzd - wr)
   rsk = (dzp - sl)
   rwd = (rsk * 3)
   t1 = (dzp + rwd)
   t2 = szp
   print("Target 1:", t1)
   print("Target 2:", t2)

def intromenu():
   choice = input("1. Buy\n2. Sell\n\nEnter: ")
   if choice == 1:
       buy()
   else:
       exit()

intromenu()
When I run the program, I enter 1, the program exits with no errors. I'm trying to make it so whenever I enter 1, the function buy() executes. Thanks.
input return str, and you compare with int, that is why if choice == 1 is always false
obviously you are aware that input return str, because you convert it to float in buy function.
(May-27-2017, 08:28 PM)buran Wrote: [ -> ]input return str, and you compare with int, that is why if choice == 1 is always false
obviously you are aware that input return str, because you convert it to float in buy function.

So how would I fix that? I didn't necessarily know that input returns a string, I was just messing around and found that that would get rid of my errors. I'm trying to call function
buy()
from function
intromenu()
but can't.
(May-27-2017, 09:46 PM)icabero0225 Wrote: [ -> ]
(May-27-2017, 08:28 PM)buran Wrote: [ -> ]input return str, and you compare with int, that is why if choice == 1 is always false
obviously you are aware that input return str, because you convert it to float in buy function.

So how would I fix that? I didn't necessarily know that input returns a string, I was just messing around and found that that would get rid of my errors. I'm trying to call function
buy()
from function
intromenu()
but can't.


Anything entered as a response to input will be a str.

So

if input == '1' should work; add quotes around 1.