Welcome Features News Download Registration Support FAQ Wish list Links
Advanced stock charting and analysis program

AFL Library

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: P&F Chart - High/Low prices Sept2003
Author/Uploader: Graham Kavanagh - gkavanagh [at] e-wire.net.au
Date/Time added: 2003-10-01 02:44:23
Origin: Australia
Keywords:
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:

Supersedes other P&F versions in this and yahoo files.
P&F chart for V4.40 and above. Based on close prices.
Problem resolved with boxes not being created at right prices due to the 9 decimal place inaccuracies for numbers with decimals. This was causing a problem creating the rising and falling boxes with the Ceil and Floor functions.
Place in indicator builder. Chart is compacted to the right end of the chart space ending on last date bar.
Box sizes and reverse can be changed near the beginning of the afl code within the "Boxsize = IIF" statements.

Formula:

//AFL P&F Chart for Amibroker Indicator window. Based on High/low prices.
//Based on code in AB help files
//Reverse is 3 boxes.
//Graham Kavanagh 30 Sep 2003

Version(4.40);
SetBarsRequired(100000,100000);

//Size for P&F boxes
boxsize=IIf(C<0.05, 0.001,
IIf(C>=0.05 AND C<0.1, 0.002,
IIf(C>=0.1 AND C<0.5, 0.005,
IIf(C>=0.5 AND C<2, 0.01,
IIf(C>=2 AND C<5, 0.02,
IIf(C>=5 AND C<10, 0.05,
IIf(C>=10 AND C<50, 0.1,
IIf(C>=50 AND C<100, 0.2,
IIf(C>=100 AND C<200, 0.5,
IIf(C>=200 AND C<500, 1,
2 ))))))))));
Box = LastValue(boxsize);
HX = round((H/box)*10)/10;
LX = round((L/box)*10)/10;
RH = floor(HX);
FL = ceil(LX);


// initialize first element
j = 0;

Reverse = 3;                      // reversal requirement

PFC[j] = FL[0];
PFO[j] = PFC[j] + 1;
down = 1;                  // By default the first bar is a down bar.
up = 0;
swap = 0;

// perform the loop that produces PF Chart
for( i = 1; i < BarCount; i++ )
{

 if( FL[i] <= PFC[j]-1 && down)         //continue down
 {
  PFC[j] = FL[i];
  PFO[j] = PFC[j] + 1;
 }
 else
 {
  if( RH[i] >= PFC[j] + Reverse && down)  //Change direction to up
  {
   j++;
   swap = 1;
   PFC[j] = RH[i];
   PFO[j] = PFC[j]-1;
  }
 }
 if( RH[i] >= PFC[j] + 1 && up)         //Continue up
 {
  PFC[j] = RH[i];
  PFO[j] = PFC[j] - 1;
 }
 else
 {
  if( FL[i] <= PFC[j] - Reverse && up)   //Change direction to down
  {
   j++;
   PFC[j] = FL[i];
   PFO[j] = PFC[j] + 1;
   swap = 1;
  }
 }
 if( swap )
 {
  swap = 0;
  if( up )
  {
   up = 0;
   down = 1;
  }
  else
  {
   up = 1;
   down = 0;
  }
 }
}
delta = BarCount - j-1;


PFO = Ref( PFO, -delta );
PFC = Ref( PFC, -delta );

// High-Low range sets the height of the P&F bar
H = IIf(Ref(PFC,-1)>Ref(PFO,-1),Ref(HHV(PFC,1),-1)-1,Max(PFO,PFC))*Box;
L = IIf(Ref(PFC,-1)<Ref(PFO,-1),Ref(LLV(PFC,1),-1)+1,Min(PFO,PFC))*Box;
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 should be set to box size
// the sign decides if X or O are plotted
C = O + Box * IIf( PFC > PFO, 1,-1);

GraphXSpace = 2;
Title ="No Jscript  " + Name()+ "  PF HiLo, H: " + H+ ", L: " + L+", Box: "+
box + ", Reversal: " + reverse;

Plot( C, "P&F Chart Close", IIf( PFC > PFO, colorBlue, colorRed ),
styleCandle+styleNoLabel+stylePointAndFigure);

Comments:

