{"id":1137,"date":"2007-09-23T16:10:34","date_gmt":"2007-09-23T16:10:34","guid":{"rendered":"http:\/\/www.amibroker.org\/userkb\/2007\/09\/23\/numbering-bars\/"},"modified":"2008-08-27T19:34:52","modified_gmt":"2008-08-27T19:34:52","slug":"numbering-bars","status":"publish","type":"post","link":"http:\/\/www.amibroker.org\/editable_userkb\/2007\/09\/23\/numbering-bars\/","title":{"rendered":"Numbering Bars"},"content":{"rendered":"

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: <\/p>\n

<\/p>\n

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. <\/p>\n

Plot<\/span>(<\/span>C<\/span>,<\/span>""<\/span>,<\/span>1<\/span>,<\/span>128<\/span>); \r<\/span>_SECTION_BEGIN<\/span>(<\/span>"BAR LABELING"<\/span>); \r<\/span>ShowBars <\/span>= <\/span>ParamToggle<\/span>(<\/span>"Label Bars"<\/span>,<\/span>"NO|YES"<\/span>,<\/span>0<\/span>);\r<\/span>LabelCo <\/span>= <\/span>ParamColor<\/span>(<\/span>"Label"<\/span>,<\/span>colorYellow<\/span>);\r<\/span>Label <\/span>= <\/span>ParamList<\/span>(<\/span>"Bar Label"<\/span>,<\/span>"NUMBER|TIMENUM|DATENUM"<\/span>,<\/span>0<\/span>); \r<\/span>GraphXSpace <\/span>= <\/span>10<\/span>; \rif( <\/span>Showbars <\/span>) \r{ \r<\/span>DN<\/span>=<\/span>DateNum<\/span>(); \r<\/span>TN<\/span>=<\/span>TimeNum<\/span>(); \r<\/span>FirstVisibleBar <\/span>= <\/span>Status<\/span>( <\/span>"FirstVisibleBar" <\/span>); \r<\/span>Lastvisiblebar <\/span>= <\/span>Status<\/span>(<\/span>"LastVisibleBar"<\/span>);  \rfor( <\/span>b <\/span>= <\/span>Firstvisiblebar<\/span>, <\/span>BN<\/span>=<\/span>0<\/span>; <\/span>b <\/span><= <\/span>Lastvisiblebar <\/span>AND <\/span>b <\/span>< <\/span>BarCount<\/span>; <\/span>b<\/span>++) \r{ \rif( <\/span>Label <\/span>== <\/span>"NUMBER" <\/span>) <\/span>BarLabel <\/span>= <\/span>NumToStr<\/span>(<\/span>BN<\/span>++,<\/span>1.0<\/span>); \relse if ( <\/span>Label <\/span>== <\/span>"TIMENUM" <\/span>) <\/span>BarLabel <\/span>= <\/span>NumToStr<\/span>(<\/span>TN<\/span>[<\/span>b<\/span>],<\/span>1.0<\/span>); \relse <\/span>BarLabel<\/span>= <\/span>NumToStr<\/span>(<\/span>DN<\/span>[<\/span>b<\/span>],<\/span>1.0<\/span>); \r<\/span>PlotText<\/span>(<\/span>"\\n^\\n"<\/span>+<\/span>BarLabel<\/span>,<\/span>b<\/span>,<\/span>L<\/span>[<\/span>b<\/span>],<\/span>LabelCo<\/span>); \r} \r} \r<\/span>_SECTION_END<\/span>();<\/span><\/pre>\n

<\/del>  <\/p>\n

The labeled charts look like this: <\/p>\n

<\/p>\n

Below a more streamlined version using the Switch():<\/p>\n

_SECTION_BEGIN<\/span>( <\/span>"BAR LABELING" <\/span>);\r<\/span>Plot<\/span>( <\/span>C<\/span>, <\/span>""<\/span>, <\/span>1<\/span>, <\/span>128 <\/span>);\r<\/span>ShowBars <\/span>= <\/span>ParamToggle<\/span>( <\/span>"Label Bars"<\/span>, <\/span>"NO|YES"<\/span>, <\/span>0 <\/span>);\r<\/span>LabelCo <\/span>= <\/span>ParamColor<\/span>( <\/span>"Label"<\/span>, <\/span>colorYellow <\/span>);\r<\/span>Label <\/span>= <\/span>ParamList<\/span>( <\/span>"BarLabel"<\/span>, <\/span>"NUMBER|TimeNum|DateNum|BARNUM|WEEKDAYNUM|WEEKDAY"<\/span>, <\/span>0 <\/span>);\r<\/span>GraphXSpace <\/span>= <\/span>10<\/span>;\r\rif ( <\/span>Showbars <\/span>)\r{\r    <\/span>DN <\/span>= <\/span>DateNum<\/span>();\r    <\/span>TN <\/span>= <\/span>TimeNum<\/span>();\r    <\/span>WD <\/span>= <\/span>DayOfWeek<\/span>();\r    <\/span>WDList <\/span>= <\/span>"SUN,MON,TUE,WED,THU,FRI,SAT"<\/span>;\r    <\/span>FirstVisibleBar <\/span>= <\/span>Status<\/span>( <\/span>"FirstVisibleBar" <\/span>);\r    <\/span>Lastvisiblebar <\/span>= <\/span>Status<\/span>( <\/span>"LastVisibleBar" <\/span>);\r\r    for ( <\/span>b <\/span>= <\/span>Firstvisiblebar<\/span>, <\/span>BN <\/span>= <\/span>0<\/span>; <\/span>b <\/span><= <\/span>Lastvisiblebar <\/span>AND <\/span>b <\/span>< <\/span>BarCount<\/span>; <\/span>b<\/span>++ )\r    {\r        switch ( <\/span>Label <\/span>)\r        {\r            case <\/span>"NUMBER"<\/span>:\r                <\/span>BarLabel <\/span>= <\/span>NumToStr<\/span>( <\/span>BN<\/span>++, <\/span>1.0 <\/span>);\r                break;\r            case <\/span>"TIMENUM"<\/span>:\r                <\/span>BarLabel <\/span>= <\/span>NumToStr<\/span>( <\/span>TN<\/span>[<\/span>b<\/span>], <\/span>1.0 <\/span>);\r                break;\r            case <\/span>"BARNUM"<\/span>:\r                <\/span>BarLabel <\/span>= <\/span>NumToStr<\/span>( <\/span>b<\/span>, <\/span>1.0 <\/span>);\r                break;\r            case <\/span>"WEEKDAYNUM"<\/span>:\r                <\/span>BarLabel <\/span>= <\/span>NumToStr<\/span>( <\/span>WD<\/span>[<\/span>b<\/span>], <\/span>1.0 <\/span>);\r                break;\r            case <\/span>"WEEKDAY"<\/span>:\r                <\/span>BarLabel <\/span>= <\/span>StrExtract<\/span>( <\/span>WDList<\/span>, <\/span>WD<\/span>[<\/span>b<\/span>] );\r                break;\r            default:\r                <\/span>BarLabel <\/span>= <\/span>NumToStr<\/span>( <\/span>DN<\/span>[<\/span>b<\/span>], <\/span>1.0 <\/span>);\r                break;\r        }\r        <\/span>PlotText<\/span>( <\/span>"\\n^\\n" <\/span>+ <\/span>BarLabel<\/span>, <\/span>b<\/span>, <\/span>L<\/span>[<\/span>b<\/span>] - ( <\/span>H<\/span>[<\/span>b<\/span>] - <\/span>L<\/span>[<\/span>b<\/span>] ), <\/span>LabelCo <\/span>);\r    }\r}\r<\/span>_SECTION_END<\/span>();<\/span><\/pre>\n

Edited by Al Venosa.<\/p>\n","protected":false},"excerpt":{"rendered":"

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 […]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[63],"tags":[],"_links":{"self":[{"href":"http:\/\/www.amibroker.org\/editable_userkb\/wp-json\/wp\/v2\/posts\/1137"}],"collection":[{"href":"http:\/\/www.amibroker.org\/editable_userkb\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.amibroker.org\/editable_userkb\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.amibroker.org\/editable_userkb\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/www.amibroker.org\/editable_userkb\/wp-json\/wp\/v2\/comments?post=1137"}],"version-history":[{"count":0,"href":"http:\/\/www.amibroker.org\/editable_userkb\/wp-json\/wp\/v2\/posts\/1137\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.amibroker.org\/editable_userkb\/wp-json\/wp\/v2\/media?parent=1137"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.amibroker.org\/editable_userkb\/wp-json\/wp\/v2\/categories?post=1137"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.amibroker.org\/editable_userkb\/wp-json\/wp\/v2\/tags?post=1137"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}