Plot functions

plot (string Name, var Value, int Type, int Color)

plot (string Name, vars Data, int Type, int Color)

Plots a variable, or the first element of the Data series, on the current bar position on the chart, and exports it optionally to a CSV file. The value can be plotted as a dot, line, bar, or band, dependent on Type. The plot is linked to the current asset. 

plotBar (string Name, int Pos, var Label, var Value, int Type, int Color)

Adds a value to a given x axis position in a histogram. A histogram consists of vertical bars that display the sum, average, standard deviation, maximum, or minimum of the values added to any x position. It is optionally also exported to a CSV file.

plotGraph (string Name, var X, var Y, int Type, int Color)

Plots a dot, symbol, line, or polygon at a given X,Y position with the given Color into the current chart or histogram. Call this function to mark certain events in the price chart, or to plot a scatter graph in a histogram.

plotText (string Name, var X, var Y, string Text, int Style, int Color)

Displays the Text with the given Color at a given X,Y relative or absolute position on the current chart or histogram. Text on relative positions is visible above a zoom factor determined by PlotText.

plotData (string Name): DATA*

Returns a pointer to the DATA struct with the data stored by a chart plot or histogram with the given Name. The DATA struct is defined in include\trading.h. DATA->Data[DATA->start] is the first valid data point, and DATA->Data[DATA->end] the last. In the case of a chart plot, wdateBar(n) is the time belonging to Data[n]. The function can be used for retrieving the plot curve, for analyzing it, or for modifying data before plotting. The returned data is in chronological order.

plotChart (string FileName)

Generates a chart or histogram from the previous plot calls, and displays it with the chart viewer or stores it in a .png file with the given FileName when PL_FILE is set. Deletes all plot elements so that new plots can be built afterwards. Use this function to update charts or histograms in real time (see PayOff.c). If this function is not used, the chart is generated at the end of a backtest or when clicking [Result].



Name The name for the chart legend; a string constant with up to 15 characters. Different curves - including the upper and lower curve of a band - must have different names. If the name begins with '#', it does not appear in the chart legend.
Pos The bar number in a histogram (-2000..2000), determines the bar's position on the horizontal axis. All plotBar commands within a +/-0.5 range of the same bar number plot to the same bar.
X,Y In a histogram, X is the bar number and Y is the bar height or position on the vertical axis.
In a price chart, X is the bar offset (0 = current bar), and Y is the position on the left or right vertical axis.
Label A number printed on the horizontal axis at the given bar position, or 0 for no label. For readability, label numbers should be in the ±0.1 .. ±1000 range.
Value The data value to be plotted or added to the bar. Use 1 in combination with SUM for counting events in a histogram. For plotting an int, cast it to var.
Text The text to be plotted on the chart; up to 15 characters. For longer texts put several plotText calls together.
Data The data series whose first element, i.e. most recent value is plotted.

The type of the data curve in the chart or the bar in a histogram; must not change per Name. Either 0 for a simple line, or a combination of:

- plot a bar or vertical mark. For plot and plotBar.
DOT - plot a colored dot. For plot, plotBar, and plotGraph.
BAND1 - for plot, plot the upper line of a band, use the color for the upper and lower lines. Main chart only.
BAND2 - for plot, plot the lower line of a band, use the color for filling the band. Main chart only.
LINE - for plot, use a thick line. Otherwise it's a thin line.

MAIN - for plot, plot this and all following curves in the main price chart.
NEW - for plot, plot this and all following curves in a new extra chart (see remark below about plot order).
AXIS2 - use a second y axis on the right side of the chart.
LOG - use a logarithmic y scale.

AVG - for plotBar, plot the average of all values of the current x position. For plot, use the average of all sample cycles.
DEV - for plotBar, plot the standard deviation of all values of the current x position.
SUM - for plotBar, plot the sum of all values at the current x position.
MINV - for plotBar, plot the minimum of all values at the current x position.
MAXV - for plotBar, plot the maximum of all values at the current x position.
NRM - for plotBar, normalize the values of all x positions to 1.

LINE - for plotGraph, draw a line from the last position to the current position.
END - for plotGraph, end point of a line or polygon started with LINE.
DEL - for plotGraph, delete the previous plot and start over.
DOT - draw a colored dot. The size can be determined with PlotScale.
SQUARE - draw a colored square.
TRIANGLE - draw a upwards pointing colored triangle.
TRIANGLE2,3,4 - draw a colored triangle pointing to the left, right, or down.
CROSS - draw a colored cross.
CROSS2 - draw a colored diagonal cross.

Style Text style; must not change per Name. Text centered = 0 (default), aligned to Bottom Left = 1, Bottom Center = 2, Bottom Right = 3, Left = 4, Right = 6, Top Left = 7, Top Center = 8, Top Right = 9. Add 32 for text at absolute X,Y pixel position (0,0 = upper left corner of the chart). Add 64 for text on a white background. Add 128 for large bold text.
Color The color and transparency of the data curve, bar, symbol, or text, in the format as described under Colors.. Elements on a histogram can have different colors; on a chart the color must not change per Name. If at 0,, nothing is plotted, but the data is stored for later analyzing it by plotData. Use the color function for generating color ranges.


Examples (see also profile.c, indicators.c):

// Compare price distribution (red) with random distribution (blue)
function run()
  vars Price = series(price(0));
  int num = NumRiseFall(Price,20);

  vars Random = series(0);
  Random[0] = Random[1] + random();
  num = NumRiseFall(Random,20);
// plotGraph test
function run()
// plot green dots above the price at every 20th bar
  if(Bar%20 == 0)
if(Bar == 500) { // plot a single blue rectangle in the price chart plotGraph("Rectangle",0,0.99*price(),LINE,BLUE); // start point plotGraph("Rectangle",-500,0.99*price(),LINE,BLUE); // 1st corner plotGraph("Rectangle",-500,1.01*price(),LINE,BLUE); // 2nd corner plotGraph("Rectangle",0,1.01*price(),LINE,BLUE); // 3rd corner plotGraph("Rectangle",0,0.99*price(),LINE|END,BLUE); // 4th corner and end point // plot a single red dot plotGraph("Single Dot",-250,price(),DOT,RED); } }
// plot tiny triangles above / below price for buy and sell signals
PlotScale = 8; // size of triangle
if(SignalBuy) plot("Buy",0.9*priceLow(),MAIN|TRIANGLE,GREEN);
if(SignalSell) plot("Sell",1.1*priceHigh(),MAIN|TRIANGLE4,RED);
// plot a chart title
if(Init) plotText("Title",60,25,"My Chart",32+64+128+7,BLACK);
Examples of plotting symbols can be found in the Predict script and in the profile library.

See also:

printf, PlotMode, PlotScale, plotProfile, Colors, color

► latest version online