Horizontal Gridlines 5-point Interval

Is there a way to plot horizontal gridlines at every 5 point interval, i am aware of the plot grid function,
http://www.amibroker.com/guide/afl/plotgrid.html
but the above does not help if am moving across symbols with the huge price difference.

hi @Niftyalpha

The following code is from @Tomasz ( at yahoo email list 12-10-2007 )
Since then we have many new updates on Amibroker

// The following code is from yahoo email list 12-10-2007
// adjustable scale
// Turn off default grid, and then use PlotGrid function:
Plot( C, "", colorDefault, styleCandle );
gridINCR = Param( "incr", 0.0004, 1, 10, 0.0001 );

if( ParamToggle( "show custom grid", "NO|YES", 1 ) )
{
    SetChartOptions( 1, chartShowArrows | chartShowDates, 0 );
    firstbarvisible = BarIndex() == 1 OR( Status( "barvisible" ) AND NOT Ref( Status( "barvisible" ), -1 ) );
    GridMIN = LastValue( LowestSince( firstbarvisible, round( ( Low - 40 ) / 10 ) * 10 ) );
    GridMAX = LastValue( HighestSince( firstbarvisible, round( ( High + 40 ) / 10 ) * 10 ) );
    steps = ( GridMAX - GridMIN ) / gridINCR ;

    for( i = 0; i < steps; i++ )
        PlotGrid( GridMIN + i * gridINCR );
}
else
    SetChartOptions( 1, chartShowArrows | chartShowDates );
// Best regards,
// Tomasz Janeczko
// amibroker.com  

I just quickly wrote a code based on the above code. Just to give you an idea how can make it more automatic adjustable scale.
The logic of this code is based on tick size. You MUST define per-symbol tick size in the Symbol->Information window otherwise this afl will not respond.
This code may need some more improvement but I give it as an template.

// The logic of this code is based on tick size, and you MUST define per-symbol tick size in the Symbol->Information window.  
// a tamplate code of how to plot the grid every xxx pips,
// By Panos 5/6/19 
// this AFL works ONLY if you define tick size 

Plot( C, "", colorDefault, styleCandle );

// a nested IIF is looking for the TickSize value, so can be used in the switch statement
value = IIf( TickSize == 0.0001 , 1,
                IIf( TickSize == 0.001 , 2,
                     IIf( TickSize == 0.25 , 3,		/* SP500*/ 
                          IIf( TickSize == 1,  4, 1 ) ) ) );


if( ParamToggle( "show custom grid", "NO|YES", 1 ) )
{
    SetChartOptions( 1, chartShowArrows | chartShowDates, 0 );

    switch( value )
    {
        case 1:      // for Symbols with Tick size 0.0001
            gridINCR =  0.0010;
            GridMIN = LastValue( LowestVisibleValue( round( ( Low - 0.0010 ) / 0.0010 ) * 0.0010 ) ) ;
            GridMAX = LastValue( HighestVisibleValue( round( ( High + 0.0010 ) / 0.0010 ) * 0.0010 ) ) ;
            break;

        case 2:		// for Symbols with Tick size 0.001
            gridINCR =  0.020;
            GridMIN = LastValue( LowestVisibleValue( round( ( Low - 0.010 ) / 0.010 ) * 0.010 ) ) ;
            GridMAX = LastValue( HighestVisibleValue( round( ( High + 0.010 ) / 0.010 ) * 0.010 ) ) ;
            break;

        case 3:   // Sp500     // for Symbols with Tick size 0.25
            //gridINCR = Param( "incr", 10, 0.25, 50, 0.25 );  // with OR without parameters
            gridINCR =   TickSize * 10;		/* two and half of point Value */
            GridMIN = LastValue( LowestVisibleValue( round( ( Low - 20 ) / 10 ) * 10 ) ) ;
            GridMAX = LastValue( HighestVisibleValue( round( ( High + 20 ) / 10 ) * 10 ) ) ;
            break;

        case 4:			// for Symbols with Tick size = 1
            gridINCR =  10;
            GridMIN = LastValue( LowestVisibleValue( round( ( Low - 20 ) / 10 ) * 10 ) ) ;
            GridMAX = LastValue( HighestVisibleValue( round( ( High + 20 ) / 10 ) * 10 ) ) ;
            break;

        default:
            // default action
            gridINCR = 0;
            GridMIN = 0 ;
            GridMAX = 0;
            SetChartOptions( 1, chartShowArrows | chartShowDates );
            break;
    }

    steps = ( GridMAX - GridMIN ) / gridINCR ;
	
    for( i = 0; i < steps; i++ )
    { if (TickSize ==0 ) break;
        PlotGrid( GridMIN + i * gridINCR );
    }    

}

else 
  SetChartOptions( 1, chartShowArrows | chartShowDates );
2 Likes

i have a typo in the code and we need to replace line 12

IIf( TickSize == 1,  4, 1 ) ) ) );

replace  with 

IIf( TickSize == 1,  4, 0 ) ) ) );
2 Likes

Thank you very much !!!!

1 Like