Skip to content

Commit cc8682d

Browse files
committed
quick fix for renko bricks
1 parent 3e1cc72 commit cc8682d

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/mplfinance/_utils.py

Lines changed: 6 additions & 2 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 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)

0 commit comments

Comments
 (0)