forked from Rom3dius/TV-Settings-Optimizer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathemaslope.py
73 lines (64 loc) · 2.05 KB
/
emaslope.py
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
63
64
65
66
67
68
69
70
71
72
73
# 18 19 20 22
from selenium.common.exceptions import NoSuchElementException, StaleElementReferenceException, TimeoutException
from selenium.webdriver.support.ui import WebDriverWait
from functions import click, webdriver, xpaths, database
import os
import time
import numpy as np
url = 'https://www.tradingview.com/chart/awk7Das0/' # enter your trading view profile link here.
# range = np.arange(min_value, max_value, increment)
# combinations = np.array(np.meshgrid(x, y, z)).T.reshape(-1,3)
r1 = np.arange(7, 10, 1)
r2 = np.arange(80, 120, 1)
# r3 = np.arange(1, 1, 1)
# r4 = np.arange(-1, -1, 1)
combinations = np.array(np.meshgrid(r1, r2)).T.reshape(-1,2)
def run_script(driver):
"""find the best stop loss value."""
db = database.DB()
wait = WebDriverWait(driver, 5)
driver.get(url)
time.sleep(10)
click.strategy_tester()
time.sleep(2)
click.overview()
time.sleep(1)
try:
click.perf_sum()
time.sleep(1)
except NoSuchElementException:
time.sleep(1)
click.perf_sum()
print("Loading script...")
try:
for n in combinations:
print(n)
click.settings_button(wait)
click.input(n[1], 24, wait)
click.input(n[0], 23, wait)
#click.input(n[2], 20, wait)
#click.input(n[3], 22, wait)
click.close_settings()
time.sleep(3)
try:
x = xpaths.report({'Fast': int(n[0]), 'Slow': int(n[1])})
db.append(x)
del x
except Exception as e:
print(f"Exception: {e}")
except KeyboardInterrupt:
print("Detected interrupt! Printing results...")
print("Net Profit... ")
wr = db.index("NP")[-3:]
print(wr)
del wr
print("Max Drawdown... ")
md = db.index("MD")[-3:]
print(md)
del md
if not os.path.exists('databases'):
os.makedirs('databases')
del db
os.rename('db.json', f'databases/db_{round(time.time())}.json')
if __name__ == '__main__':
run_script(webdriver.driver)