Skip to content

Commit e2a86e3

Browse files
committed
Add Stochastic indicator
1 parent 2aaac61 commit e2a86e3

File tree

5 files changed

+57
-6
lines changed

5 files changed

+57
-6
lines changed

common.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,10 @@ def calc_stochastic_oscillator(df, n=14, m=3, smooth=3):
6969
d = k.rolling(m).mean()
7070
return k, d
7171

72+
73+
def calc_stochasticRsi_oscillator(df, n=14, m=3, smooth=3):
74+
lo = df.Low.rolling(n).min()
75+
hi = df.High.rolling(n).max()
76+
k = 100 * (df.Close-lo) / (hi-lo)
77+
d = k.rolling(m).mean()
78+
return k, d

finplotWindow.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
from indicators import ichimoku
66
from indicators import rsi
7+
from indicators import stochastic
8+
from indicators import stochasticRsi
79

810
sys.path.append('../finplot')
911
import finplot as fplt
@@ -329,9 +331,13 @@ def updateChart(self):
329331
self.rsi_indicator.draw(self.ax_rsi)
330332

331333
if self.IndStochasticActivated:
334+
self.stochastic_indicator = stochastic.Stochastic(self.data)
335+
self.stochastic_indicator.draw(self.ax_stochastic)
332336
pass
333337

334338
if self.IndStochasticRsiActivated:
339+
self.stochasticRsi_indicator = stochasticRsi.StochasticRsi(self.data)
340+
self.stochasticRsi_indicator.draw(self.ax_stochasticRsi)
335341
pass
336342

337343
if self.IndVolumesActivated:

indicators/rsi.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,7 @@
44
sys.path.append('../finplot')
55
import finplot as fplt
66

7-
import backtrader.functions as func
8-
from pyqtgraph.functions import Color
9-
107
from common import calc_rsi
11-
from common import calc_parabolic_sar
12-
from common import calc_stochastic_oscillator
138

149
class Rsi():
1510

@@ -22,5 +17,4 @@ def draw(self, ax, rsi_color = "magenta"):
2217
pass
2318

2419
def clear(self):
25-
2620
pass

indicators/stochastic.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env python3
2+
import sys
3+
4+
sys.path.append('../finplot')
5+
import finplot as fplt
6+
7+
from common import calc_stochastic_oscillator
8+
9+
class Stochastic():
10+
11+
def __init__(self, dataFrames, stochastic_periods=14, stochastic_quick=3, stochastic_smooth = 3):
12+
self.stochastic_df, self.stochastic_quick_df = calc_stochastic_oscillator(dataFrames, stochastic_periods, stochastic_quick, stochastic_smooth)
13+
pass
14+
15+
def draw(self, ax, stochasticColor = "magenta", stochastic_quick_color="yellow"):
16+
self.stochastic_plot = fplt.plot(self.stochastic_df, ax = ax, color=stochasticColor, width=1 )
17+
self.stochastic_quick_plot = fplt.plot(self.stochastic_quick_df, ax = ax, color=stochastic_quick_color, width=1 )
18+
pass
19+
20+
def clear(self):
21+
22+
pass

indicators/stochasticRsi.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env python3
2+
import sys
3+
4+
sys.path.append('../finplot')
5+
import finplot as fplt
6+
7+
from common import calc_stochasticRsi_oscillator
8+
9+
class StochasticRsi():
10+
11+
def __init__(self, dataFrames, stochasticRsi_periods=14, stochasticRsi_quick=3, stochasticRsi_smooth = 3):
12+
self.stochasticRsi_df, self.stochasticRsi_quick_df = calc_stochasticRsi_oscillator(dataFrames, stochasticRsi_periods, stochasticRsi_quick, stochasticRsi_smooth)
13+
pass
14+
15+
def draw(self, ax, stochasticRsi_color = "red", stochasticRsi_quick_color="green"):
16+
self.stochasticRsi_plot = fplt.plot(self.stochasticRsi_df, ax = ax, color=stochasticRsi_color, width=1 )
17+
self.stochasticRsi_quick_plot = fplt.plot(self.stochasticRsi_quick_df, ax = ax, color=stochasticRsi_quick_color, width=1 )
18+
pass
19+
20+
def clear(self):
21+
22+
pass

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy