{"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> However – by default both grid lines and the selector line would get covered by the area plot:<\/p> <\/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> <\/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>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>