Skip to content

Commit 351e867

Browse files
committed
Merge remote-tracking branch 'upstream/master'
2 parents 7afff49 + 89a6729 commit 351e867

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

src/mplfinance/_utils.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -391,9 +391,13 @@ def _construct_renko_collections(dates, highs, lows, volumes, config_renko_param
391391

392392
volume_cache = 0 # holds the volumes for the dates that were skipped
393393

394-
394+
last_diff_sign = 0 # direction the bricks were last going in -1 -> down, 1 -> up
395395
for i in range(len(cdiff)):
396-
num_bricks = abs(int(round(cdiff[i], 0)))
396+
num_bricks = abs(int(cdiff[i]))
397+
curr_diff_sign = cdiff[i]/abs(cdiff[i])
398+
if last_diff_sign != 0 and num_bricks > 0 and curr_diff_sign != last_diff_sign:
399+
num_bricks -= 1
400+
last_diff_sign = curr_diff_sign
397401

398402
if num_bricks != 0:
399403
new_dates.extend([dates[i]]*num_bricks)
@@ -442,7 +446,7 @@ def _construct_renko_collections(dates, highs, lows, volumes, config_renko_param
442446
linewidths=lw
443447
)
444448

445-
return (rectCollection, ), new_dates, new_volumes, brick_values
449+
return (rectCollection, ), new_dates, new_volumes, brick_values, brick_size
446450

447451
def _construct_pointnfig_collections(dates, highs, lows, volumes, config_pointnfig_params, closes, marketcolors=None):
448452
"""Represent the price change with Xs and Os

src/mplfinance/plotting.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ def plot( data, **kwargs ):
269269
collections = _construct_ohlc_collections(xdates, opens, highs, lows, closes,
270270
marketcolors=style['marketcolors'] )
271271
elif ptype == 'renko':
272-
collections, new_dates, volumes, brick_values = _construct_renko_collections(dates, highs, lows, volumes, config['renko_params'], closes,
272+
collections, new_dates, volumes, brick_values, brick_size = _construct_renko_collections(dates, highs, lows, volumes, config['renko_params'], closes,
273273
marketcolors=style['marketcolors'] )
274274
elif ptype == 'pnf' or ptype == 'p&f' or ptype == 'pointnfigure':
275275
collections, new_dates, volumes, brick_values = _construct_pointnfig_collections(dates, highs, lows, volumes, config['pointnfig_params'], closes,
@@ -325,8 +325,12 @@ def plot( data, **kwargs ):
325325
avg_dist_between_points = (xdates[-1] - xdates[0]) / float(len(xdates))
326326
minx = xdates[0] - avg_dist_between_points
327327
maxx = xdates[-1] + avg_dist_between_points
328-
miny = min([low for low in lows if low != -1])
329-
maxy = max([high for high in highs if high != -1])
328+
if ptype is not 'renko':
329+
miny = min([low for low in lows if low != -1])
330+
maxy = max([high for high in highs if high != -1])
331+
else:
332+
miny = min([brick for brick in brick_values])
333+
maxy = max([brick+brick_size for brick in brick_values])
330334
corners = (minx, miny), (maxx, maxy)
331335
ax1.update_datalim(corners)
332336

0 commit comments

Comments
 (0)