Skip to content

Commit dd72297

Browse files
committed
Added Doji candlestick patern detection.
Further work on a functioning example. Changes to be committed: modified: Base/Library/JRRtechnical.py modified: Extras/CodeProofs/jrrTA/demo.ex1 modified: Extras/CodeProofs/jrrTA/demo.sw-zl-hma
1 parent 163eca1 commit dd72297

6 files changed

Lines changed: 483 additions & 5434 deletions

File tree

Base/Library/JRRtechnical.py

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,10 @@ def MakeOHLCV(self,days=0,hours=0,minutes=0,seconds=60):
225225

226226
return [epoch, o, h, l, c, v]
227227

228+
##
229+
## Technical Indicators
230+
##
231+
228232
# Calculate difference between two moving averages and where or not they
229233
# crossed over/user each other
230234

@@ -1212,7 +1216,51 @@ def OBV(self, closeIDX=4, volumeIDX=5):
12121216
self.AddColumn(obv)
12131217
return self.window
12141218

1215-
## Future additions (No particular order)
1219+
##
1220+
## Candlestick patterns
1221+
##
1222+
1223+
# Detect a Doji candlestick pattern
1224+
1225+
def Doji(self,OpenIDX=1,HighIDX=2,LowIDX=3,CloseIDX=4,threshold=0.1):
1226+
if len(self.window)<1:
1227+
self.AddColumn(None) # body
1228+
self.AddColumn(None) # range
1229+
self.AddColumn(None) # ratio
1230+
self.AddColumn(None) # upper wick/shadow
1231+
self.AddColumn(None) # lowwer wick/shadow
1232+
self.AddColumn(None) # is doji (1=yes)
1233+
return self.window
1234+
1235+
last_row=self.LastRow()
1236+
1237+
o=last_row[OpenIDX]
1238+
h=last_row[HighIDX]
1239+
l=last_row[LowIDX]
1240+
c=last_row[CloseIDX]
1241+
1242+
isDoji=0
1243+
b=abs(o-c) # Body of candle
1244+
r=h-l # Range of candle
1245+
ratio=b/r if r!=0 else 0 # body to range ratio
1246+
1247+
us=h-max(o,c) # length of upper wick/shadow
1248+
ls=max(o,c)-l # length of lower wick/shadow
1249+
1250+
self.AddColumn(b)
1251+
self.AddColumn(r)
1252+
self.AddColumn(ratio)
1253+
self.AddColumn(us)
1254+
self.AddColumn(ls)
1255+
1256+
if ratio<=threshold:
1257+
isDoji=1
1258+
1259+
self.AddColumn(isDoji)
1260+
1261+
return self.window
1262+
1263+
## Future indicator additions (No particular order)
12161264

12171265
## Volume-based
12181266

0 commit comments

Comments
 (0)