-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lesson3
executable file
·50 lines (37 loc) · 1.29 KB
/
lesson3
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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# 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 answer!='':
try:
answer=float(answer)
except:
print("Enter a number.")
else:
done=True
else:
print("Enter a number.")
return answer
# Ask for the closing price
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)