{"id":1330,"date":"2015-08-29T16:35:35","date_gmt":"2015-08-29T15:35:35","guid":{"rendered":"http:\/\/www.amibroker.com\/kb\/?p=1330"},"modified":"2016-01-29T16:40:50","modified_gmt":"2016-01-29T15:40:50","slug":"how-to-add-symbol-labels-to-relative-performance-chart","status":"publish","type":"post","link":"https:\/\/www.amibroker.com\/wordpress\/kb\/2015\/08\/29\/how-to-add-symbol-labels-to-relative-performance-chart\/","title":{"rendered":"How to add symbol labels to Relative Performance chart"},"content":{"rendered":"

The built-in Relative Performance chart displays symbol names colored respectively in the chart Title. However – it may be practical to display the symbol label next to the plotted line for easier identification. This can easily be done with PlotText<\/a> or PlotTextSetFont<\/a> function. <\/p>

A sample code showing such modification is presented below. Font size of the labels can be changed through Parameters dialog.<\/p>_N<\/span>( <\/span>TickerList <\/span>= <\/span>ParamStr<\/span>( <\/span>"Tickers"<\/span>, <\/span>"^DJI,MSFT,GE" <\/span>) );
<\/span>fontsize <\/span>= <\/span>Param<\/span>(<\/span>"Label font size"<\/span>, <\/span>10<\/span>, <\/span>4<\/span>, <\/span>30<\/span>, <\/span>1 <\/span>);
<\/span>fvb <\/span>= <\/span>Status<\/span>( <\/span>"firstvisiblebar" <\/span>);

for( <\/span>i <\/span>= <\/span>0<\/span>; ( <\/span>symbol <\/span>= <\/span>StrExtract<\/span>( <\/span>Name<\/span>() + <\/span>"," <\/span>+ <\/span>TickerList<\/span>, <\/span>i <\/span>) ) != <\/span>""<\/span>; <\/span>i<\/span>++ )
{
    <\/span>fc <\/span>= <\/span>Foreign<\/span>( <\/span>symbol<\/span>, <\/span>"C" <\/span>);

    if( ! <\/span>IsNull<\/span>( <\/span>fc<\/span>[ <\/span>0 <\/span>] ) )
    {
        <\/span>relP <\/span>= <\/span>100 <\/span>* ( <\/span>fc <\/span>- <\/span>fc<\/span>[ <\/span>fvb <\/span>] ) \/ <\/span>fc<\/span>[ <\/span>fvb <\/span>];
        <\/span>Plot<\/span>( <\/span>relP <\/span>, <\/span>symbol<\/span>, <\/span>color <\/span>= <\/span>colorLightOrange <\/span>+ ( ( <\/span>2 <\/span>* <\/span>i <\/span>) % <\/span>15 <\/span>), <\/span>styleLine <\/span>);

        <\/span>x <\/span>= <\/span>LastValue<\/span>( <\/span>BarIndex<\/span>() ) + <\/span>1<\/span>;
        <\/span>y <\/span>= <\/span>LastValue<\/span>( <\/span>relP <\/span>);

        <\/span>PlotTextSetFont<\/span>( <\/span>symbol<\/span>, <\/span>"Arial"<\/span>, <\/span>fontsize<\/span>, <\/span>x<\/span>, <\/span>y<\/span>, <\/span>GetChartBkColor<\/span>(), <\/span>color<\/span>, -<\/span>fontsize<\/span>\/<\/span>2 <\/span>);
    }
}

<\/span>PlotGrid<\/span>( <\/span>0<\/span>, <\/span>colorYellow <\/span>);
<\/span>_N<\/span>( <\/span>Title <\/span>= <\/span>"{{NAME}} - Relative Performance [%]: {{VALUES}}" <\/span>)<\/code>

\"Relative<\/p>","protected":false},"excerpt":{"rendered":"

The built-in Relative Performance chart displays symbol names colored respectively in the chart Title. However – it may be practical to display the symbol label next to the plotted line for easier identification. This can easily be done with PlotText or PlotTextSetFont function. A sample code showing such modification is presented below. Font size of […]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[10],"tags":[53,55,98],"_links":{"self":[{"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/posts\/1330"}],"collection":[{"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/comments?post=1330"}],"version-history":[{"count":1,"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/posts\/1330\/revisions"}],"predecessor-version":[{"id":1332,"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/posts\/1330\/revisions\/1332"}],"wp:attachment":[{"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/media?parent=1330"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/categories?post=1330"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/tags?post=1330"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}