-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmain.py
More file actions
785 lines (567 loc) · 31.9 KB
/
main.py
File metadata and controls
785 lines (567 loc) · 31.9 KB
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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
# Importing Necessary Libraries
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import yfinance as yf
import dash
import ta
import plotly.express as px
import plotly.graph_objects as go
import dash_bootstrap_components as dbc
from ta import add_all_ta_features
from ta import trend
from ta import volume
from ta import momentum
from ta import volatility
from ta.trend import sma_indicator
from ta.trend import ema_indicator
from ta.momentum import awesome_oscillator
from ta.volatility import bollinger_hband
from ta.volatility import bollinger_lband
from ta.volatility import bollinger_mavg
from dash.dependencies import Input, Output
from dash import html
from dash import dcc
from datetime import date
from datetime import datetime as dt
import colorlover as cl
# Creating an empty dataframe for later use.
df = pd.DataFrame()
# Calling the application with the SpaceLabs theme
app = dash.Dash(external_stylesheets=[dbc.themes.SPACELAB])
# Defining Colorscales for the candlestick sharts
colorscale = cl.scales['9']['qual']['Paired']
################################################################################
# #
# APP LAYOUT STARTS HERE #
# #
################################################################################
app.layout = html.Div(
[
# TITLE
html.H3(children = "Visualizing Technical Indicators Using Python and Plotly. - By Surya Sashank Gundepudi",
style = {
'textAlign' : 'center'
}),
# NOTE
html.Div(children='''(This is for educational purposes only)''',
style = {
'textAlign' : 'center',
}),
# LINK FOR TUTORIAL
html.Div(children=[html.A('SEARCH FOR TUTORIAL AND SOURCE AT GITHUB',
href='https://github.com/suryasashankgundepudi/technical-analysis-visualization-using-python-v1/blob/main/README.md',
target='_blank')],
style = {
'textAlign' : 'center',
}),
# LINK FOR TECHNICAL ANALYSIS LIBRARY DOCUMENTATION
html.Div(children=[html.A("""UNDERSTAND WHICH PARAMETERS ARE NEEDED PLEASE GO HERE.
IF PARAMETERS ARE MISSING DEFAULT VALUES ARE TAKEN""",
href='https://technical-analysis-library-in-python.readthedocs.io/en/latest/ta.html',
target='_blank')],
style = {
'textAlign' : 'center',
}),
#LINK FOR CURRENT INDICATOR
html.Div(children=[html.A('LEARN MORE ABOUT CURRENT INDICATOR HERE',
href='https://www.investopedia.com/terms/s/sma.asp',
id = "indicator-link",
target='_blank')],
style = {
'textAlign' : 'center',
}),
html.Br(),
html.Br(),
# THE FIRST ROW AS SEEN IN APPLICATION
dbc.Row(
[
# TEXT FOR TICKER
dbc.Col(html.Div(children='''Enter The ticker from yahoo finance. Copy and paste all letters
at same time please: '''),
align = 'start',
style = {"margin-left": "20px"}),
# TEXT FOR START AND END DATE
dbc.Col((html.Div(children='''Enter the START DATE and END DATE''')), align = 'center',
style = {"margin-left": "100px"}),
dbc.Col((html.Div(children = '''Select what kind of graph you would like along with indicator''')),
align = 'center', style = {"margin-right" : '100px'})
# ROW 1 ENDS HERE
],
align="start",
),
# THE SECOND ROW AS SEEN IN THE APPLICATION
dbc.Row(
[
# INPUT FOR TICKER VALUE
dbc.Col((dcc.Input(id="input-1", type="text", value="AMZN")), align = 'start',
style = {"margin-left": "20px", 'border-radius': 10}),
# INPUT FOR DATE RANGE
dbc.Col((dcc.DatePickerRange(
id='my-date-picker-range',
start_date=date(2018, 1, 1),
end_date = date(2019, 12, 31),
min_date_allowed=date(2003, 1, 1),
max_date_allowed=date(2020, 12, 31),
initial_visible_month= date(2018, 1, 12),
start_date_placeholder_text= date(2018, 1, 1),
end_date_placeholder_text= date(2019, 12, 31)
)), align = 'end',
style = {"margin-left": "100px", 'border-radius': 10}),
# INPUT FOR TYPE OF GRAPH
dbc.Col((dcc.Dropdown(
id='graphtypeselect',
options = [
{'label' : "CandleStick Chart", 'value' : "candle"},
{'label' : "Open of Stock", "value" : "open"},
{'label' : "Close of Stock", "value" : "close"}
],
value = 'candle'
)), align = 'end',
style = {"margin-right": "40px", 'border-radius': 10})
# ROW ENDS HERE
]
),
html.Br(),
html.Br(),
# THE THIRD ROW AS SEEN IN THE APPLICATION
dbc.Row(
[
# TEXT FOR SHORT WINDOW LENGTH
dbc.Col( html.Div(children='''Enter the Short Window Length'''), align = 'start',
style = {"margin-left": "20px"}),
# TEXT FOR LONG WINDOW LENGTH
dbc.Col( html.Div(children='''Enter the Long Window Length (if indicator requires only one
window it will take the first one)'''),
align = 'center'),
#TEXT FOR SIGNAL WINDOW
dbc.Col( html.Div(children='''Enter the signal Window (if indicator requires only one
window length it will take the first value)''')),
# TEXT FOR TYPE OF INDICATOR
dbc.Col((html.Div(children='''Select the Type of Indicator''')), align = 'end',
style = {"margin-right": "40px"}),
],
align="start",
),
# THE FOURTH ROW AS SEEN IN THE APPLICATION
dbc.Row(
[
# INPUT VALUE FOR SHORT WINDOW LENGTH
dbc.Col((dcc.Input(id="input-window", type="number", value=12)), align = 'start',
style = {"margin-left": "20px", 'border-radius': 10}),
# INPUT VALUE FOR LONG WINDOW LENGTH
dbc.Col((dcc.Input(id="input-window-long", type="number", value=26,
style = {'border-radius': 10})), align = 'center'),
# INPUT VALUE FOR LONG WINDOW LENGTH
dbc.Col((dcc.Input(id="input-window-signal", type="number", value=9,
style = {'border-radius': 10}))),
# INPUT VALUE FOR INDICATOR
dbc.Col((dcc.Dropdown(
id='indicator',
options = [
{'label' : "Stock Only", 'value' : "PLAIN"},
{'label' : "Accumulation/Distribution Index", 'value' : "ACCDI"},
{'label' : 'Aroon Indicator', 'value' : 'AROON'},
{'label' : "Average Directional index", 'value' : 'ADX'},
{'label' : "Average True Range (ATR)", 'value' : 'Average True Range'},
{'label': 'Awesome Oscillator', 'value' : 'Awesome Oscillator'},
{'label': 'Bollinger Bands (std - 2)', 'value' : 'Bollinger Bands'},
{'label': 'Chaikin Money Flow (CMF)', 'value' : 'Chaikin Money Flow'},
{'label' : 'Cummilative Returm', 'value' : 'CUMRET'},
{'label' : 'Daily Return', 'value' : 'DRET'},
{'label' : 'Donchian Channel Bands', 'value' : 'DCI'},
{'label': 'Ease of Movement', 'value' : 'Ease of Movement'},
{'label': 'Exponential Moving Average', 'value' : 'Exponential Moving Average'},
{'label' : "Ichimoku Kinkō Hyō (Ichimoku)", 'value' : 'ICHIMOKU'},
{'label': 'Kaufman’s Adaptive Moving Average', 'value' : 'KAMA'},
{'label' : 'Kelter Channel Index', 'value' : "KCI"},
{'label' : 'Money Flow index', 'value' : "MFI"},
{'label' : 'MACD', 'value' : 'MACD'},
{'label' : 'Negative Volume Index Indicator', 'value' : "NVII"},
{'label': 'Percentage Price Oscillator', 'value' : 'Percentage Price Oscillator (PPO)'},
{'label': 'Percentage Volume Oscillator', 'value' : 'Percentage Volume Oscillator'},
{'label': 'Rate of Change', 'value' : 'Rate of Change'},
{'label': 'Relative Strength Index (RSI)', 'value' : 'Relative Strength Index'},
{'label': 'Simple Moving Average', 'value' : 'Simple Moving Average'},
{'label': 'Ulcer Index', 'value' : 'ULCI'},
{'label' : 'Volume Weighted Average Price', 'value' : "VWAP"},
{'label' : 'Weighted Moving Average', 'value': 'WMA'}
],
value = 'PLAIN'
)), align = 'end',
style = {"margin-right": "40px", 'border-radius': 10})]
),
html.Br(),
dcc.Graph(id='GRAPH'),
])
# USING THE INPUTS FROM THE APP TO UPDATE THE GRAPH. CURRENT CALLBACK UPDATES THE GRAP
@app.callback(
Output('GRAPH', 'figure'),
Input("input-1", "value"),
Input('indicator', 'value'),
Input('input-window', 'value'),
Input('input-window-long', 'value'),
Input('input-window-signal', 'value'),
Input("graphtypeselect", "value"),
Input('my-date-picker-range', 'start_date'),
Input('my-date-picker-range', 'end_date'))
def update_output(input1, indicator_1, window_input, window_input_long, signal_input, graphtype, start_date, end_date):
# DOWNLOADING THE DATA FROM YAHOO FINANCE USING THE FIRST INPUT
df = yf.download(input1, start_date,end_date)
# SAVING ONLY THE NECESSARY VALUES INTO DATAFRAME NAMED STOCK
Stock = pd.DataFrame({
"Date" : df.index,
"Close" : df["Close"],
"Open" : df["Open"],
"High" : df["High"],
"Low" : df["Low"],
"Volume" : df["Volume"]
})
# SETTING THE INDEX OF STOCK AS THE DATES OF THE DATAFRAME
Stock.set_index("Date")
# SECOND CALLBACK FOR THE TYPE OF GRAPH TO BY PLOTTED
if graphtype == "candle":
add_trace_graph = go.Candlestick(x = Stock["Date"],
open=Stock["Open"],
high=Stock['High'],
low=Stock['Low'],
close=Stock['Close'], name = input1)
if graphtype == "close":
add_trace_graph = {'x' : Stock["Date"], 'y' : Stock["Close"], 'type' : 'scatter', 'name' : 'Close'}
if graphtype == "open":
add_trace_graph = {'x' : Stock["Date"], 'y' : Stock["Open"], 'type' : 'scatter', 'name' : 'Open'}
# ACCUMALATION DISTRIBUTION INDEX
if indicator_1 == "PLAIN":
fig = go.Figure()
fig.add_trace(add_trace_graph)
fig.update_yaxes(fixedrange=False)
fig.update_layout(transition_duration=500)
return fig
# ACCUMALATION DISTRIBUTION INDEX
if indicator_1 == "ACCDI":
Stock["ADI"] = volume.acc_dist_index(high = Stock["High"], low = Stock["Low"],
close = Stock["Close"], volume = Stock["Volume"])
fig = px.line(Stock[["ADI"]], title='Accumulation/Distribution Index (ADI)')
fig.update_layout(transition_duration=500)
return fig
# AROON INDICATOR
elif indicator_1 == "AROON":
Stock["AROON UP"] = trend.aroon_up(Stock["Close"], window = window_input)
Stock["AROON DOWN"] = trend.aroon_down(Stock["Close"], window = window_input)
fig = px.line(Stock[["AROON UP", "AROON DOWN"]], title='Aroon Indicator')
fig.update_layout(transition_duration=500)
return fig
# AVERAGE DIRECTIONAL INDICATOR
elif indicator_1 == "ADX":
Stock["ADX"] = trend.adx(Stock["High"], Stock["Low"], Stock["Close"],
window=window_input)
Stock["DX_NEG"] = trend.adx_neg(Stock["High"], Stock["Low"], Stock["Close"],
window=window_input)
Stock["DX_POS"] = trend.adx_pos(Stock["High"], Stock["Low"], Stock["Close"],
window=window_input)
fig = px.line(Stock[["ADX"]], title='Average Directional Indicator')
fig.update_layout(transition_duration=500)
return fig
# AWESOME INDICATOR
elif indicator_1 == "Awesome Oscillator":
Stock["Awesome Oscillator"] = awesome_oscillator(Stock["High"], Stock["Low"], window1=window_input,
window2=window_input_long)
fig = px.line(Stock[["Awesome Oscillator"]], title='Awesome Indicator')
fig.update_yaxes(fixedrange=False)
fig.update_layout(transition_duration=500)
return fig
# AVERAGE TRUE RANGE INDICATOR
elif indicator_1 == "Average True Range":
Stock["Average True Range"] = volatility.average_true_range(high = Stock["High"], low = Stock["Low"],
close = Stock["Close"], window=window_input)
fig = px.line(Stock[["Average True Range"]], title='Average True Range')
fig.update_yaxes(fixedrange=False)
fig.update_layout(transition_duration=500)
return fig
# BOLLINGER BANDS
elif indicator_1 == "Bollinger Bands":
Stock["HIGH BAND"] = bollinger_hband(Stock["Close"], window = window_input, window_dev = 2)
Stock["LOW BAND"] = bollinger_lband(Stock["Close"], window = window_input, window_dev = 2)
Stock["MID BAND"] = bollinger_mavg(Stock["Close"], window = window_input)
#fig = px.line(Stock[["Close", "HIGH BAND", "LOW BAND", "MID BAND"]], title='Close and Bollinger Bands')
fig = px.line(Stock[["HIGH BAND", "LOW BAND", "MID BAND"]], title='Close and Bollinger Bands')
fig.add_trace(add_trace_graph)
fig.update_yaxes(fixedrange=False)
fig.update_layout(transition_duration=500)
return fig
# CHAIKIN INDICATOR
elif indicator_1 == "Chaikin Money Flow":
Stock["Chaikin Money Flow"] = volume.chaikin_money_flow(high = Stock["High"], low = Stock["Low"],
close = Stock["Close"], volume = Stock["Volume"],
window = window_input)
fig = px.line(Stock[["Chaikin Money Flow"]], title='Chaikin Indicator')
fig.update_yaxes(fixedrange=False)
fig.update_layout(transition_duration=500)
return fig
# Commodity Channel Index (CCI)
elif indicator_1 == "CCI":
Stock["CCI"] = trend.cci(high = Stock["High"], low = Stock["Low"],
close = Stock["Close"], window=window_input)
fig = px.line(Stock["CCI"], title='Close VS Commodity Chanel Index')
fig.add_trace(add_trace_graph)
fig.update_yaxes(fixedrange=False)
fig.update_layout(transition_duration=500)
return fig
# CUMMILATIVE RETURN
elif indicator_1 == "CUMRET":
Stock["Cummilative Return"] = ta.others.cumulative_return(Stock['Close'])
fig = px.line(Stock[["Cummilative Return"]], title='Cummilative Return')
fig.update_yaxes(fixedrange=False)
fig.update_layout(transition_duration=500)
return fig
# DAILY RETURN
elif indicator_1 == "DRET":
Stock["Daily Return"] = ta.others.daily_return(Stock['Close'])
fig = px.line(Stock[["Daily Return"]], title='Daily Return')
fig.update_yaxes(fixedrange=False)
fig.update_layout(transition_duration=500)
return fig
# Donchian CHANNEL INDICATOR
elif indicator_1 == "DCI":
Stock["HIGH BAND"] = volatility.donchian_channel_hband(high = Stock["High"], low = Stock["Low"],
close = Stock["Close"], window = window_input)
Stock["LOW BAND"] = volatility.donchian_channel_lband(high = Stock["High"], low = Stock["Low"],
close = Stock["Close"], window = window_input)
Stock["MID BAND"] = volatility.donchian_channel_mband(high = Stock["High"], low = Stock["Low"],
close = Stock["Close"], window = window_input)
fig = px.line(Stock[["HIGH BAND", "LOW BAND", "MID BAND"]], title='Close and Donchian Channel Bands')
fig.add_trace(add_trace_graph)
fig.update_yaxes(fixedrange=False)
fig.update_layout(transition_duration=500)
return fig
# EASE OF MOVEMENT INDICATOR
elif indicator_1 == "Ease of Movement":
Stock["Ease of Movement"] = volume.ease_of_movement(high = Stock["High"], low = Stock["Low"],
volume = Stock["Volume"], window = window_input)
fig = px.line(Stock[["Ease of Movement"]], title='Ease of Movement')
fig.update_yaxes(fixedrange=False)
fig.update_layout(transition_duration=500)
return fig
# EXPONENTIAL MOVING AVERAGE
elif indicator_1 == "Exponential Moving Average":
Stock["EMA"] = ema_indicator(Stock["Close"], window = window_input)
fig = px.line(Stock["EMA"], title='Close VS Exponential Moving Average')
fig.add_trace(add_trace_graph)
fig.update_yaxes(fixedrange=False)
fig.update_layout(transition_duration=500)
return fig
# Ichimoku Kinkō Hyō (Ichimoku)
elif indicator_1 == "ICHIMOKU":
Stock["Senkou Span A"] = trend.ichimoku_a(high = Stock["High"], low = Stock["Low"], window1 = window_input,
window2 = window_input_long)
Stock["Senkou Span B"] = trend.ichimoku_b(high = Stock["High"], low = Stock["Low"], window2 = window_input_long,
window3 = signal_input)
Stock["Kiju Sen (Base Line)"] = trend.ichimoku_base_line(high = Stock["High"], low = Stock["Low"],
window1 = window_input,
window2 = window_input_long)
Stock["Tenkan Sen (Conversion Line)"] = trend.ichimoku_conversion_line(high = Stock["High"], low = Stock["Low"],
window1 = window_input,
window2 = window_input_long)
fig = px.line(Stock[["Senkou Span A", "Senkou Span B", "Kiju Sen (Base Line)",
"Tenkan Sen (Conversion Line)"]],
title='Close and Ichimoku')
fig.add_trace(add_trace_graph)
fig.update_yaxes(fixedrange=False)
fig.update_layout(transition_duration=500)
return fig
# KAUFMAN'S ADAPTIVE MOVING AVERAGE
elif indicator_1 == "KAMA":
Stock["KAMA"] = momentum.kama(Stock["Close"], window = window_input)
fig = px.line(Stock["KAMA"], title='Close VS KAMA')
fig.add_trace(add_trace_graph)
fig.update_yaxes(fixedrange=False)
fig.update_layout(transition_duration=500)
return fig
# KELTER CHANNEL INDICATOR
elif indicator_1 == "KCI":
Stock["HIGH BAND"] = volatility.keltner_channel_hband(Stock['High'], Stock['Low'],
Stock["Close"], window = window_input,
window_atr=window_input_long)
Stock["LOW BAND"] = volatility.keltner_channel_lband(Stock['High'], Stock['Low'],
Stock["Close"], window = window_input,
window_atr=window_input_long)
Stock["MID BAND"] = volatility.keltner_channel_mband(Stock['High'], Stock['Low'],
Stock["Close"], window = window_input,
window_atr=window_input_long)
fig = px.line(Stock[["HIGH BAND", "LOW BAND", "MID BAND"]], title='Close and Keltner Indicator')
fig.add_trace(add_trace_graph)
fig.update_yaxes(fixedrange=False)
fig.update_layout(transition_duration=500)
return fig
# MONEY FLOW INDEX
elif indicator_1 == "MFI":
Stock["MFI"] = volume.money_flow_index(high = Stock["High"], low = Stock["Low"],
close = Stock["Close"], volume = Stock["Volume"],
window = window_input)
fig = px.line(Stock["MFI"], title='MONEY FLOW INDEX')
fig.update_yaxes(fixedrange=False)
fig.update_layout(transition_duration=500)
return fig
# MOVING AVERAGE CONVERGENCE DIVERGENCE
elif indicator_1 == "MACD":
Stock["MACD"] = trend.macd(Stock["Close"], window_slow = window_input_long,
window_fast=window_input)
Stock["MACD SIGNAL"] = trend.macd_signal(Stock["Close"], window_slow = window_input_long,
window_fast=window_input, window_sign= signal_input)
fig = px.line(Stock[["MACD", "MACD SIGNAL"]], title='MACD AND MACD SIGNAL')
fig.update_yaxes(fixedrange=False)
fig.update_layout(transition_duration=500)
return fig
# NEGATIVE VOLUME INDEX INDICATOR
elif indicator_1 == "NVII":
Stock["NVII"] = volume.negative_volume_index(close = Stock["Close"], volume = Stock["Volume"])
fig = px.line(Stock["NVII"], title='Close and Negative Volume Index Indicator')
fig.add_trace(add_trace_graph)
fig.update_yaxes(fixedrange=False)
fig.update_layout(transition_duration=500)
return fig
# PERCENTAGE PRICE OSCILLATOR
elif indicator_1 == "Percentage Price Oscillator (PPO)":
Stock["PPO"] = momentum.ppo(Stock["Close"], window_slow = window_input_long,
window_fast=window_input, window_sign= signal_input)
fig = px.line(Stock[["PPO"]], title='PPO')
fig.update_yaxes(fixedrange=False)
fig.update_layout(transition_duration=500)
return fig
# PERCENTAGE VOLUME OSCILLATOR
elif indicator_1 == "Percentage Volume Oscillator":
Stock["PVO"] = momentum.pvo(Stock["Close"], window_slow = window_input_long,
window_fast=window_input, window_sign= signal_input)
Stock["SIGNAL"] = momentum.pvo(Stock["Close"], window_slow = window_input_long,
window_fast=window_input, window_sign= signal_input)
fig = px.line(Stock[["PVO", "SIGNAL"]], title='PVO VS PVO SIGNAL')
fig.update_yaxes(fixedrange=False)
fig.update_layout(transition_duration=500)
return fig
# RATE OF CHANGE
elif indicator_1 == "Rate of Change":
Stock["ROC"] = momentum.roc(Stock["Close"], window=window_input)
fig = px.line(Stock["ROC"], title='RATE OF CHANGE')
fig.update_yaxes(fixedrange=False)
fig.update_layout(transition_duration=500)
return fig
# RELATIVE STRENGTH INDEX
elif indicator_1 == "Relative Strength Index":
Stock["RSI"] = momentum.rsi(Stock["Close"], window = window_input)
fig = px.line(Stock[["RSI"]], title='Relative Strength Index')
fig.update_yaxes(fixedrange=False)
fig.update_layout(transition_duration=500)
return fig
# SIMPLE MOVING AVERAGE
elif indicator_1 == "Simple Moving Average":
Stock["MA"] = sma_indicator(Stock["Close"], window = window_input)
fig = px.line(Stock["MA"], title='Close VS Simple Moving Average')
fig.add_trace(add_trace_graph)
fig.update_yaxes(fixedrange=False)
fig.update_layout(transition_duration=500)
return fig
# ULCER INDEX
elif indicator_1 == "ULCI":
Stock["ULCI"] = volatility.ulcer_index(Stock["Close"], window = window_input)
fig = px.line(Stock["ULCI"], title='Ulcer Index')
fig.update_yaxes(fixedrange=False)
fig.update_layout(transition_duration=500)
return fig
# VOLUME WEIGHTED AVERAGE PRICE
elif indicator_1 == "VWAP":
Stock["VWAP"] = volume.volume_weighted_average_price(high = Stock["High"], low = Stock["Low"],
close = Stock["Close"], volume = Stock["Volume"],
window = window_input)
fig = px.line(Stock["VWAP"]
, title='Close VS Volume Weighter Average Price')
fig.add_trace(add_trace_graph)
fig.update_yaxes(fixedrange=False)
fig.update_layout(transition_duration=500)
return fig
# WEIGHTED MOVING AVERAGE
elif indicator_1 == "WMA":
Stock["WMA"] = trend.wma_indicator(close = Stock["Close"], window = window_input)
fig = px.line(Stock["WMA"], title='Close VS Weighted Moving Average')
fig.add_trace(add_trace_graph)
fig.update_yaxes(fixedrange=False)
fig.update_layout(transition_duration=500)
return fig
#UPDATING THE LINKS FOR TECHNICAL INDICATOR
@app.callback(
Output('indicator-link', 'href'),
Input('indicator', 'value')
)
def update_link(indicator_1):
if indicator_1 == "ACCDI":
url = """https://www.ifcm.co.uk/ntx-indicators/awesome-oscillatorr"""
return url
elif indicator_1 == "Awesome Oscillator":
url = "https://www.ifcm.co.uk/ntx-indicators/awesome-oscillator"
return url
elif indicator_1 == "ADX":
url = """https://www.ifcm.co.uk/ntx-indicators/awesome-oscillator"""
return url
elif indicator_1 == "AROON":
url = """https://www.investopedia.com/terms/a/aroon.asp"""
return url
elif indicator_1 == "Average True Range":
url = """https://www.ifcm.co.uk/ntx-indicators/awesome-oscillatore"""
return url
elif indicator_1 == "Bollinger Bands":
url = "https://www.investopedia.com/trading/using-bollinger-bands-to-gauge-trends/"
return url
elif indicator_1 == "Chaikin Money Flow":
url = "https://school.stockcharts.com/doku.php?id=technical_indicators:chaikin_money_flow_cmf"
return url
elif indicator_1 == "CCI":
url = "https://technical-analysis-library-in-python.readthedocs.io/en/latest/ta.html#ta.trend.CCIIndicator"
return url
elif indicator_1 == "Ease of Movement":
url = """https://en.wikipedia.org/wiki/Ease_of_movement"""
return url
elif indicator_1 == "Exponential Moving Average":
url = "https://www.investopedia.com/terms/e/ema.asp"
return url
elif indicator_1 == "ICHIMOKU":
url = """https://school.stockcharts.com/doku.php?id=technical_indicators:ichimoku_cloud"""
return url
elif indicator_1 == "KAMA":
url = "https://www.tradingview.com/ideas/kama/"
return url
elif indicator_1 == "KCI":
url = """https://school.stockcharts.com/doku.php?id=technical_indicators:keltner_channels"""
return url
elif indicator_1 == "MFI":
url = """https://school.stockcharts.com/doku.php?id=technical_indicators:money_flow_index_mfi"""
return url
elif indicator_1 == "MACD":
url = """https://technical-analysis-library-in-python.readthedocs.io/en/latest/ta.html#ta.trend.MACD"""
return url
elif indicator_1 == "Percentage Price Oscillator (PPO)":
url = "https://school.stockcharts.com/doku.php?id=technical_indicators:price_oscillators_ppo"
return url
elif indicator_1 == "Percentage Volume Oscillator":
url = "https://school.stockcharts.com/doku.php?id=technical_indicators:percentage_volume_oscillator_pvo"
return url
elif indicator_1 == "Rate of Change":
url = "https://school.stockcharts.com/doku.php?id=technical_indicators:rate_of_change_roc_and_momentum"
return url
elif indicator_1 == "Relative Strength Index":
url = "https://www.investopedia.com/terms/r/rsi.asp"
return url
elif indicator_1 == "Simple Moving Average":
url = "https://www.investopedia.com/terms/s/sma.asp"
return url
elif indicator_1 == "ULCI":
url = """https://school.stockcharts.com/doku.php?id=technical_indicators:ulcer_index"""
return url
elif indicator_1 == "VWAP":
url = """https://school.stockcharts.com/doku.php?id=technical_indicators:vwap_intraday"""
return url
elif indicator_1 == "WMA":
url = "https://corporatefinanceinstitute.com/resources/knowledge/trading-investing/weighted-moving-average-wma/"
return url
# In[6]:
if __name__ == '__main__':
app.run_server()
# In[ ]: