_SECTION_BEGIN("PNF box2");
// formula written by Jeevan Lal
_SECTION_BEGIN
("P&F Daily");
//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
Version
(4.40);
SetBarsRequired
(100000, 100000);
//Size for P&F boxes
Bx = Param("box size",2,1,20,1);
boxsize=bx;//IIf(C>=0.01 AND C<29, 0.10,IIf(C>29 AND C<60, 0.15,IIf(C>60 AND C<140, 0.20,IIf(C>140 AND C<290, 0.50,IIf(C>290 AND C<600, 1.00,IIf(C>600 AND C<1400, 2.00,IIf(C>1400 AND C<2900, 3.00,IIf(C>2900 AND C<6000, 5.00,5.00))))))));
Box =
LastValue(boxsize);
HX =
round((H/box)*10)/10;
LX =
round((L/box)*10)/10;
RH =
floor(HX);
FL =
ceil(LX);
Plot(H,"high",colorWhite,styleNoLine);
Plot(L,"Low",colorWhite,styleNoLine);
// initialize first element
j =
0;
Reverse =
2; // 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;
Plot
( C, "Box", IIf( PFC > PFO, colorCustom9, colorRed ), styleCandle+styleNoLabel+stylePointAndFigure);
_SECTION_END
();
_SECTION_BEGIN
( "Point & Figure w Values adj" );
GraphXSpace
= 5;
SetChartBkColor
( ParamColor( "BackGroundColor", colorBlack) );
//GraphColor = ParamColor("GarphColor", colorLightGrey);
GridColor =
ParamColor( "GridColor", colorLightGrey );
Scaling =
ParamList( "Scaling Method", "Traditional|Percentage|AVG True
Range
" );
if
( scaling == "Traditional" )
Box =
Param( "Box", 1, 0.2, 10, 0.1 );
else
if ( scaling == "Percentage" )
Box =
Param( "Box ", 1, 0.2, 10, 0.1 ) / 100 * LastValue( C );
else
if ( scaling == "AVG True Range" )
Box =
Param( "Box", 1, 0.3, 5, 0.1 ) * LastValue( ATR ( 20 ) );
shiftChart =
0;
shiftLastClose =
1;
shiftGrid =
7;
shiftPriceAxis =
2;
Reverse =
Param( "Reverse", 3, 1, 5 );
j =
0;
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] + Reverse*Box )
{
j++;
direction[j] =
1;
PFH[j] = Box *
floor( High[i] / Box );
PFL[j] = PFL[j -
1] + Box;
}
}
}
else
{
if ( High[i] >= PFH[j] + Box )
{
PFH[j] = Box *
floor( High[i] / Box );
}
else
{
if ( Low[i] <= PFH[j] - Reverse * Box )
{
j++;
direction[j] =
0;
PFH[j] = PFH[j -
1] - Box;
PFL[j] = Box *
ceil( Low[i] / Box );
}
}
}
}
// end for loop
delta = BarCount - j -
1;
direction =
Ref( direction, - 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 );
Graphcolor =
IIf( direction == 1, ParamColor( "X_Color", colorBrightGreen ),
ParamColor
( "O_Color", colorDarkRed ) );
PlotOHLC
( Op, Hi, Lo, Cl, "", GraphColor, stylePointAndFigure | styleNoLabel, 0, 0, shiftChart );
PlotOHLC
( Op, Hi, Lo, Cl, "", GraphColor, stylePointAndFigure | styleNoLabel, 0, 0, shiftChart );
Last =
Ref( LastValue( C ), -( BarCount - 1 ) );
Plot
( Last, "", colorDarkRed, styleNoLine | styleDots, 0, 0, shiftLastClose );
// selected value
Value =
IIf( direction > 0, SelectedValue( Hi ) - box / 2, SelectedValue( Lo ) + box / 2 );
_SECTION_END();