{"id":1122,"date":"2015-02-13T10:00:58","date_gmt":"2015-02-13T15:00:58","guid":{"rendered":"http:\/\/www.amibroker.com\/kb\/?p=1122"},"modified":"2015-02-13T10:06:21","modified_gmt":"2015-02-13T15:06:21","slug":"customizing-chart-titles","status":"publish","type":"post","link":"https:\/\/www.amibroker.com\/wordpress\/kb\/2015\/02\/13\/customizing-chart-titles\/","title":{"rendered":"Customizing chart titles"},"content":{"rendered":"
When we create custom indicators in AmiBroker, then by default the program will automatically create chart title line based on the selected ticker and the information we have provided in Plot<\/strong> function calls.<\/p> If we use the following formula: Then the auto-generated chart title line will contain:<\/p> <\/p> First item is the symbol name selected for that particular chart window (BA in this case), then the output is based on the plot names (provided in the 2nd argument of Plot function calls within the code) and colors will also match the respective plot colors. Number of decimal places depends on the settings in Tools->Preferences->Miscellaneous: Decimal places in chart titles\/tools<\/strong><\/p> If we do not want certain plot to affect the chart titles, we can use styleNoTitle<\/strong> chart style, for example changing the 3rd line of the above code into:<\/p> Would result in removing MA-50 values from the title output presented above, even though MA-50 values are still presented in the chart.<\/p> We can customize the chart title output even further by means of dedicated Title<\/strong> variable. If we define Title<\/strong> string within the formula, it will override the automatic title generation. Therefore, starting with most basic example, defining an empty string with use of:<\/p> would hide the title output completely, while using statement like this:<\/p> would generate default-color output such as the following (the price is formatted to use 2 decimal places by using NumToStr function in this case):<\/p> <\/p> It is also possible to define chart color by using EncodeColor<\/strong>() function, so changing the above line into:<\/p> would result in displaying the price value (and other text that follows the EncodeColor<\/strong> call) in red color<\/font>.<\/p> Now let us analyse the Title definition included in the built-in Price chart. <\/p> Among other elements shown above, the Title<\/strong> definition uses templates like {{NAME}} or {{VALUES}} etc. in the defined string. <\/p> These are special tokens that are replaced by appropriate values at run-time:<\/p> The built-in title definition uses also StrFormat<\/strong> function. This function allows us to specify the string followed by the list of arguments that will be inserted into the string in places, where %f, %g or %e specifications are entered. <\/p> <\/p> If we use the code like the one above, it would produce the following output:<\/p> <\/p> Those specifications allow us to format the output string accordingly.<\/p>Plot<\/span>( <\/span>Close<\/span>, <\/span>"Close"<\/span>, <\/span>colorDefault<\/span>, <\/span>styleBar <\/span>);
<\/span>Plot<\/span>( <\/span>MA<\/span>( <\/span>Close<\/span>, <\/span>20<\/span>), <\/span>"MA-20"<\/span>, <\/span>colorRed <\/span>);
<\/span>Plot<\/span>( <\/span>MA<\/span>( <\/span>Close<\/span>, <\/span>50<\/span>), <\/span>"MA-50"<\/span>, <\/span>colorBlue <\/span>)<\/code>Plot<\/span>( <\/span>MA<\/span>( <\/span>Close<\/span>, <\/span>50<\/span>), <\/span>"MA-50"<\/span>, <\/span>colorBlue<\/span>, <\/span>styleNoTitle <\/span>)<\/code>
Title <\/span>= <\/span>""<\/span><\/code>
Title <\/span>= <\/span>"Close Price: " <\/span>+<\/span>NumToStr<\/span>( <\/span>Close<\/span>, <\/span>1.2 <\/span>)<\/code>
Title <\/span>= <\/span>"Close Price: " <\/span>+<\/span>EncodeColor<\/span>( <\/span>colorRed <\/span>) + <\/span>NumToStr<\/span>( <\/span>Close<\/span>, <\/span>1.2 <\/span>)<\/code>
_N<\/span>(<\/span>Title <\/span>= <\/span>StrFormat<\/span>(<\/span>"{{NAME}} - " <\/span>+<\/span>FullName<\/span>() +
<\/span>" - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) Vol " <\/span>+
<\/span>WriteVal<\/span>( <\/span>V<\/span>, <\/span>1.0 <\/span>) +<\/span>" {{VALUES}}"<\/span>, <\/span>O<\/span>, <\/span>H<\/span>, <\/span>L<\/span>, <\/span>C<\/span>, <\/span>SelectedValue<\/span>( <\/span>ROC<\/span>( <\/span>C<\/span>, <\/span>1 <\/span>)) ))<\/code>