@@ -400,16 +400,25 @@ def plot( data, **kwargs ):
400
400
collections = _construct_mpf_collections (ptype ,dates ,xdates ,opens ,highs ,lows ,closes ,volumes ,config ,style )
401
401
402
402
if ptype in VALID_PMOVE_TYPES :
403
- collections , new_dates , volumes , brick_values , size = collections
404
- formatter = IntegerIndexDateTimeFormatter (new_dates , fmtstring )
405
- xdates = np .arange (len (new_dates ))
403
+ collections , calculated_values = collections
404
+ volumes = calculated_values ['volumes' ]
405
+ pmove_dates = calculated_values ['dates' ]
406
+ pmove_values = calculated_values ['values' ]
407
+ if all ([isinstance (v ,(list ,tuple )) for v in pmove_values ]):
408
+ pmove_avgvals = [sum (v )/ len (v ) for v in pmove_values ]
409
+ else :
410
+ pmove_avgvals = pmove_values
411
+ pmove_size = calculated_values ['size' ]
412
+ pmove_counts = calculated_values ['counts' ] if 'counts' in calculated_values else None
413
+ formatter = IntegerIndexDateTimeFormatter (pmove_dates , fmtstring )
414
+ xdates = np .arange (len (pmove_dates ))
406
415
407
416
if collections is not None :
408
417
for collection in collections :
409
418
axA1 .add_collection (collection )
410
419
411
420
if ptype in VALID_PMOVE_TYPES :
412
- mavprices = _plot_mav (axA1 ,config ,xdates ,brick_values )
421
+ mavprices = _plot_mav (axA1 ,config ,xdates ,pmove_avgvals )
413
422
else :
414
423
mavprices = _plot_mav (axA1 ,config ,xdates ,closes )
415
424
@@ -428,8 +437,8 @@ def plot( data, **kwargs ):
428
437
_lows = lows
429
438
_highs = highs
430
439
else :
431
- _lows = brick_values
432
- _highs = [brick + size for brick in brick_values ]
440
+ _lows = pmove_avgvals
441
+ _highs = [value + pmove_size for value in pmove_avgvals ]
433
442
434
443
miny = np .nanmin (_lows )
435
444
maxy = np .nanmax (_highs )
@@ -458,13 +467,17 @@ def plot( data, **kwargs ):
458
467
459
468
if config ['return_calculated_values' ] is not None :
460
469
retdict = config ['return_calculated_values' ]
461
- if ptype in VALID_PMOVE_TYPES :
462
- prekey = ptype
463
- retdict [prekey + '_bricks' ] = brick_values
464
- retdict [prekey + '_dates' ] = mdates .num2date (new_dates )
465
- retdict [prekey + '_size' ] = size
466
- if config ['volume' ]:
467
- retdict [prekey + '_volumes' ] = volumes
470
+ if ptype == 'renko' :
471
+ retdict ['brick_values' ] = pmove_values
472
+ retdict ['brick_dates' ] = mdates .num2date (pmove_dates )
473
+ retdict ['brick_size' ] = pmove_size
474
+ retdict ['brick_volumes' ] = volumes if config ['volume' ] else None
475
+ elif ptype == 'pnf' :
476
+ retdict ['box_dates' ] = mdates .num2date (pmove_dates )
477
+ retdict ['box_counts' ] = pmove_counts
478
+ retdict ['box_values' ] = pmove_values
479
+ retdict ['box_size' ] = pmove_size
480
+ retdict ['box_volumes' ] = volumes if config ['volume' ] else None
468
481
if config ['mav' ] is not None :
469
482
mav = config ['mav' ]
470
483
if len (mav ) != len (mavprices ):
@@ -480,7 +493,7 @@ def plot( data, **kwargs ):
480
493
# Note: these are NOT mutually exclusive, so the order of this
481
494
# if/elif is important: VALID_PMOVE_TYPES must be first.
482
495
if ptype in VALID_PMOVE_TYPES :
483
- dtix = pd .DatetimeIndex ([dt for dt in mdates .num2date (new_dates )])
496
+ dtix = pd .DatetimeIndex ([dt for dt in mdates .num2date (pmove_dates )])
484
497
elif not config ['show_nontrading' ]:
485
498
dtix = data .index
486
499
else :
0 commit comments