-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lesson4
executable file
·62 lines (44 loc) · 1.45 KB
/
lesson4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Validate user input
# oldChar='lOSZ'
# newChar='1052'
def IsNumbersOnly(ustring):
numbers='0123456789.'
if ustring=='':
return False
for usChar in ustring:
if usChar not in numbers:
return False
return True
# Ask for the closing price and give the stop loss and take profit prices.
# stop loss and take profit in the form reward/risk.
# R:R 2:1 means 2 times the reward for your risk
def GetUserInput(question):
done=False
answer=''
while not done:
answer=input(question)
if IsNumbersOnly(answer):
done=True
else:
print("Enter a number.")
return float(answer)
# Ask for the closing price
# key = value
closingPrice=GetUserInput("What is the closing price? ")
# Get the risk percentage
risk=GetUserInput("What is the risk percentage (number only)? ")/100
reward=GetUserInput("What is the reward ratio (number only)? ")*risk
stopLoss=closingPrice-(closingPrice*risk)
takeProfit=closingPrice+(closingPrice*reward)
print("Closing Price:",closingPrice)
print("Take Profit:",takeProfit)
print("Stop Loss:",stopLoss)
# Ask user how much they want to buy.
# display how much they will profit or loose.
buyAmount=GetUserInput("How much do you want to buy? ")
win=buyAmount*reward
loss=buyAmount*risk
print("Profit:",win,"Winning Position:",buyAmount+win)
print("Loss:",loss,"Loosing Position:",buyAmount-loss)