Point and figure chart custom y axis using gfx*

I finally (almost) got the code done for the gfx* version of the point and figure chart. I would like to implement a custom y axis that sits on top of the regular y axis but draw in the minor lines and text in the values, the y value will change depending on log version or regular version etc., however, the first step is to be able to draw a line that sits right at the regular y axis location, please help. Thanks.
pf

I rarely used GFX but was trying it out and i found some useful arguments in Status().

In pixel mode, you can anchor the line in the chart area near Y-AXIS or even on top of it

GfxSetCoordsMode( 0 );
GfxSelectPen( colorRed);
GfxMoveTo( Status("pxchartwidth"), 0);
GfxLineTo( Status("pxchartwidth"), Status("pxchartbottom") );
// more lines

image

Status("pxchartwidth") + 20
image

3 Likes

Everything is there in the manual. You just have to spend time.

1 Like

if you installed the Python plugin you can also play around with code that is available in Python. I just tried this 1: https://github.com/matplotlib/mplfinance/blob/master/examples/price-movement_plots.ipynb

I made a simple implementation. I assume you figure out how to get it running. Resulting chart for some hourly @ES# data.

the AFL code:

PyLoadFromFile( "PnF", "C:\\Users\\win 10\\AppData\\Local\\Programs\\Python\\Python38\\mypython\\pointandfigure.py" );

trig1 = ParamTrigger( "Trig1", "Show PnF" );

yearArray = Year();
monthArray = Month();
dayArray = Day();
hourArray = Hour();
minuteArray = Minute();
secondArray = Second();
openArray = Open;
highArray = High;
lowArray = Low;
closeArray = Close;
volumeArray = Volume;


if( trig1 )
{
    outputArray = PyEvalFunction( "PnF", "calculatePnF", yearArray, monthArray, dayArray,
                                  hourArray, minuteArray, secondArray, openArray, highArray, lowArray, closeArray, volumeArray );
}

the Python code:

'''
https://github.com/matplotlib/mplfinance
'''
import pandas as pd                             # pip install pandas
import mplfinance as mpf                        # pip install --upgrade mplfinance
import AmiPy                                    # install AmiPy plugin in Amibroker

def calculatePnF(year, month, day, hour, minute, second, open, high, low, close, volume):

    df = pd.DataFrame()

    df['Year'] = year.astype(int)
    df['Month'] = month.astype(int)
    df['Day'] = day.astype(int)
    df['Hour'] = hour.astype(int)
    df['Minute'] = minute.astype(int)
    df['Second'] = second.astype(int)

    df['High'] = high
    df['Low'] = low
    df['Open'] = open
    df['Close'] = close
    df['Volume'] = volume

    df.fillna(value=0, inplace=True) # replace all empty values with 0
    a_series = (df != 0).any(axis=1) # drop rows entirely consisting of zeros
    df = df.loc[a_series]

    df['Datetime'] = pd.to_datetime(df[['Year', 'Month', 'Day', 'Hour', 'Minute','Second']])
    df.index = df.Datetime

    df.drop(['Datetime'], axis='columns', inplace=True)
    df.drop(['Year'], axis='columns', inplace=True)
    df.drop(['Month'], axis='columns', inplace=True)
    df.drop(['Day'], axis='columns', inplace=True)
    df.drop(['Hour'], axis='columns', inplace=True)
    df.drop(['Minute'], axis='columns', inplace=True)
    df.drop(['Second'], axis='columns', inplace=True)

    # AmiPy.Print(str(df))

    mpf.plot(df,type='pnf',style='starsandstripes')

here is how a chart looks like when you press the trigger in the AFL code

Figure_1

7 Likes

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.