How To Erase a Plot

by | Mar 6, 2018 | Indicators

This screen shot shows the TypicalPrice indicator plotted on a daily chart. We are interested in having this indicator show on the most recent 10 bars of a chart (cyan), and erasing the indicator beyond the 10th bar (yellow).
chart showing unwanted portion of indicator plot in yellow

Fig. 1. Chart showing unwanted portion of indicator plot in yellow

To erase the portion of the indicator shown in yellow, we can plot over the original plot with a second plot command, replacing the color with the background color (black) as follows:

Plot1(TypicalPrice, “Price”, cyan, default, 1);
Plot1[PriceLength](TypicalPrice, “Price”, black, default, 1);

This produces the chart shown below:
Unwanted portion of plot overplotted in black to hide original plot

Fig. 2. Unwanted portion of plot overplotted in black to hide original plot

This chart contains an undesirable result in that the overplotted indicator leaves a trail of black lines passing through the candlestick bodies and tails. To improve the appearance of an erased indicator, the indicator can be shifted from its original value to a value that is beyond the range of the candlestick bodies and tails. However, it is preferable not to shift the original indicator more than necessary to prevent the chart from rescaling the vertical axis and shrinking or compressing the price action. It is also desirable to make the shifted plot as narrow as possible to avoid overplotting and covering over any more of the small dots comprising the chart grid that necessary.

A convenient function to use to produce the desired shift is the fast calculation version of the Lowest Low function, LowestFC:

Plot1(TypicalPrice, “Price”, Cyan, default, 1);
Plot1[PriceLength]( LowestFC(Low, DisplaceLength), “Price”, Yellow, default, 0);

Using a DisplaceLength of 15 (greater than the length of the price that we desire to display, PriceLength = 10), produces the chart below:
chart with unwanted portion of plot displayed entirely below the bar lows

Fig. 3. Chart with unwanted portion of plot displayed entirely below the bar lows

And finally, we change the color of the original function that has been shifted away from the candlestick bodies and tails to match the background color of the chart (black), producing:
Displayed unwanted portion of plot is now overplotted in black, producing final desired hidden result

Fig. 4. Displayed unwanted portion of plot is now overplotted in black, producing final desired hidden result

Steps To Erase a Plot (TS versions prior to 9.0)

  • Plot the desired function (Typical Price, in this example).
  • Overplot this function with an offset of PriceLength bars, changing the color of the overplot to match the background color of the chart, and setting the width of this overplotted indicator to the narrowest width possible (width = 0).
  • Shift the overplot away from the symbol candlestick bars so that the overplotted function line (now in the background color: black) does not cross any of the body or tails of the candlesticks. This may be accomplished with the Lowest Low function using a length somewhat greater than the length of the indicator portion to remain visible on the chart.

Steps to Erase a Plot (TS versions 9.0 and later)

The reserved word transparent was introduced to Easylanguage in version 9.0 providing an simpler method to erase a plot:

Plot1(TypicalPrice, “Price”, Cyan, default, 1);
Plot1[PriceLength]( Plot1, “Price”, transparent);

Note that the second line over-writes PriceLength bars back from the current bar effectively making invisible whatever was plotted by the first statement.

The final code may be visualized by clicking the PlotErase Indicator link below.

Downloads

Initial posted version: 01/02/08

Latest Update: 01/31/10

*.ELD files are compiled for TS 8.7

All ELD and code text files packaged here:

PlotErase.zip

Users of earlier versions of Tradestation may compile the code
from the text files included in the above *.zip file.

The code may be visualized here:

Indicator: PlotErase