Apologies I mentioned the wrong for-loop wanted to bring @SpinTrader 's code:

How to factor the auto-scale or scrolling of Plot() in GfxSetOverlayMode( 2 )?

Here is the one:

```
pxchartwidth = Status( "pxchartwidth" );
pxchartheight = Status( "pxchartheight" );
lvb = Status( "lastvisiblebar" );
fvb = Status( "firstvisiblebar" );
pxchartleft = Status( "pxchartleft" );
pxchartbottom = Status( "pxchartbottom" );
Miny = Status( "axisminy" );
Maxy = Status( "axismaxy" );
function GfxConvertBarToPixelX( bar )
{
local bardiff, barnum, relbar, px;
// based on http://www.amibroker.com/kb/2009/03/30/how-to-convert-from-bar-value-to-pixel-co-ordinates/
barnum = lvb - fvb + 1;
bardiff = bar - fvb;
relbar = bardiff / barnum;
px = relbar * pxchartwidth + pxchartleft;
return Nz( px );
}
function GfxConvertValueToPixelY( Value, logscale )
{
local logMiny, logMinMax, pxy;
//based on http://www.amibroker.com/kb/2009/03/30/how-to-convert-from-bar-value-to-pixel-co-ordinates/
if( logscale )
{
logMiny = log( Miny );
logMinMax = log( Maxy ) - logMiny;
pxy = pxchartbottom - floor( 0.5 + ( log( Value ) - logMiny ) * pxchartheight / logMinMax );
}
else
{
pxy = pxchartbottom - floor( 0.5 + ( Value - Miny ) * pxchartheight / ( Maxy - Miny + 1e-9 ) );
}
return Nz( pxy );
}
_log = ParamToggle( "Log Scale", "Off|On", 1 );
SetChartOptions( IIf( _log, 2, 3 ), chartLogarithmic );
//dispCoodC = ParamToggle( "Show Coord. Candles", "No|Yes", 0 );
//Plot( C, "", ParamColor( "C Dot Co-Ordinates color", colorDefault ), styleNoLine | styleNoLabel | IIf( dispCoodC, styleCandle, styleNoDraw ), Null, Null, 0, 4, 2 );
//NumBars = BarCount - fvb;
//pxPerBar = GfxConvertBarToPixelX( NumBars ) / NumBars;
GfxSetOverlayMode( 2 );
/*
for( i = fvb; i <= BarCount - 1; i++ )
{
OpPixelY = GfxConvertValueToPixelY( O[ i ], _log );
HiPixelY = GfxConvertValueToPixelY( H[ i ], _log );
LoPixelY = GfxConvertValueToPixelY( L[ i ], _log );
ClPixelY = GfxConvertValueToPixelY( C[ i ], _log );
PixelX = GfxConvertBarToPixelX( i );
if( C[ i ] >= O[ i ] )
{
BarColor = ColorRGB( 1, 254, 1 );
}
else if( C[ i ] < O[ i ] )
{
BarColor = ColorRGB( 255, 0, 0 );
}
GfxSelectPen( BarColor, 2 );
GfxMoveTo( PixelX, HiPixelY );
GfxLineTo( PixelX, LoPixelY );
}
*/
bi = BarIndex();
FVB = FirstVisibleValue( bi );
LVB = LastVisibleValue( bi );
ScreenResolution = (pxchartwidth+10^-20); // Small fix to prevent divide by zero
PixIncr = LastValue( BI)/Screenresolution;
for( i = FVB + 1; i <= LVB AND i < BarCount-PixIncr; i=i+PixIncr )
{
OpPixelY = GfxConvertValueToPixelY( O[ i ], _log );
HiPixelY = GfxConvertValueToPixelY( H[ i ], _log );
LoPixelY = GfxConvertValueToPixelY( L[ i ], _log );
ClPixelY = GfxConvertValueToPixelY( C[ i ], _log );
PixelX = GfxConvertBarToPixelX( i );
if( C[ i ] >= O[ i ] )
{
BarColor = ColorRGB( 1, 254, 1 );
}
else if( C[ i ] < O[ i ] )
{
BarColor = ColorRGB( 255, 0, 0 );
}
GfxSelectPen( BarColor, 2 );
GfxMoveTo( PixelX, HiPixelY );
GfxLineTo( PixelX, LoPixelY );
}
GfxSelectPen( colorWhite, 2 );
GfxMoveTo( 0, GfxConvertValueToPixelY( Maxy, _log ) );
GfxLineTo( pxchartwidth, GfxConvertValueToPixelY( Maxy, _log ) );
GfxMoveTo( 0, GfxConvertValueToPixelY( Miny, _log ) );
GfxLineTo( pxchartwidth, GfxConvertValueToPixelY( Miny, _log ) );
GfxMoveTo( pxchartwidth, GfxConvertValueToPixelY( Maxy, _log ) );
GfxLineTo( pxchartwidth, GfxConvertValueToPixelY( Miny, _log ) );
RequestTimedRefresh( 1 );
```