help with P&f chart

mrm

New Member
#1
With version 5.9 I'm getting error in P&f Chart.
Please help me to correct following formula
_SECTION_BEGIN("Point&Figure");
( "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 <= PFL[j] - Box )

{

PFL[j] = Box * ceil( Low / Box );

}

else

{

if ( High >= PFL[j] + Reverse*Box )

{

j++;

direction[j] = 1;

PFH[j] = Box * floor( High / Box );

PFL[j] = PFL[j - 1] + Box;

}

}

}

else

{

if ( High >= PFH[j] + Box )

{

PFH[j] = Box * floor( High / Box );

}

else

{

if ( Low <= PFH[j] - Reverse * Box )

{

j++;

direction[j] = 0;

PFH[j] = PFH[j - 1] - Box;

PFL[j] = Box * ceil( Low / Box );

}

}

}

}

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", colorRed ) );

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, "", colorRed, styleNoLine | styleDots, 0 , 0, shiftLastClose );

// selected value

Value = IIf( direction > 0, SelectedValue( Hi ) - box / 2, SelectedValue( Lo ) +
box / 2 );

//-----------------------------------------------------------------------

// GRID CONSTRUCTION

//----------------------------------------------------------------------

PlotGridLines = ParamToggle( "PlotdGrid", "Yes! |No", 1 ) ;

if ( PlotGridLines )

{

begin = SelectedValue( BarIndex() );

end = LastValue( BarIndex() );

period = end - begin + 1;

if ( begin < end )

{

ScreenHigh = LastValue( HHV( cl, period ) );

ScreenLow = LastValue( LLV( Cl, period ) );

top = LineArray( begin - shiftGrid, screenHigh, end, screenhigh, 0 , 1 );

Bot = LineArray( begin - shiftGrid, screenlow, end, screenLow, 0, 1 );

Plot( top, "", gridColor, styleLine | styleNoLabel , 0, 0, shiftGrid );

//Plot( bot, "", gridColor,styleLine|styleNoLabel, 0 , 0 , shiftGrid);

VerticalGrid = IIf ( BarIndex() >= begin, IIf( direction == 1, screenHigh,
screenLow ), Null );

Plot ( VerticalGrid, "", gridColor, styleStaircase | styleNoLabel, 0, 0, 1 );

format = 8.2;

for ( n = LastValue( bot ); n < LastValue( top ) - 0.5*box; n = n + box )

{

Plot( bot , "", gridColor, styleLine | styleNoLabel, 0, 0 , shiftGrid );

text = NumToStr( LastValue( bot ) + 0.5 * box, format );

xposition = BarCount + shiftPriceaxis;

yPosition = LastValue( bot ) + 0.27 * box;

PlotText( text, xPosition , yPosition, colorBlue );

bot = bot + box;

Graphcolor = IIf( direction == 1, ParamColor( "X_Color", colorBrightGreen ),

ParamColor( "O_Color", colorRed ) );

PlotOHLC( Op, Hi, Lo, Cl, "", GraphColor ,

stylePointAndFigure | styleNoLabel, 0, 0 , shiftChart );

}

}

}



//---------------------------------------------------------------------

// TITLE

//----------------------------------------------------------------------

Title = "\n" +

" Instrument : " + Name() + FullName() + "\n " +

"Formula : " + " Point & Figure (High/Low Range)" + "\n " +

"Box : " + NumToStr( Box, 4.4 ) + " " +

"Reverse : " + NumToStr( Reverse, 2.0 ) + "\n " +

"ATR : " + WriteVal( LastValue( ATR( 100 ) ), format = 4.4 );

_SECTION_END();

_SECTION_END();
Error is in "Reverse = Param( "Reverse", 3, 1, 5 );"
and I don't know how to correct this error
Could anyone be so kind and help me
Thank you
 
#4
Hi,

Using the above code for 1X1 ie box size 1 and reversal amount 1 single prints happens. Is it possible to change/modify the code where price starts in the same single print line as shown in the chart attached.

Its basically Wyckoff type of PNF chart. If anybody knows how to do it, it will be a big help for me.

Kindly help.

Regards,
S

 

KelvinHand

