@@ -103,22 +103,45 @@ def _get_valid_plot_types(plottype=None):
103103
104104
105105def _mav_validator (mav_value ):
106- '''
106+ '''
107107 Value for mav (moving average) keyword may be:
108- scalar int greater than 1, or tuple of ints, or list of ints (greater than 1).
109- tuple or list limited to length of 7 moving averages (to keep the plot clean).
108+ scalar int greater than 1, or tuple of ints, or list of ints (each greater than 1)
109+ or a dict of `period` and `shift` each of which may be:
110+ scalar int, or tuple of ints, or list of ints: each `period` int must be greater than 1
110111 '''
111- if isinstance (mav_value ,int ) and mav_value > 1 :
112+ def _valid_mav (value , is_period = True ):
113+ if not isinstance (value ,(tuple ,list ,int )):
114+ return False
115+ if isinstance (value ,int ):
116+ return (value >= 2 or not is_period )
117+ # Must be a tuple or list here:
118+ for num in value :
119+ if not isinstance (num ,int ) or (is_period and num < 2 ):
120+ return False
112121 return True
113- elif not isinstance (mav_value ,tuple ) and not isinstance (mav_value ,list ):
122+
123+ if not isinstance (mav_value ,(tuple ,list ,int ,dict )):
114124 return False
115125
116- if not len (mav_value ) < 8 :
126+ if not isinstance (mav_value ,dict ):
127+ return _valid_mav (mav_value )
128+
129+ else : #isinstance(mav_value,dict)
130+ if 'period' not in mav_value : return False
131+
132+ period = mav_value ['period' ]
133+ if not _valid_mav (period ): return False
134+
135+ if 'shift' not in mav_value : return True
136+
137+ shift = mav_value ['shift' ]
138+ if not _valid_mav (shift , False ): return False
139+ if isinstance (period ,int ) and isinstance (shift ,int ): return True
140+ if isinstance (period ,(tuple ,list )) and isinstance (shift ,(tuple ,list )):
141+ if len (period ) != len (shift ): return False
142+ return True
117143 return False
118- for num in mav_value :
119- if not isinstance (num ,int ) and num > 1 :
120- return False
121- return True
144+
122145
123146def _hlines_validator (value ):
124147 if isinstance (value ,dict ):
0 commit comments