Search code examples
pythonmplfinance

kwarg "alines" validator returned False


The message is telling me something but I can't see it:

TypeError: kwarg "alines" validator returned False for value: "{'alines': [[(Timestamp('2020-09-08 00:00:00'), 40.0), (Timestamp('2021-03-19 00:00:00'), 35.82)], [(Timestamp('2020-09-08 00:00:00'), 35.82), (Timestamp('2021-03-19 00:00:00'), 35.82)], [(datetime.datetime(2021, 2, 17, 0, 0), '47.5'), (datetime.datetime(2021, 2, 26, 0, 0), '47.5')], [(datetime.datetime(2021, 2, 25, 0, 0), '47'), (datetime.datetime(2021, 3, 19, 0, 0), '47')]], 'colors': ['b', 'g'], 'linestyle': '--'}"
    'Validator'   : lambda value: _alines_validator(value) },

It happens on this call:

mpf.plot(df_history, show_nontrading=True,
         alines=dict(alines=seq_of_points, colors=['b', 'g'], linestyle='--'),
         type='candle', style=s, savefig=bildpfad, 
         update_width_config=dict(candle_linewidth=0.4))

Solution

  • The problem is you have some strings in your alines specification where you should have floats. This is what your alines specification looks like (pprint):

    {'alines': [[(Timestamp('2020-09-08 00:00:00'), 40.0),
                 (Timestamp('2021-03-19 00:00:00'), 35.82)],
                [(Timestamp('2020-09-08 00:00:00'), 35.82),
                 (Timestamp('2021-03-19 00:00:00'), 35.82)],
                [(datetime.datetime(2021, 2, 17, 0, 0), '47.5'),
                 (datetime.datetime(2021, 2, 26, 0, 0), '47.5')],
                [(datetime.datetime(2021, 2, 25, 0, 0), '47'),
                 (datetime.datetime(2021, 3, 19, 0, 0), '47')]],
     'colors': ['b', 'g'],
     'linestyle': '--'}
    

    Notice that for the last two line segments (those that use datetime.datetime instead of Timestamp (which is fine)), instead of float for the price value, you have strings.

    For example, '47.5' instead of 47.5