@@ -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
0 commit comments