Skip to content

Commit d2f1147

Browse files
committed
fix volume and mav data and scale box width
1 parent 4532941 commit d2f1147

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

src/mplfinance/_utils.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ def _construct_pf_collections(dates, highs, lows, volumes, config_renko_params,
508508
diff = abs(int(round(difference, 0)))
509509
if volumes is not None: # only adds volumes if there are volume values when volume=True
510510
if diff != 0:
511-
new_volumes.extend([volumes[diff_index] + volume_cache]*diff)
511+
new_volumes.append(volumes[diff_index] + volume_cache)
512512
volume_cache = 0
513513
else:
514514
volume_cache += volumes[diff_index]
@@ -521,21 +521,27 @@ def _construct_pf_collections(dates, highs, lows, volumes, config_renko_params,
521521

522522

523523
sign = (difference / abs(difference)) # -1 or 1
524-
x = [index] * (diff)
525524
start_iteration = 0 if sign > 0 else 1
526525
start_iteration += 0 if (last_trend_positive and sign > 0) or (not last_trend_positive and sign < 0) else 1
527526

528-
y = [(curr_price + (i * box_size * sign)) for i in range(start_iteration, diff+start_iteration)]
529-
box_values.extend(y)
527+
x = [index] * (diff)
528+
y = [(curr_price + ((i+(box_size * 0.01)) * box_size * sign)) for i in range(start_iteration, diff+start_iteration)]
529+
530530

531531
spacing = 0.1 * box_size
532532
curr_price += (box_size * sign * (diff)) + spacing
533+
box_values.append(curr_price - spacing - box_size)
534+
533535
for i in range(len(x)): # x and y have the same length
536+
height = box_size * 0.9
537+
width = min(0.5 * (box_size * 0.2), 0.9)
538+
if height < 0.5:
539+
width = height
534540
if sign == 1: # X
535-
line_seg.append([(x[i]-0.25, y[i]-(box_size/2)), (x[i]+0.25, y[i]+(box_size/2))]) # create / part of the X
536-
line_seg.append([(x[i]-0.25, y[i]+(box_size/2)), (x[i]+0.25, y[i]-(box_size/2))]) # create \ part of the X
541+
line_seg.append([(x[i]-width/2, y[i]-(height/2)), (x[i]+width/2, y[i]+(height/2))]) # create / part of the X
542+
line_seg.append([(x[i]-width/2, y[i]+(height/2)), (x[i]+width/2, y[i]-(height/2))]) # create \ part of the X
537543
else: # O
538-
circle_patches.append(Ellipse((x[i], y[i]), 0.5, box_size/0.9))
544+
circle_patches.append(Ellipse((x[i], y[i]), width, height))
539545
useAA = 0, # use tuple here
540546
lw = 0.5
541547

0 commit comments

Comments
 (0)