Graham Kavanagh
gkavanagh [at] e-wire.net.au
2003-10-01 02:45:45
Comments should read Based on High and Low prices
Sorry, Graham
Graham Kavanagh
gkavanagh [at] e-wire.net.au
2003-10-02 05:38:47
Due to the price scale being linear the P&F charts will seem to have less boxes in a reversal than normally seen. A 3 box reversal will have 2 boxes showing in the new column. This is because of the linear scale, whereas P&F charts require a stepped scale where the whole value is one box value, not a sliding value between one price and another. eg box size of 10 cents should be 10 above the 9cent level, but linear scale has it going through 9.1, 9.2, 9.3,......9.9.
The first box in the reversal is taken with just moving it back down that scale to the next box value. I designed it this way so that the first visible reversal box is one value below the last box in the previous column as per normal convention on P&F charts.
noname
noname [at] noname.net
2003-10-02 17:08:30
GraphXSpace = 5;


Box = Param("Box", 0.05, 0.01, 1, 0.01);


Revers = Param("Revers", 3, 1, 5);


D = DateTime();


A = 0.00001;

// ????????? ???????
j = 0;

PFL = Null;
PFH = Null;
PFL[0] = Box * ceil(Low[0]/Box) + Box;
PFH[0] = Box * floor(High[0]/Box);
direction = 0;


for( i = 1; i < BarCount; i++ )
{
if(direction[j] == 0)
{
if(Low[i] <= PFL[j] - Box)
{
PFL[j] = Box * ceil(Low[i]/Box);
}
else
{
if(High[i] >= PFL[j] + Revers*Box -A)
{
j++;
direction[j] = 1;
PFH[j] = Box * floor(High[i]/Box);
PFL[j] = PFL[j - 1] + Box;
PFD[j] = D[i];
}
}
}
else
{
if(High[i] >= PFH[j] + Box)
{
PFH[j] = Box * floor(High[i]/Box);
}
else
{
if( Low[i] <= PFH[j] - Revers * Box + A)
{
j++;
direction[j] = 0;
PFH[j] = PFH[j - 1] - Box;
PFL[j] = Box * ceil(Low[i]/Box);
PFD[j] = D[i];
}
}
}
}



delta = BarCount - j -2;


LastClose = LastValue(Close);

direction = Ref(direction, - delta);

PFD = Ref(PFD, -delta);

Hi = Ref(PFH, -delta) + Box/2;
Lo = Ref(PFL, -delta) - Box/2;


Cl = IIf(direction == 1, Hi, Lo);
Op = IIf(direction == 1, Cl - Box, Cl + Box);


i = IIf(floor(BarIndex()/2)*2 == BarIndex(), 1, 0);


//EnableTextOutput(False);
PlotOHLC(Op, Hi, Lo, Cl,"P & F Chart (High/Low Range)",IIf(direction > 0, 27, 4), 8192);


Plot(Ref(LastClose, -BarCount+1), "Close", 1, 8 + 16);




Plot( i, "", 47, 512 + 65536 + 4096);

Hor = LastValue(frac(Lowest(Low)*10000/box))-box/2;
while (Hor < LastValue(Highest(Hi)))
{
EnableTextOutput(0);
Plot(Hor, "", 47, 1 + 2048 + 4096);
Hor = Hor + Box;
}



//=====================================

Title = Name() + " " +
EncodeColor(colorRed) + "X - O (High/Low Range)" + " " +
EncodeColor(colorBlue) + "Box" + " = " +
EncodeColor(colorBlack) + WriteVal(Box, format = 1.4) + " " +
EncodeColor(colorCustom12) + "Revers" + " = " +
EncodeColor(colorBlack) + WriteVal(Revers, format = 1.0);
Graham Kavanagh
gkavanagh [at] e-wire.net.au
2003-10-12 03:19:58
Thats good noname. You achieved the box reversal ok.
Graham Kavanagh
gkavanagh [at] e-wire.net.au
2003-10-12 04:25:15

Try this for plotting the vertical axis grids

barvisible = Status("barvisible");
firstvisiblebar = barvisible AND NOT Ref( barvisible, -1 );
period=BarsSince(firstvisiblebar==1);

ScreenHigh = HHV(Hi-box/2, period);
ScreenLow = LLV(Lo+box/2, period);

Hor = LastValue( ScreenLow );
while (Hor < LastValue(ScreenHigh) )
{
PlotGrid( LastValue( Hor ) );
Hor = Hor + Box;
}
Understand
Understand [at] Understand.com
2004-08-15 00:41:50
Is this AFL uptodate?

I don't understand the last two comments.

Should we be puting the last post's code into the main code?

