From 42971826b5e0a99613ce51cb0d97d14922976239 Mon Sep 17 00:00:00 2001 From: "Dr. Chandrakant Bangar" <127198654+DrChandrakant@users.noreply.github.com> Date: Fri, 9 Jun 2023 18:49:27 +0530 Subject: [PATCH 1/5] Create binancedark.py Feature Request: New style called binance-dark #614 style Created --- src/mplfinance/_styledata/binancedark.py | 27 ++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/mplfinance/_styledata/binancedark.py diff --git a/src/mplfinance/_styledata/binancedark.py b/src/mplfinance/_styledata/binancedark.py new file mode 100644 index 00000000..eab60f00 --- /dev/null +++ b/src/mplfinance/_styledata/binancedark.py @@ -0,0 +1,27 @@ +style = dict(style_name = 'binancedark', + base_mpl_style= 'dark_background', + marketcolors = {'candle' : {'up': '#3dc985', 'down': '#ef4f60'}, + 'edge' : {'up': '#3dc985', 'down': '#ef4f60'}, + 'wick' : {'up': '#3dc985', 'down': '#ef4f60'}, + 'ohlc' : {'up': 'green', 'down': 'red'}, + 'volume' : {'up': '#247252', 'down': '#82333f'}, + 'vcedge' : {'up': 'green', 'down': 'red'}, + 'vcdopcod' : False, + 'alpha' : 1.0, + }, + mavcolors = ['#ffc201','#ff10ff','#cd0468','#1f77b4', + '#ff7f0e','#2ca02c','#40e0d0'], + y_on_right = True, + gridcolor = None, + gridstyle = '--', + facecolor = None, + rc = [ ('axes.grid','True'), + ('axes.grid.axis' , 'y'), + ('axes.edgecolor' , '#474d56' ), + ('axes.titlecolor','red'), + ('figure.titlesize', 'x-large' ), + ('figure.titleweight','semibold'), + ('figure.facecolor', '#0a0a0a' ), + ], + base_mpf_style= 'binancedark' + ) From b859305abde8abdcaf46981cbfa2ad8ce34c60b7 Mon Sep 17 00:00:00 2001 From: "Dr. Chandrakant Bangar" <127198654+DrChandrakant@users.noreply.github.com> Date: Tue, 13 Jun 2023 17:34:13 +0530 Subject: [PATCH 2/5] Update __init__.py --- src/mplfinance/_styledata/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/mplfinance/_styledata/__init__.py b/src/mplfinance/_styledata/__init__.py index 0dcbf598..373d1da0 100644 --- a/src/mplfinance/_styledata/__init__.py +++ b/src/mplfinance/_styledata/__init__.py @@ -16,6 +16,7 @@ from mplfinance._styledata import binance from mplfinance._styledata import kenan from mplfinance._styledata import ibd +from mplfinance._styledata import binancedark _style_names = [n for n in dir() if not n.startswith('_')] From 5a15c77faa342698b6238f0a50537b82442ef99c Mon Sep 17 00:00:00 2001 From: "Dr. Chandrakant Bangar" <127198654+DrChandrakant@users.noreply.github.com> Date: Tue, 13 Jun 2023 22:36:51 +0530 Subject: [PATCH 3/5] New Compact Theme 'Trading View' Add A New Compact Theme Named as `tradingview` was added. ### List of Features Updated - Mostly Useful For `type=hollow_and_filled`. Compatible With All Other Types of Plots. - If `style = tradingview` Title of Plot Remove From `fig.suptitle()` and Migrated To Legend Box. - Dynamically `volume_width` Changed to 0.80 So the Thin Volume Candles Are Plot - If 'volume = True' Grid of Volume Panel Is Disable --- src/mplfinance/_styledata/__init__.py | 1 + src/mplfinance/_styledata/tradingview.py | 27 ++++++++++++++++++++++++ src/mplfinance/_widths.py | 12 ++++++++++- src/mplfinance/plotting.py | 14 +++++++++++- 4 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 src/mplfinance/_styledata/tradingview.py diff --git a/src/mplfinance/_styledata/__init__.py b/src/mplfinance/_styledata/__init__.py index 373d1da0..89349f95 100644 --- a/src/mplfinance/_styledata/__init__.py +++ b/src/mplfinance/_styledata/__init__.py @@ -17,6 +17,7 @@ from mplfinance._styledata import kenan from mplfinance._styledata import ibd from mplfinance._styledata import binancedark +from mplfinance._styledata import tradingview _style_names = [n for n in dir() if not n.startswith('_')] diff --git a/src/mplfinance/_styledata/tradingview.py b/src/mplfinance/_styledata/tradingview.py new file mode 100644 index 00000000..2fc4e30a --- /dev/null +++ b/src/mplfinance/_styledata/tradingview.py @@ -0,0 +1,27 @@ +style = dict(style_name = 'tradingview', + base_mpl_style= 'fast', + marketcolors = {'candle' : {'up': '#26a69a', 'down': '#ef5350'}, + 'edge' : {'up': '#26a69a', 'down': '#ef5350'}, + 'wick' : {'up': '#26a69a', 'down': '#ef5350'}, + 'ohlc' : {'up': '#26a69a', 'down': '#ef5350'}, + 'volume' : {'up': '#26a69a', 'down': '#ef5350'}, + 'vcedge' : {'up': '#26a69a', 'down': '#ef5350'}, + 'vcdopcod' : False, + 'alpha' : 1.0, + }, + mavcolors = ['#ffc201','#ff10ff','#cd0468','#1f77b4', + '#ff7f0e','#2ca02c','#40e0d0'], + y_on_right = True, + gridcolor = None, + gridstyle = '--', + facecolor = None, + rc = [ ('axes.grid','True'), + #('axes.grid.axis' , 'y'), + ('axes.edgecolor' , 'grey' ), + ('axes.titlecolor','red'), + ('figure.titlesize', 'x-large' ), + ('figure.titleweight','semibold'), + ('figure.facecolor', 'white' ), + ], + base_mpf_style = 'tradingview' + ) diff --git a/src/mplfinance/_widths.py b/src/mplfinance/_widths.py index 3b6813c4..1239820b 100644 --- a/src/mplfinance/_widths.py +++ b/src/mplfinance/_widths.py @@ -138,11 +138,21 @@ def _determine_width_config( xdates, config ): width_config['candle_linewidth'] = _dfinterpolate(_widths,datalen,'clw') width_config['line_width' ] = _dfinterpolate(_widths,datalen,'lw') + + if config['scale_width_adjustment'] is None: + if config['style']['base_mpf_style'] == 'tradingview': + width_config['volume_width'] *= 0.80 + else: + pass + if config['scale_width_adjustment'] is not None: scale = _process_kwargs(config['scale_width_adjustment'],_valid_scale_width_kwargs()) if scale['volume'] is not None: - width_config['volume_width'] *= scale['volume'] + if config['style']['base_mpf_style'] == 'tradingview': + width_config['volume_width'] *= 0.80 + else: + width_config['volume_width'] *= scale['volume'] if scale['ohlc'] is not None: width_config['ohlc_ticksize'] *= scale['ohlc'] if scale['candle'] is not None: diff --git a/src/mplfinance/plotting.py b/src/mplfinance/plotting.py index 2fecd8c3..8d5777c8 100644 --- a/src/mplfinance/plotting.py +++ b/src/mplfinance/plotting.py @@ -502,6 +502,10 @@ def plot( data, **kwargs ): panels.at[config['main_panel'],'used2nd'] = True else: volumeAxes = panels.at[config['volume_panel'],'axes'][0] + if config['style']['base_mpf_style'] == 'tradingview': + volumeAxes.grid(False) + else: + pass else: volumeAxes = None @@ -840,6 +844,11 @@ def plot( data, **kwargs ): axA1.set_ylabel(config['ylabel']) + if config['title']: + script_title = config['title'] + else: + script_title = None + if config['volume']: if external_axes_mode: volumeAxes.tick_params(axis='x',rotation=xrotation) @@ -910,7 +919,10 @@ def plot( data, **kwargs ): title_kwargs.update(title_dict) # allows override default values set by mplfinance above else: title = config['title'] # config['title'] is a string - fig.suptitle(title,**title_kwargs) + if config['style']['base_mpf_style'] == 'tradingview': + axA1.legend(['Price'],title=script_title, title_fontsize='large',loc='upper left',frameon=False) + else: + fig.suptitle(title,**title_kwargs) if config['axtitle'] is not None: From 59382decab54e7b20b1ee46b42f32618d8abc65b Mon Sep 17 00:00:00 2001 From: "Dr. Chandrakant Bangar" <127198654+DrChandrakant@users.noreply.github.com> Date: Thu, 15 Jun 2023 18:32:00 +0530 Subject: [PATCH 4/5] Modifications Done Primary application Tradingview theme use fill and hallow --- src/mplfinance/_styledata/binancedark.py | 4 ++-- src/mplfinance/_styledata/tradingview.py | 10 +++++----- src/mplfinance/_version.py | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/mplfinance/_styledata/binancedark.py b/src/mplfinance/_styledata/binancedark.py index eab60f00..3ad8be10 100644 --- a/src/mplfinance/_styledata/binancedark.py +++ b/src/mplfinance/_styledata/binancedark.py @@ -5,7 +5,7 @@ 'wick' : {'up': '#3dc985', 'down': '#ef4f60'}, 'ohlc' : {'up': 'green', 'down': 'red'}, 'volume' : {'up': '#247252', 'down': '#82333f'}, - 'vcedge' : {'up': 'green', 'down': 'red'}, + 'vcedge' : {'up': '#247252', 'down': '#82333f'}, 'vcdopcod' : False, 'alpha' : 1.0, }, @@ -24,4 +24,4 @@ ('figure.facecolor', '#0a0a0a' ), ], base_mpf_style= 'binancedark' - ) + ) \ No newline at end of file diff --git a/src/mplfinance/_styledata/tradingview.py b/src/mplfinance/_styledata/tradingview.py index 2fc4e30a..91e42472 100644 --- a/src/mplfinance/_styledata/tradingview.py +++ b/src/mplfinance/_styledata/tradingview.py @@ -5,18 +5,18 @@ 'wick' : {'up': '#26a69a', 'down': '#ef5350'}, 'ohlc' : {'up': '#26a69a', 'down': '#ef5350'}, 'volume' : {'up': '#26a69a', 'down': '#ef5350'}, - 'vcedge' : {'up': '#26a69a', 'down': '#ef5350'}, + 'vcedge' : {'up': 'white' , 'down': 'white' }, 'vcdopcod' : False, 'alpha' : 1.0, + 'volume_alpha': 0.65, }, - mavcolors = ['#ffc201','#ff10ff','#cd0468','#1f77b4', - '#ff7f0e','#2ca02c','#40e0d0'], + scale_width_adjustment = { 'volume': 0.8 }, + mavcolors = ['#2962ff','#2962ff',], y_on_right = True, gridcolor = None, gridstyle = '--', facecolor = None, rc = [ ('axes.grid','True'), - #('axes.grid.axis' , 'y'), ('axes.edgecolor' , 'grey' ), ('axes.titlecolor','red'), ('figure.titlesize', 'x-large' ), @@ -24,4 +24,4 @@ ('figure.facecolor', 'white' ), ], base_mpf_style = 'tradingview' - ) + ) \ No newline at end of file diff --git a/src/mplfinance/_version.py b/src/mplfinance/_version.py index 9929be97..bc874c3c 100644 --- a/src/mplfinance/_version.py +++ b/src/mplfinance/_version.py @@ -1,4 +1,4 @@ -version_info = (0, 12, 9, 'beta', 8) +version_info = (0, 12, 9, 'beta', 9) _specifier_ = {'alpha': 'a','beta': 'b','candidate': 'rc','final': ''} From a5df6a0a3af54260b6c04d810704b4cf3b0cd6f7 Mon Sep 17 00:00:00 2001 From: "Dr. Chandrakant Bangar" <127198654+DrChandrakant@users.noreply.github.com> Date: Thu, 15 Jun 2023 20:28:17 +0530 Subject: [PATCH 5/5] Width Related Modification Complete Width Related Modification Complete. Label and Legend Box Kept Same --- src/mplfinance/_widths.py | 44 ++++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 24 deletions(-) diff --git a/src/mplfinance/_widths.py b/src/mplfinance/_widths.py index 1239820b..9b8cb69c 100644 --- a/src/mplfinance/_widths.py +++ b/src/mplfinance/_widths.py @@ -102,6 +102,21 @@ def _valid_update_width_kwargs(): return vkwargs +def _scale_width_config(scale,width_config): + if scale['volume'] is not None: + width_config['volume_width'] *= scale['volume'] + if scale['ohlc'] is not None: + width_config['ohlc_ticksize'] *= scale['ohlc'] + if scale['candle'] is not None: + width_config['candle_width'] *= scale['candle'] + if scale['lines'] is not None: + width_config['line_width'] *= scale['lines'] + if scale['volume_linewidth'] is not None: + width_config['volume_linewidth'] *= scale['volume_linewidth'] + if scale['ohlc_linewidth'] is not None: + width_config['ohlc_linewidth' ] *= scale['ohlc_linewidth'] + if scale['candle_linewidth'] is not None: + width_config['candle_linewidth'] *= scale['candle_linewidth'] def _determine_width_config( xdates, config ): ''' @@ -138,33 +153,14 @@ def _determine_width_config( xdates, config ): width_config['candle_linewidth'] = _dfinterpolate(_widths,datalen,'clw') width_config['line_width' ] = _dfinterpolate(_widths,datalen,'lw') - - if config['scale_width_adjustment'] is None: - if config['style']['base_mpf_style'] == 'tradingview': - width_config['volume_width'] *= 0.80 - else: - pass + if 'scale_width_adjustment' in config['style']: + scale = _process_kwargs(config['style']['scale_width_adjustment'],_valid_scale_width_kwargs()) + _scale_width_config(scale,width_config) if config['scale_width_adjustment'] is not None: - scale = _process_kwargs(config['scale_width_adjustment'],_valid_scale_width_kwargs()) - if scale['volume'] is not None: - if config['style']['base_mpf_style'] == 'tradingview': - width_config['volume_width'] *= 0.80 - else: - width_config['volume_width'] *= scale['volume'] - if scale['ohlc'] is not None: - width_config['ohlc_ticksize'] *= scale['ohlc'] - if scale['candle'] is not None: - width_config['candle_width'] *= scale['candle'] - if scale['lines'] is not None: - width_config['line_width'] *= scale['lines'] - if scale['volume_linewidth'] is not None: - width_config['volume_linewidth'] *= scale['volume_linewidth'] - if scale['ohlc_linewidth'] is not None: - width_config['ohlc_linewidth' ] *= scale['ohlc_linewidth'] - if scale['candle_linewidth'] is not None: - width_config['candle_linewidth'] *= scale['candle_linewidth'] + _scale_width_config(scale,width_config) + if config['update_width_config'] is not None: