GfxPolygon: number of arguments must be even

Although the no. of arguments are paired co-ordinates, unable to find the cause of the error.

Was trying to plot a tilted triangle (pointer) around the close using GfxPolygon which would glide automatically as price moves, but, got the error. Works fine when pxY is assigned as a param and slided manually.

SetChartBkColor( colorAqua );
Miny = Status("axisminy");
Maxy = Status("axismaxy"); 
pxchartbottom = Status("pxchartbottom"); 
pxchartheight = Status("pxchartheight"); 
value = LastValue( C );
//pxY = Param( "pxY", 0, 0, 2500, 1 );
pxY = pxchartbottom - floor( 0.5 + ( Value - Miny ) * pxchartheight/ ( Maxy - Miny ) ); //Y co-ordinate to pixel

GfxSetOverlayMode( 0 );
GfxSelectPen( colorBlack );
GfxSelectSolidBrush( colorBlue );
//Shape of a tilted triangle. No error if pxY is assigned as a param and slided manually.
GfxPolygon( 1500, pxY, 1500+20, pxY-20, 1500+20, pxY+20 );

Plot( C, "C", colorBlack, styleCandle|styleOwnScale );

Interestingly, same code finds no error when a GfxRectangle is used.

SetChartBkColor( colorAqua );
Miny = Status("axisminy");
Maxy = Status("axismaxy"); 
pxchartbottom = Status("pxchartbottom"); 
pxchartheight = Status("pxchartheight"); 
value = LastValue( C );
//pxY = Param( "pxY", 0, 0, 2500, 1 );
pxY = pxchartbottom - floor( 0.5 + ( Value - Miny ) * pxchartheight/ ( Maxy - Miny ) ); //Y co-ordinate to pixel

GfxSetOverlayMode( 0 );
GfxSelectPen( colorBlack );
GfxSelectSolidBrush( colorBlue );
//No error!
GfxRectangle( 1500, pxY-5, 1500+35, pxY+5 );

Plot( C, "C", colorBlack, styleCandle|styleOwnScale|styleNoLabel );

Also, no error when GfxMoveTo, GfxLineTo is used. Is there a way to fill the inner fence with color?

SetChartBkColor( colorAqua );
Miny = Status("axisminy");
Maxy = Status("axismaxy");
pxchartbottom = Status("pxchartbottom");
pxchartheight = Status("pxchartheight");
value = LastValue( C );
//pxY = Param( "pxY", 0, 0, 2500, 1 );
pxY = pxchartbottom - floor( 0.5 + ( Value - Miny ) * pxchartheight/ ( Maxy - Miny ) ); //Y co-ordinate to pixel

GfxSetOverlayMode( 0 );
GfxSelectPen( colorBlack, 2 );
//No error!
//Is there a way to color fill the inner fence?
GfxMoveTo( 1500, pxY );
GfxLineTo( 1500+20, pxY-20 );
GfxMoveTo( 1500+20, pxY-20 );
GfxLineTo( 1500+20, pxY+20 );
GfxMoveTo( 1500+20, pxY+20 );
GfxLineTo( 1500, pxY );

Plot( C, "C", colorBlack, styleCandle|styleOwnScale|styleNoLabel );

Thanks for your time!

You are having problems because you ignored “division by zero” warning that was generated in line that calculates pxY. GfxPolygon checks the number of NON-Null arguments. If argument is Null or Not-A-Number it is treated as empty (non existing) hence you are getting an error.
Your pxY calculation may produce not-a-number thru division by zero:

 //Y co-ordinate to pixel  - this produces division by zero when code is run NOT 
// inside chart. AFL editor is not a chart
pxY = pxchartbottom - floor( 0.5 + ( Value - Miny ) * pxchartheight/ ( Maxy - Miny ) );

//  because line above produces not-a-number you must add this
pxY = Nz( pxY ); // convert non-numbers to zero

1 Like