By default, the Plot function draws the graph for all visible bars. In some situations however, we may want to draw some selected bars, leaving remaining chart space unaffected.<\/p>
To achieve that – we simply assign Null<\/strong> value for the bars that we want to skip. Our graph will just be drawn for the non-null bars. <\/p>
This simple example draws candlesticks only on Mondays and leaves empty all the other days.<\/p>IsMonday <\/span>= <\/span>DayOfWeek<\/span>() == <\/span>1<\/span>;
<\/span>\/\/ assign Close for Mondays, otherwise assign Null
<\/span>Data <\/span>= <\/span>IIf<\/span>( <\/span>IsMonday<\/span>, <\/span>Close<\/span>, <\/span>Null <\/span>);
<\/span>\/\/ plot the data
<\/span>Plot<\/span>( <\/span>Data<\/span>, <\/span>"Chart of Mondays"<\/span>, <\/span>colorDefault<\/span>, <\/span>styleCandle <\/span>)<\/code>
The following example shows how to restrict the visibility to last N bars. The code defines a custom function, which can be called later on for the arrays we want to show only partially.<\/p>
<\/span>\/\/ custom function definition
<\/span>function <\/span>LastNBars<\/span>( array, <\/span>bars <\/span>)
{
<\/span>bi <\/span>= <\/span>BarIndex<\/span>();
<\/span>lvbi <\/span>= <\/span>LastValue<\/span>( <\/span>bi <\/span>);
<\/span>\/\/ use Null value for bars other than last N
<\/span>return <\/span>IIf<\/span>( <\/span>bi <\/span>> <\/span>lvbi <\/span>- <\/span>bars<\/span>, array, <\/span>Null <\/span>);
}
<\/span>\/\/ price plot
<\/span>Plot<\/span>( <\/span>Close<\/span>, <\/span>"Close"<\/span>, <\/span>colorDefault<\/span>, <\/span>styleBar <\/span>);
<\/span>\/\/ MA-50 restricted to last 10-bars only
<\/span>line <\/span>= <\/span>MA<\/span>( <\/span>Close<\/span>, <\/span>50 <\/span>);
<\/span>Plot<\/span>( <\/span>LastNBars<\/span>( <\/span>line<\/span>, <\/span>10 <\/span>), <\/span>"last 10 bars"<\/span>, <\/span>colorRed <\/span>);
<\/span>\/\/ shaded area
<\/span>Plot<\/span>( <\/span>LastNbars<\/span>( <\/span>True<\/span>, <\/span>10 <\/span>), <\/span>""<\/span>, <\/span>colorYellow<\/span>, <\/span>styleArea<\/span>|<\/span>styleOwnScale<\/span>|<\/span>styleNoLabel<\/span>, <\/span>0<\/span>, <\/span>1<\/span>, <\/span>0<\/span>, -<\/span>1 <\/span>)<\/code>
<\/p>
In the above chart both Moving average (red line) and yellow shading area have been restricted to last 10-bars only.<\/p>
In a similar way we can restrict the visibility to most recent day only in intraday chart:<\/p>
<\/span>\/\/ custom function definition
<\/span>function <\/span>ShowLastDay<\/span>( array )
{
<\/span>dn <\/span>= <\/span>datenum<\/span>();
<\/span>lastDay <\/span>= <\/span>dn <\/span>== <\/span>LastValue<\/span>( <\/span>dn <\/span>);
return <\/span>IIf<\/span>( <\/span>lastDay<\/span>, array, <\/span>Null <\/span>);
}
<\/span>\/\/ price plot
<\/span>Plot<\/span>( <\/span>Close<\/span>, <\/span>"Close"<\/span>, <\/span>colorDefault<\/span>, <\/span>styleBar <\/span>);
<\/span>\/\/ daily high \/ low on last day only
<\/span>dailyH <\/span>= <\/span>TimeFrameGetPrice<\/span>(<\/span>"H"<\/span>, <\/span>inDaily <\/span>);
<\/span>dailyL <\/span>= <\/span>TimeFrameGetPrice<\/span>(<\/span>"L"<\/span>, <\/span>inDaily <\/span>);
<\/span>Plot<\/span>( <\/span>ShowLastDay<\/span>( <\/span>dailyH <\/span>), <\/span>"dailyH"<\/span>, <\/span>colorGreen<\/span>, <\/span>styleThick <\/span>);
<\/span>Plot<\/span>( <\/span>ShowLastDay<\/span>( <\/span>dailyL <\/span>), <\/span>"dailyL"<\/span>, <\/span>colorRed<\/span>, <\/span>styleThick <\/span>);
<\/span>\/\/ shaded area
<\/span>colorPaleYellow <\/span>= <\/span>ColorBlend<\/span>(<\/span>colorWhite<\/span>, <\/span>colorYellow<\/span>, <\/span>0.1<\/span>);
<\/span>style <\/span>= <\/span>styleArea <\/span>| <\/span>styleOwnScale <\/span>| <\/span>styleNoLabel<\/span>;
<\/span>Plot<\/span>( <\/span>ShowLastDay<\/span>( <\/span>1 <\/span>), <\/span>""<\/span>, <\/span>colorPaleYellow<\/span>, <\/span>style<\/span>, <\/span>0<\/span>, <\/span>1<\/span>, <\/span>0<\/span>, -<\/span>1 <\/span>)<\/code>
<\/p>
Other practical implementations of such technique is presented in these formulas:
http:\/\/www.amibroker.com\/kb\/2007\/03\/24\/how-to-plot-a-trailing-stop-in-the-price-chart\/<\/a>
http:\/\/www.amibroker.com\/kb\/2014\/10\/10\/how-to-draw-regression-channel-programatically\/<\/a><\/p>","protected":false},"excerpt":{"rendered":"