And what is that code that "noname" posted? Should we be useing that?
Graham
gkavanagh [at] e-wire.net.au
2004-08-21 23:34:13
The first posted was my last update on P&F, noname provided an alternative code.
run_for_your_life2003
run_for_your_life2003 [at] yahoo.com
2004-08-22 10:35:20
Is to possible to be able to place a price scale on the left side and right side?
Also on the month and J for January in the column for around the first of the month thru December in the columns.
I've seen a lot of charts on Price and Figure.
Graham
gkavanagh [at] e-wire.net.au
2004-08-26 19:50:55
No
No, you can place markers in columns to show when months/quarters/years change during the column. Just takes some additional programming in the loops and plots. I have done it for myself, but suggest it a good exercise to learn AFL. I am not using the limited capabilities of P&F charts anymore as I have developed my own alternative, so if luckey someone else will pick up the mantle of P&F developer.

This is an indicator developed using the formula language, not as yet a built in chart.
run_for_your_life2003
run_for_your_life2003 [at] yahoo.com
2006-01-07 19:45:06
Thanks for your response on P&F Charts using Amibroker.

I think the old software like Omega Supercharts V3 (1990-1995)or Omega Tradestation Prosuite 2000i do a much better job with the graphics on P&F charting.

Excellent Book on PnF Charts by James Dines (1972)
Now a collector's Item.

http://www.amazon.com/gp/product/offer-listing/B0006VV47G/ref=dp_olp_2//103-7033400-4440631?condition=all
run_for_your_life2003
run_for_your_life2003 [at] yahoo.com
2006-01-07 20:09:52
Example:

Point n Figure Chart using Omega SuperCharts

SOHU January 6th,2006 (Two reverse H n S Patterns)
http://img455.imageshack.us/my.php?image=sohu0601063we.jpg
Graham
gkavanagh [at] e-wire.net.au
2006-01-08 20:47:16
RFYL2003, AB does not yet have built-in P&F charts like some of the other software, just what we have written in AFL, so there is no point comparing this with others.
If you want certain capabilities in AB just put a request in and if reasonable will be added to the to-do list, try that with the other programs
M Ramu
ramu.manjunath [at] vignani.com
2007-08-23 09:28:25
can you build this indicator for intraday chart please
Sveta
Ida [at] gimail.com
2007-11-19 18:36:13
9dd369b7 4444f009 b06
I like it and the background and colors make it easy to read
Wesley Bush
wesb3189rg [at] comcast.net
2008-07-08 14:50:23
the following code will take care of most of the Daily box size problems. Just cut and Paste. I'm not a programmer I just dabble a little.




//AFL P&F Chart for Amibroker Indicator window. //Based on High/low prices.
//Based on code in AB help files
//Reverse is 2 boxes.
//Graham Kavanagh 30 Sep 2003
// Modified by Wesley Bush

Version(4.40);


//Size for P&F boxes
PercentChange=Param("PercentChange",0.01,0.01,1,0.01);
BoxIncrement= C*PercentChange;
boxsize=SQRT(BoxIncrement);
Reverse =Param("Reverse",2,1,13,1); // reversal requirement

Box = LastValue(boxsize);
HX = round((H/box)*10)/10;
LX = round((L/box)*10)/10;
RH = floor(HX);
FL = ceil(LX);

Bar = BarIndex();
BarDate = DateNum();
BarTurn = 0;
BarEnd = 0;


// initialize first element
Mandeep Singh
man4urheart [at] gmail.com
2009-01-05 05:58:38
Plot( C, \\\"P&F Chart Close\\\", IIf( PFC > PFO, colorBlue, colorRed ),

This means it ia Code using Close and not High
and low!

This is completely incorrect AFL. Please correct same!
Mandeep SIngh
man4urheart [at] gmail.com
2009-01-05 06:00:38
I think your formula should use this

PlotOHLC(Op, Hi, Lo, Cl,\\\"\\\", ParamColor(\\\"ChartColor\\\",colorLightGrey), stylePointAndFigure|styleNoLabel);

Kinldy confirm!
Mandeep Singh
man4urheart [at] gmail.com
2009-01-05 06:02:53
Can somebody fix this issue in this code

\\\"Due to the price scale being linear the P&F charts will seem to have less boxes in a reversal than normally seen. A 3 box reversal will have 2 boxes showing in the new column.\\\"

I wonder Amibroker has not yet offcially published a good AFL code for Point and Figure chart, they are only busy in releasing versions but not improving basic charts!


About | Privacy | Terms of Use | Contact information
Copyright © 2001 AMIBROKER.COM