-
Notifications
You must be signed in to change notification settings - Fork 2
/
dsi15eod.py
212 lines (159 loc) · 5.64 KB
/
dsi15eod.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
from datetime import time
from time import sleep
import backtrader as bt
from dsicache.allobjects import *
from mytelegram.skyler import Skyler
from tradingschedule import *
fromdate = lastclosingtime.date()
sessionstart = time(hour=9, minute=15)
sessionend = time(hour=15, minute=30)
nexttradingsession = nextclosingtime.date()
tickers = ['NIFTY50_IND_NSE', 'BANKNIFTY_IND_NSE', 'RELIANCE_STK_NSE', 'SBIN_STK_NSE', 'TATASTEEL_STK_NSE',
'HCLTECH_STK_NSE', 'TATAMOTOR_STK_NSE', 'ADANIPORT_STK_NSE', 'AXISBANK_STK_NSE', 'BAJFINANC_STK_NSE',
'BAJAJFINS_STK_NSE', 'BHARTIART_STK_NSE', 'INDUSINDB_STK_NSE', 'MARUTI_STK_NSE', 'ONGC_STK_NSE',
'TECHM_STK_NSE', 'TITAN_STK_NSE', 'WIPRO_STK_NSE', 'HDFC_STK_NSE', 'TCS_STK_NSE', 'HINDALCO_STK_NSE',
'JSWSTEEL_STK_NSE']
tickers.sort()
lastclose_dict = dict()
def round05(n):
return round(n * 20) / 20
def format2d(n):
return format(n, '.2f')
def get_arrow(n):
if n == 1:
return '⬆️'
elif n == 0:
return '➡️'
elif n == -1:
return '⬇️'
else:
return 'Invalid input'
class Strategy(bt.Strategy):
def next(self):
if self.datas[0].datetime.datetime(0) == lastclosingtime:
self.cerebro.runstop()
def stop(self):
global lastclose_dict
for data in self.datas:
ticker = data._dataname
close = data.close[0]
lastclose_dict.update({ticker: close})
def getdata(t):
global cerebro
data0 = store.getdata(dataname=t, fromdate=fromdate,
sessionstart=sessionstart,
sessionend=sessionend,
historical=True, timeframe=bt.TimeFrame.Days)
cerebro.adddata(data0)
cerebro = bt.Cerebro(runonce=False)
cerebro.addstrategy(Strategy)
store = bt.stores.IBStore(port=7496, _debug=True)
cerebro.addcalendar("BSE")
for index in tickers:
getdata(index)
cerebro.run()
skyler = Skyler()
sleep(10)
for ticker, close in lastclose_dict.items():
dsi15 = dsi15x[ticker]
dsi75 = dsi75x[ticker]
dsiD = dsiDx[ticker]
atr = round05(dsi15["curvestate"]["atrvalue"])
upperband = round05(close + atr * 3)
lowerband = round05(close - atr * 3)
print(atr, close, upperband, lowerband)
message = ""
message += "*Plan for: " + str(nexttradingsession.strftime("%d-%m-%Y")) + "*\n\n"
trendDay = get_arrow(dsiD["trendstate"]["trend"])
trend75 = get_arrow(dsi75["trendstate"]["trend"])
trend15 = get_arrow(dsi15["trendstate"]["trend"])
message += f"Daily Trend: {trendDay}\n"
message += f"75 Min Trend: {trend75}\n"
message += f"15 Min Trend: {trend15}\n\n"
szs = dsiD["supplyzones"][:2]
while len(szs):
sz = szs.pop(-1)
entry = format2d(round05(sz.entry))
sl = format2d(round05(sz.sl))
score = str(sz.score)
message += f"-{entry} SL {sl} Ω {score}\n"
message += f"- " * 25 + "\n"
message += f"- " * 25 + "\n"
#####################################
# ____________________________________
szs = []
for sz in dsi75["supplyzones"]:
if sz.entry <= upperband:
szs.append(sz)
else:
break
while len(szs):
sz = szs.pop(-1)
entry = format2d(round05(sz.entry))
sl = format2d(round05(sz.sl))
score = str(sz.score)
message += f"-{entry} SL {sl} Ω {score}\n"
message += f"- " * 25 + "\n"
message += f"- " * 25 + "\n"
#####################################
# ____________________________________
szs = []
for sz in dsi15["supplyzones"]:
if sz.entry <= upperband:
szs.append(sz)
else:
break
while len(szs):
sz = szs.pop(-1)
entry = format2d(round05(sz.entry))
sl = format2d(round05(sz.sl))
score = str(sz.score)
message += f"-{entry} SL {sl} Ω {score}\n"
#####################################
# ____________________________________
message += f"\n*{ticker.split('_')[0]}: {round05(close)} @ {round05(atr)}*\n\n"
# ____________________________________
#####################################
dzs = []
for dz in dsi15["demandzones"]:
if dz.entry >= lowerband:
dzs.append(dz)
else:
break
while len(dzs):
dz = dzs.pop(0)
entry = format2d(round05(dz.entry))
sl = format2d(round05(dz.sl))
score = str(dz.score)
message += f"+{entry} SL {sl} Ω {score}\n"
# ____________________________________
#####################################
message += f"- " * 25 + "\n"
message += f"- " * 25 + "\n"
dzs = []
for dz in dsi75["demandzones"]:
if dz.entry >= lowerband:
dzs.append(dz)
else:
break
while len(dzs):
dz = dzs.pop(0)
entry = format2d(round05(dz.entry))
sl = format2d(round05(dz.sl))
score = str(dz.score)
message += f"+{entry} SL {sl} Ω {score}\n"
# ____________________________________
#####################################
message += f"- " * 25 + "\n"
message += f"- " * 25 + "\n"
dzs = dsiD["demandzones"][:2]
while len(dzs):
dz = dzs.pop(0)
entry = format2d(round05(dz.entry))
sl = format2d(round05(dz.sl))
score = str(dz.score)
message += f"+{entry} SL {sl} Ω {score}\n"
skyler.send_all_clients(message, parse_mode="Markdown")
# skyler.send_message(975198388, message, parse_mode="Markdown")
skyler.send_all_clients(f"*Disclaimer:*\nTrade Levels for educational purpose only. Consult your advisor before trading.", parse_mode="Markdown")
skyler.stop()