Numbering Bars

When you are developing systems and discussing charts with other traders by email, it is often convenient to be able to refer to the bars on your chart by number, date, or time. The code below can be appended to the end of your code to give you these options:

The b < Barcount check prevents out of range errors when you have AmiBroker Preferences set to give you a number of Blank bars at the right edge of your chart.

Plot(C,"",1,128); 
_SECTION_BEGIN("BAR LABELING"); 
ShowBars ParamToggle("Label Bars","NO|YES",0);
LabelCo ParamColor("Label",colorYellow);
Label ParamList("Bar Label","NUMBER|TIMENUM|DATENUM",0); 
GraphXSpace 10; 
if( Showbars ) 
{ 
DN=DateNum(); 
TN=TimeNum(); 
FirstVisibleBar Status"FirstVisibleBar" ); 
Lastvisiblebar Status("LastVisibleBar");  
for( FirstvisiblebarBN=0<= Lastvisiblebar AND BarCountb++) 
{ 
if( Label == "NUMBER" BarLabel NumToStr(BN++,1.0); 
else if ( Label == "TIMENUM" BarLabel NumToStr(TN[b],1.0); 
else BarLabelNumToStr(DN[b],1.0); 
PlotText("\n^\n"+BarLabel,b,L[b],LabelCo); 
} 
} 
_SECTION_END();

 

The labeled charts look like this:

Below a more streamlined version using the Switch():

_SECTION_BEGIN"BAR LABELING" );
PlotC""1128 );
ShowBars ParamToggle"Label Bars""NO|YES");
LabelCo ParamColor"Label"colorYellow );
Label ParamList"BarLabel""NUMBER|TimeNum|DateNum|BARNUM|WEEKDAYNUM|WEEKDAY");
GraphXSpace 10;

if ( Showbars )
{
    DN DateNum();
    TN TimeNum();
    WD DayOfWeek();
    WDList "SUN,MON,TUE,WED,THU,FRI,SAT";
    FirstVisibleBar Status"FirstVisibleBar" );
    Lastvisiblebar Status"LastVisibleBar" );

    for ( FirstvisiblebarBN 0<= Lastvisiblebar AND BarCountb++ )
    {
        switch ( Label )
        {
            case "NUMBER":
                BarLabel NumToStrBN++, 1.0 );
                break;
            case "TIMENUM":
                BarLabel NumToStrTN[b], 1.0 );
                break;
            case "BARNUM":
                BarLabel NumToStrb1.0 );
                break;
            case "WEEKDAYNUM":
                BarLabel NumToStrWD[b], 1.0 );
                break;
            case "WEEKDAY":
                BarLabel StrExtractWDListWD[b] );
                break;
            default:
                BarLabel NumToStrDN[b], 1.0 );
                break;
        }
        PlotText"\n^\n" BarLabelbL[b] - ( H[b] - L[b] ), LabelCo );
    }
}
_SECTION_END();

Edited by Al Venosa.

1 Star2 Stars3 Stars4 Stars5 Stars (3 votes, average: 4.33 out of 5)
Loading...Loading...

Comments are closed.