Well-Known Member
#5
Change to the latest version. old version cannot understand new version command.
PHP:
_SECTION_BEGIN("Point&Figure");

//--Modified by KelvinHand--------
// Changes:
// * Optimize the code, remove unused statements inside the looping.
// * Improve readability


GraphXSpace = 5;
SetChartBkColor( ParamColor( "BackGroundColor", colorBlack) );

X_Color = ParamColor( "X_Color", colorBrightGreen );
O_Color = ParamColor( "O_Color", colorRed);


PlotGridLines = ParamToggle( "PlotdGrid", "No|Yes", 1 ) ;
GridColor = ParamColor( "GridColor", colorGrey50 );
TextColor = ParamColor( "TextColor", colorBlue );  //--KH: Add Selectable Text Color instead of blue

Scaling = ParamList( "Scaling Method", "Traditional|Percentage|AVG True Range",2);
ATRPer = Param("ATR Period", 20, 1); //--KH: Add Changeable Period for ATR

//--KH: Previous Code, use 3 Param() of difference cases. 
// so the improvement as follow:
Box = Param( "Box", 1, 0.2, 10, 0.1 );

	if ( scaling == "Percentage" )
		Box = (Box /100) * LastValue( C );
	else
	if ( scaling == "AVG True Range" )
	{
             // - org. Box = Param( "Box", 1, 0.2, 5, 0.1 );
	    if (Box>5) Box=5; 
		Box = Box * LastValue( ATR ( ATRPer ));
	}

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


shiftChart = 0;
shiftLastClose = 1;
shiftGrid = 7;
shiftPriceAxis = 2;



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

direction[j] = 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 );
				}
			}
		}

	}

	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, X_Color, O_Color);
	PlotOHLC( Op, Hi, Lo, Cl, "", GraphColor,  stylePointAndFigure|styleNoLabel, 0, 0 , shiftChart );
	

	Last = Ref( LastValue( C ), -( BarCount - 1 ) );
	Plot( Last, "", colorRed, styleNoLine | styleDots, 0 , 0, shiftLastClose );


	//-----------------------------------------------------------------------
	// GRID CONSTRUCTION
	//----------------------------------------------------------------------
	if ( PlotGridLines )
	{
		begin = SelectedValue( BarIndex() );
		end = LastValue( BarIndex() );
		period = end - begin + 1;

		if ( begin < end )
		{
			ScreenHigh = LastValue( HHV( cl, period ) );
			ScreenLow = LastValue( LLV( Cl, period ) );
			top = LineArray( begin - shiftGrid, screenHigh, end, screenhigh, 0 , 1 );
			Bot = LineArray( begin - shiftGrid, screenlow, end, screenLow, 0, 1 );

			Plot( top, "", gridColor, styleLine | styleNoLabel , 0, 0, shiftGrid );
			//Plot( bot, "", gridColor,styleLine|styleNoLabel, 0 , 0 , shiftGrid);

			VerticalGrid = IIf ( BarIndex() >= begin, IIf( direction == 1, screenHigh, screenLow ), Null );
			Plot ( VerticalGrid, "", gridColor, styleStaircase | styleNoLabel, 0, 0, 1 );

			for ( n = LastValue( bot ); n < LastValue( top ) - 0.5*box; n+=box,  bot += box)
			{
				Plot( bot , "", gridColor, styleLine | styleNoLabel, 0, 0 , shiftGrid );
				
				text = NumToStr( LastValue( bot ) + 0.5 * box, 8.2 );
				xposition = BarCount + shiftPriceaxis;
				yPosition = LastValue( bot ) + 0.27 * box;
				PlotText( text, xPosition , yPosition, TextColor );
			}
		}
	}



//---------------------------------------------------------------------
// TITLE
//----------------------------------------------------------------------
Title = "\n Instrument : " + Name() + " - "+ FullName() + 
		"\n Formula : " + " Point & Figure (High/Low Range)" +
		"\n Box : " + NumToStr( Box, 4.4 ) + " " + "Reverse : " + NumToStr( Reverse, 2.0 ) + 
		"\n ATR : " + WriteVal( LastValue( ATR( 100 ) ), format = 4.4 );

_SECTION_END();
 
Last edited:

Similar threads