{"id":1161,"date":"2015-09-30T10:23:49","date_gmt":"2015-09-30T15:23:49","guid":{"rendered":"http:\/\/www.amibroker.com\/kb\/?p=1161"},"modified":"2015-09-30T10:47:45","modified_gmt":"2015-09-30T15:47:45","slug":"positioning-area-plots-behind-the-grid-lines","status":"publish","type":"post","link":"https:\/\/www.amibroker.com\/wordpress\/kb\/2015\/09\/30\/positioning-area-plots-behind-the-grid-lines\/","title":{"rendered":"Positioning area plots behind the grid lines"},"content":{"rendered":"

When we want to paint the background with custom colors to indicate certain states or conditions – we can use area plots style for this purpose. The code example presented below shows green background when Close stays above 50-period moving average and red when below MA-50. <\/p>Plot<\/span>( <\/span>Close<\/span>, <\/span>"Close"<\/span>, <\/span>colorDefault<\/span>, <\/span>styleThick<\/span>);
<\/span>Plot<\/span>( <\/span>MA50 <\/span>= <\/span>MA<\/span>(<\/span>Close<\/span>,<\/span>50<\/span>), <\/span>"MA50"<\/span>, <\/span>colorBlue<\/span>, <\/span>styleThick<\/span>);

<\/span>color <\/span>= <\/span>IIf<\/span>( <\/span>Close <\/span>> <\/span>MA50<\/span>, <\/span>colorGreen<\/span>, <\/span>colorRed <\/span>);
<\/span>Plot<\/span>( <\/span>1<\/span>, <\/span>""<\/span>, <\/span>color<\/span>, <\/span>styleArea<\/span>|<\/span>styleOwnScale<\/span>,<\/span>0<\/span>,<\/span>1 <\/span>)<\/code>

However – by default both grid lines and the selector line would get covered by the area plot:<\/p>

\"area<\/p>

There is an easy fix for that – AmiBroker allows to specify the Z-axis position too, so we can shift the visibility and order of plots (including their position against grids and other elements) by means of Z-order argument of Plot function.<\/p>

If we specify the Z-order argument to -1 that means we move the particular plot one level behind and this would also be located below the grids.<\/p>Plot<\/span>( <\/span>Close<\/span>, <\/span>"Close"<\/span>, <\/span>colorDefault<\/span>, <\/span>styleThick<\/span>);
<\/span>Plot<\/span>( <\/span>MA50 <\/span>= <\/span>MA<\/span>(<\/span>Close<\/span>,<\/span>50<\/span>), <\/span>"MA50"<\/span>, <\/span>colorBlue<\/span>, <\/span>styleThick<\/span>);

<\/span>color <\/span>= <\/span>IIf<\/span>( <\/span>Close <\/span>> <\/span>MA50<\/span>, <\/span>colorGreen<\/span>, <\/span>colorRed <\/span>);
<\/span>Plot<\/span>( <\/span>1<\/span>, <\/span>""<\/span>, <\/span>color<\/span>, <\/span>styleArea<\/span>|<\/span>styleOwnScale<\/span>,<\/span>0<\/span>,<\/span>1<\/span>,<\/span>0<\/span>,-<\/span>1 <\/span>); <\/span>\/\/ the 8th argument specifies z-orde<\/code>

\"fixed<\/p>

More information about use of Z-order can be found in the User’s Guide:
http:\/\/www.amibroker.com\/guide\/h_indbuilder2.html<\/a><\/p>","protected":false},"excerpt":{"rendered":"

When we want to paint the background with custom colors to indicate certain states or conditions – we can use area plots style for this purpose. The code example presented below shows green background when Close stays above 50-period moving average and red when below MA-50. Plot( Close, "Close", colorDefault, styleThick);Plot( MA50 = MA(Close,50), "MA50", colorBlue, styleThick);color = IIf( Close > MA50, colorGreen, colorRed );Plot( 1, "", color, styleArea|styleOwnScale,0,1 )However – by default both grid lines and the […]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[3],"tags":[53,55,58],"_links":{"self":[{"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/posts\/1161"}],"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=1161"}],"version-history":[{"count":2,"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/posts\/1161\/revisions"}],"predecessor-version":[{"id":1176,"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/posts\/1161\/revisions\/1176"}],"wp:attachment":[{"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/media?parent=1161"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/categories?post=1161"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/tags?post=1161"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}