Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python Trading Engine
#1
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.
Reply
#2
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.
Reply
#3
(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.
Reply
#4
(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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Star Pairs Trading Simulation Kiitoos 0 226 Feb-19-2024, 08:27 PM
Last Post: Kiitoos
  how to manage crypto trading flooding data from exchange servers Mikeardy 0 1,225 Dec-26-2021, 08:31 PM
Last Post: Mikeardy
  cbot ctrader automate trading hl29951 1 1,641 Jul-25-2021, 08:14 PM
Last Post: Larz60+
  Code should download and output trading data tayy 2 2,625 Mar-04-2021, 04:07 AM
Last Post: tayy
  Search Engine nman52 1 52,983 Dec-16-2020, 11:46 AM
Last Post: Larz60+
  problem python search engine forumpy 0 1,722 Sep-15-2020, 10:26 PM
Last Post: forumpy
  problem about slope in python script for bitcoin trading fisher_garry 1 2,495 Sep-02-2020, 01:39 PM
Last Post: fisher_garry
  Understanding Python's Import Engine MysticaL 1 2,154 Feb-07-2020, 11:26 PM
Last Post: snippsat
  Voynich search engine in python using dashes & dot totals to find Italian words Pleiades 3 3,474 Oct-10-2019, 10:04 PM
Last Post: Pleiades
  Making an application with a 3d engine in it moo5e 1 2,109 May-27-2019, 03:17 PM
Last Post: heiner55

Forum Jump:

User Panel Messages

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