This is read-only version of AFL library entry. Ability to add user formulas
and comment is only available from members-only area.
Details:
Formula name:
PF Chart - Close - April 2004
Author/Uploader:
Graham Kavanagh - gkavanagh [at] e-wire.net.au
Date/Time added:
2004-04-19 09:03:31
Origin:
Previous PF Sep 2003
Keywords:
P&F Point Figure PF PnF
Level:
semi-advanced
Flags:
indicator
DISCLAIMER: Most formulas present in AFL on-line library are submitted
by the users and are provided here on an "as is" and "as available" basis.
AmiBroker.com
makes no representations or warranties of any kind to the contents or the operation
of material presented here. We do not maintain nor provide technical support
for 3rd party formulas. Description:
P&F chart based on closing price.
Dates and bar numbers added for reference when the columns started and ended. Load file into IB.
Box size based on ATR of close price. Reverse = 3.
Formula:
// P&F chart based on closing price
// Date & Bar Number of start & end of columns
// Graham Kavanagh 17 Apr 2004
// Interpretation window data included
// 1:1 Line drawn when column selected with slope=boxsize
// Box size based on ATR of closing price
Version(4.53);
SetBarsRequired(100000,100000);
range = Min(260,BarCount/2);
box = LastValue( round(ATR(range)*100)/100 );
Reverse = 3 ; // reversal requirement
CX = round(C/box);
CF = ceil(Cx);
CR = floor(Cx);
Bar = BarIndex();
BarDate = DateNum();
BarTurn = 0;
BarEnd = 0;
// initialize first element
j = 0;
PFC[j] = CF[0];
PFO[j] = CF[0]+1;
down = 1; // By default the first bar is a down bar.
up = 0;
// perform the loop that produces PF Chart
for( i = 1; i < BarCount; i++ )
{
if( CF[i] <= PFC[j]-1 && down) //continue down
{
PFC[j] = CF[i];
PFO[j] = CF[i]+1;
BarEnd[j] = Bar[i];
}
else
{
if( CR[i] >= PFC[j] + Reverse && down) //Change direction to up
{
j++;
up = 1;
down = 0;
PFC[j] = CR[i];
PFO[j] = CR[i] - 1;
BarTurn[j] = Bar[i];
BarEnd[j] = Bar[i];
}
}
if( CR[i] >= PFC[j] + 1 && up) //Continue up
{
PFC[j] = CR[i];
PFO[j] = CR[i] - 1;
BarEnd[j] = Bar[i];
}
else
{
if( CF[i] <= PFC[j] - Reverse && up) //Change direction to down
{
j++;
up = 0;
down = 1;
PFC[j] = CR[i];
PFO[j] = CR[i]+1;
BarTurn[j] = Bar[i];
BarEnd[j] = Bar[i];
}
}
}
delta = BarCount-1 - j;
BarTurns = Ref( BarTurn, -delta);
BarEnds = Ref( BarEnd, -delta);
PFO = Ref( PFO, -delta );
PFC = Ref( PFC, -delta );
H = IIf( Ref(PFC,-1)>Ref(PFO,-1), Ref(HHV(PFC,1),-1)-1, Max(PFO,PFC) )*box +
box/2;
L = IIf( Ref(PFC,-1)<Ref(PFO,-1), Ref(LLV(PFC,1),-1)+1, Min(PFO,PFC) )*box -
box/2;
O = IIf( Ref(PFC,-1)>Ref(PFO,-1), Ref(HHV(PFC,1),-1)-1, IIf(
Ref(PFc,-1)<Ref(PFO,-1), Ref(LLV(PFC,1),-1)+1, PFO ) )*box;
// the difference between Open AND Close is set to box size
// the sign decides if X or O are plotted
C = O + box * IIf( PFC > PFO, 1, -1 );
top = H - box/2;
bot = L + box/2;
GraphXSpace = 5;
_N(
Title = Name() + " " + Date() + ": PF System, H: $" + Top + ", L: $" + Bot + ",
Box $" + Box + " Reversal " + Reverse + "\n" + "NewCol bar " + BarTurns + " date
" + WriteVal(
ValueWhen(BarIndex()==SelectedValue(BarTurns),DateTime()),formatDateTime) + "
ColEnd bar " + BarEnds + " date " + WriteVal(
ValueWhen(BarIndex()==SelectedValue(BarEnds),DateTime()),formatDateTime)
);
Plot(C, "P&F Close", IIf( PFC > PFO, colorBlue, colorRed ), styleCandle +
stylePointAndFigure);
LineUp = LineArray( SelectedValue(BarIndex()), SelectedValue(L),
SelectedValue(BarIndex())+1, SelectedValue(L)+box, 1, 0 );
Linedown = LineArray( SelectedValue(BarIndex()), SelectedValue(H),
SelectedValue(BarIndex())+1, SelectedValue(H)-box, 1, 0 );
Plot(IIf(SelectedValue(PFC<PFO),Lineup,Null), "Line", colorGreen, styleLine +
styleNoLabel + styleNoRescale);
Plot(IIf(SelectedValue(PFC>PFO),Linedown,Null), "Line", colorBrown, styleLine +
styleNoLabel + styleNoRescale);
//--Indicator-End--
Name() +", "+FullName();
"";
"Direction = " + WriteIf(pfc>pfo,"Up","Down");
"Move Today = " + WriteIf(BarIndex()==SelectedValue(BarEnds),"Yes" +
WriteIf(BarIndex()==SelectedValue(BarTurns),", New Column", ",
Continuation"),"No");
"";
"Column Start \n BarIndex() = " + BarTurns + "\n Date() = " + WriteVal(
ValueWhen(BarIndex()==SelectedValue(BarTurns), DateTime()), formatDateTime) ;
"Column End \n BarIndex() = " + BarEnds + "\n Date() = " + WriteVal(
ValueWhen(BarIndex()==SelectedValue(BarEnds),DateTime()),formatDateTime) ;
Comments:
Steve affrica [at] bigpond.net.au 2004-04-26 05:56:37
Looks great!
I would assume that the box size would alter over time. Could this be a problem?
Steve
Graham gkavanagh [at] e-wire.net.au 2004-05-02 06:48:36
The box size is related to the volatility of the stock and I have included one way to do it here. With increased volatility I would want the box size larger to counter the noise of the market.
Geo geosing [at] enooks.com 2004-05-26 18:33:05
Nice piece of code - still studying. Some questions:
1. I am curious why the (styleCandle +
stylePointAndFigure). Just the PnF style appears to work okay....
2. I plan to adapt this for Wyckoff 1 point figure charts. For this, I need to be able to mix 0 and X in the same column. When there is only one X or 0, reversals are plotted in the same column. Not sure if there are any challenges for doing this. I guess I don't end the bar if there is only one symbol after a new reversal...
Thanks again for sharing the code.
Geo
Geo geosing [at] enooks.com 2004-05-26 20:16:36
Nice piece of code - still studying. Some questions:
1. I am curious why the (styleCandle +
stylePointAndFigure). Just the PnF style appears to work okay....
2. I plan to adapt this for Wyckoff 1 point figure charts. For this, I need to be able to mix 0 and X in the same column. When there is only one X or 0, reversals are plotted in the same column. Not sure if there are any challenges for doing this. I guess I don't end the bar if there is only one symbol after a new reversal...
Thanks again for sharing the code.
Geo
Graham Kavanagh gkavanagh [at] e-wire.net.au 2004-05-28 04:32:40
Geo
The stylecandle is probabaly a hangover from earlier versions.
To change all you need to do is add another condition to check of enough boxes are present in the existing column (J) in the reversal lines.
Graham
New2AFL
2007-08-26 08:59:56
Graham, want you to know people appreciate your hard work long after you move on.
I found a cosmetic item related to the title. When a selection is made, the title displays the date (in the first line) as though the horizontal display was a non-P&F chart. (Turn on "Show Date Axis?" under "Axes & Grid" of the chart properties to see what I mean.) Since time is compressed in the P&F plot that horizontal scale may not be relevant.
Since the dates used in the selected bar are displayed in the second line of the title, I chose to make the date in the first line, the date when the chart is being viewed. Then a capture or printout shows when I last reviewed the plot.
I did this by changing the first section of the Title statement from:
Title = Name() + " " + Date() + ": PF System, H: $" + Top +
to:
Title = Name() + " " + Now(1) + ": PF System, H: $" + Top +
PR pr3 [at] directbox.com 2007-12-25 11:22:48
Could anyone code a variation that plots DORSEY´s PnF Relative Strength (comparison to any other value): issue 1 DIVIDED BY issue 2 TIMES 100.