Below an example of how I would plot a single price array in gfx. The problem is that it executes ~1000 slower than the build in Plot(). This is expected of course - hence this post.
-
Putting all other considerations aside, my question is whether there is a way to size the build-in plot() function, remove the Y-Axis, and overlay this on a gfx layout. A simple yes or no will suffice. I don’t know everything and, imo, asking a dumb question is better than asking none.
-
Am I doing something terribly wrong in the code below that results in the 1000x slower execution. If so please give me a hint.
I think it would be great if we could somehow use the Plot() function to plot on a full-window gfx layout.
Best regards,
Herman
function gfxPlotVLine( XPixels, Color )
{
global pxheight;
GfxSelectPen( Color ) ;
GfxMoveTo( XPixels, 0 );
GfxLineTo( XPixels, pxheight );
}
function GetVisualBarIndex( )
{
lvb = Status( "lastvisiblebar" );
fvb = Status( "firstvisiblebar" );
bi = BarIndex();
StaticVarSet( "NumberbarsVisible", Lvb - fvb + 1 );
return bi - bi[ 0 ] - fvb;
}
function GetYPixels( Y )
{
global PixelsPerPrice, pxTopArea, MaxY;
return ( MaxY - Y ) * PixelsPerPrice;
}
function GetXPixels( X )
{
global PixelsPerBar, pxLeftArea;
return X * PixelsPerBar;
}
BeginExecutionTime = GetPerformanceCounter( False );
FilePathName = GetFormulaPath();
SetChartOptions( 0, chartHideQuoteMarker );
RequestTimedRefresh( 1 );
pxwidth = Status( "pxwidth" );
pxheight = Status( "pxheight" );
SetChartOptions( 3, chartShowDates );
PxL = Status( "pxchartright" ); // Cover origional chart frame vertical line
gfxPlotVLine( PxL, colorblack );
Plot( C, "", colorgreen, styleNoLabel | stylenoline ); // needed to give the min and max values
Miny = Status( "axisminy" );
Maxy = Status( "axismaxy" );
YRange = MaxY - MinY;
VisBarIndex = GetVisualBarIndex( );
NumBarsVisible = StaticVarGet( "NumberbarsVisible" );
// calculate conversion factors
PixelsPerBar = pxwidth / NumBarsVisible;
PixelsPerPrice = pxHeight / ( YRange + 10 ^ -20 );
// Plot pixel plot
GfxSelectPen( colorYellow );
FVB = Status( "firstvisiblebar" );
LVB = Status( "lastvisiblebar" );
for( b = FVB + 1; b <= LVB AND b < BarCount; b++ )
{
PrevPixelY = GetYPixels( C[b - 1] );
PixelY = GetYPixels( C[b] );
PrevPixelX = GetXPixels( VisBarIndex[b - 1] );
PixelX = GetXPixels( VisBarIndex[b] );
GfxMoveTo( PrevPixelX, PrevPixelY );
GfxLineTo( PixelX, PixelY );
}
EndExecutionTime = GetPerformanceCounter( False );
ExecutionTime = EndExecutionTime - BeginExecutionTime;
StaticvarSet( "ExecutionTime", ExecutionTime );
Title =
"FormulaName: " + FilePathName + "\n" +
" Exec. Time: " + StaticVarGet( "ExecutionTime" ) + " msec";