Search code examples
pythonmplfinance

Identifying stocks where the last column in a P&F chart contains three or more "X" plots


First: mplfinance is a super great program for helping with my stock trading: thank you.

Once a week, I download, and use mplfinance to graph the stocks on the S&P 500. I would like to scan the stocks using the P&F charting method and identify the stocks where the last column contains three or more "X" plots without having to physically view each chart. I would appreciate any ideas.

Thanks,

Manny


Solution

  • New version (0.12.7a12) of mplfinance is now released:

    pip install --upgrade mplfinance
    

    In this version, if you do the following:

    cv = {}
    mpf.plot(df,type=pnf,return_calculated_values=cv)
    

    Then the "calculated values" dict, cv, will be filled with the following items:

    dict_keys(['pnf_dates', 'pnf_counts', 'pnf_values', 'pnf_avgvals', 
               'pnf_size', 'pnf_volumes', 'minx', 'maxx', 'miny', 'maxy'])
    
    • cv['pnf_counts'] will contain the number of boxes for each date in cv['pnf_dates']. It will be a positive value for up boxes, X, and a negative value for down boxes, O.
    • cv['pnf_values'] will be a list of lists. The outer list corresponds to each pnf date, and the inner list at each date corresponds to the beginning value of each box on that date: "beginning" means it is the lower bound of an upward box, or the upper bound of a downward box. For an upward box, the X spans from this value to (value + pnf_size), and for a downward box, the O spans from this value to (value - pnf_size)
    • cv['pnf_avgvals'] is the average of all pnf_values for a given date, and is the same as pnf_bricks that was returned by the previous version of mplfinance.

    Hope this helps. All the best.