Skip to content

Commit a14d6ed

Browse files
committed
More candlestick patterns detected
Changes to be committed: modified: Base/Library/JRRtechnical.py modified: Extras/CodeProofs/jrrTA/demo.candlesticks
1 parent 49305a5 commit a14d6ed

5 files changed

Lines changed: 84 additions & 78 deletions

File tree

Base/Library/.JRRtechnical.py.swp

1 KB
Binary file not shown.

Base/Library/JRRtechnical.py

Lines changed: 65 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def __init__(self, exchange, account, asset, timeframe, count=200,length=16,prec
2424
self.account = account
2525
self.asset = asset
2626
self.tf = timeframe
27-
self.count = count+1 # historical (count) + live candles
27+
self.count = count+1 if count<5000 else 5000 # historical (count) + live candles
2828
self.window = []
2929
self.length=16
3030
self.precision=8
@@ -122,29 +122,17 @@ def ReadFile2List(fname):
122122
return ohlcv
123123

124124
# Pull the OHLCV data to the limit requested.
125+
# Return the RAW ohlcv data. Do NOT add it to the rolling window.
125126

126127
def GetOHLCV(self):
127128
try:
128129
ohlcv=self.relay.GetOHLCV(symbol=self.asset,timeframe=self.tf, limit=self.count)
129-
except Exception:
130-
ohlcv=[]
131-
132-
if not ohlcv:
130+
except Exception as err:
131+
print(err)
133132
# Return a blank padded window if fetch fails
134-
self.window=[[None,None,None,None,None,None] for _ in range(self.count)]
135-
return self.window
136-
137-
# Replace the window entirely with new data
138-
self.window=[list(slice_) for slice_ in ohlcv]
133+
ohlcv=None
139134

140-
# Enforce fixed window size
141-
if len(self.window)>self.count:
142-
self.window=self.window[-self.count:]
143-
elif len(self.window)<self.count:
144-
padding=[[None,None,None,None,None,None] for _ in range(self.count-len(self.window))]
145-
self.window=padding+self.window
146-
147-
return self.window
135+
return ohlcv
148136

149137
# Update the window with the last two OHLCV values. This replaces the
150138
# incomplete candle from the previous call.
@@ -1360,7 +1348,7 @@ def Hammer(self,OpenIDX=1,HighIDX=2,LowIDX=3,CloseIDX=4):
13601348
us=h-max(o,c) # length of upper wick/shadow
13611349
ls=max(o,c)-l # length of lower wick/shadow
13621350

1363-
if ls>2*b and us>2*b: # spinning top
1351+
if b==0 or (ls>2*b and us>2*b): # spinning top
13641352
isHammer=0
13651353
if ls>2*b and us<b:
13661354
isHammer=1
@@ -1390,7 +1378,7 @@ def InvertedHammer(self,OpenIDX=1,HighIDX=2,LowIDX=3,CloseIDX=4):
13901378
us=h-max(o,c) # length of upper wick/shadow
13911379
ls=max(o,c)-l # length of lower wick/shadow
13921380

1393-
if ls>2*b and us>2*b: # spinning top
1381+
if b==0 or (ls>2*b and us>2*b): # spinning top
13941382
isInvHammer=0
13951383
if us>2*b and ls<b:
13961384
isInvHammer=1
@@ -1539,7 +1527,7 @@ def BearishMarubozu(self,OpenIDX=1,HighIDX=2,LowIDX=3,CloseIDX=4,threshold=0.1):
15391527

15401528
# Highwave candlestick pattern
15411529

1542-
def Highwave(self,OpenIDX=1,HighIDX=2,LowIDX=3,CloseIDX=4,threshold=2):
1530+
def HighWave(self,OpenIDX=1,HighIDX=2,LowIDX=3,CloseIDX=4,threshold=2):
15431531
if len(self.window)<1:
15441532
self.AddColumn(None) # is hammer (1=yes)
15451533
return self.window
@@ -1565,9 +1553,63 @@ def Highwave(self,OpenIDX=1,HighIDX=2,LowIDX=3,CloseIDX=4,threshold=2):
15651553

15661554
return self.window
15671555

1568-
## Single Candlestick Patterns
1556+
# Bullish Belt Hold
1557+
1558+
def BullishBeltHold(self,OpenIDX=1,HighIDX=2,LowIDX=3,CloseIDX=4,threshold=0.1):
1559+
if len(self.window)<1:
1560+
self.AddColumn(None) # is hammer (1=yes)
1561+
return self.window
1562+
1563+
last_row=self.LastRow()
1564+
1565+
o=last_row[OpenIDX]
1566+
h=last_row[HighIDX]
1567+
l=last_row[LowIDX]
1568+
c=last_row[CloseIDX]
1569+
1570+
isBeltHold=0
15691571

1570-
# Belt Hold (Bullish Belt Hold, Bearish Belt Hold)
1572+
b=c-o
1573+
1574+
if b>0:
1575+
us=h-c
1576+
ls=o-l
1577+
1578+
if ls<=(threshold*b) and b>0 and c>o:
1579+
isBeltHold=1
1580+
1581+
self.AddColumn(isBeltHold)
1582+
1583+
return self.window
1584+
1585+
# Bearish Belt Hold
1586+
1587+
def BearishBeltHold(self,OpenIDX=1,HighIDX=2,LowIDX=3,CloseIDX=4,threshold=0.1):
1588+
if len(self.window)<1:
1589+
self.AddColumn(None) # is hammer (1=yes)
1590+
return self.window
1591+
1592+
last_row=self.LastRow()
1593+
1594+
o=last_row[OpenIDX]
1595+
h=last_row[HighIDX]
1596+
l=last_row[LowIDX]
1597+
c=last_row[CloseIDX]
1598+
1599+
isBeltHold=0
1600+
1601+
b=o-c
1602+
1603+
if b>0:
1604+
us=h-o
1605+
ls=c-l
1606+
1607+
if us<=(threshold*b) and b>0 and o>c:
1608+
isBeltHold=1
1609+
1610+
self.AddColumn(isBeltHold)
1611+
1612+
return self.window
15711613

15721614
## Double Candlestick Patterns
15731615

Base/Library/X1

Lines changed: 0 additions & 51 deletions
This file was deleted.
1 KB
Binary file not shown.

Extras/CodeProofs/jrrTA/demo.candlesticks

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,17 @@ import JackrabbitRelay as JRR
1818
import JRRtechnical as jrTA
1919

2020
def main():
21-
ta=jrTA.TechnicalAnalysis('kraken','MAIN','ADA/USD','1m',197)
22-
ohlcv=ta.ReadOHLCV('ADAUSD.txt')
21+
if len(sys.argv) > 4:
22+
exchangeName=sys.argv[1]
23+
account=sys.argv[2]
24+
asset=sys.argv[3]
25+
tf=sys.argv[4]
26+
else:
27+
print("An exchange, (sub)account, an asset, and a timeframe must be provided.")
28+
sys.exit(1)
29+
30+
ta=jrTA.TechnicalAnalysis(exchangeName,account,asset,tf,5000)
31+
ohlcv=ta.GetOHLCV()
2332

2433
Opening=1
2534
HighIDX=2
@@ -32,10 +41,16 @@ def main():
3241

3342
# ta.Doji()
3443
# ta.TriStarDoji()
44+
# ta.Hammer()
45+
# ta.InvertedHammer()
46+
# ta.SpinningTop()
47+
# ta.HangingMan()
48+
# ta.ShootingStar()
3549
# ta.BullishMarubozu()
3650
# ta.BearishMarubozu()
37-
ta.Hammer()
38-
ta.InvertedHammer()
51+
# ta.HighWave()
52+
# ta.BullishBeltHold()
53+
# ta.BearishBeltHold()
3954

4055
ta.Display(-1)
4156

0 commit comments

Comments
 (0)