Plot functions

Zorro can generate charts, histograms, or scatter plots, and export the data in CSV or image format for further evaluation. The profile library contains often-used functions for diagrams. The following plot commands are available:

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. 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 can be exported to a CSV file for further evaluation.

plotHistogram(string Name, var Value, var Step, var Weight, int Color): int

Variant of plotBar for plotting a histogram bar. The Value range is dividied in equidistant Steps. Bars belonging to the same Step are accumulated by adding their Weights. Returns the x axis position of the bar.

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

Plots a dot, symbol, line, spline, or polygon at a given X,Y position with the given Color either to the current chart, to the current histogram created by plotBar, or to a scatter plot when Type was combined with GRAPH. Call this function to mark certain events in the price chart.

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 (dependent on Style, see below)  on the current chart, scatter plot, or histogram. Text on relative positions scrolls with the other chart elements and is only visible when the chart is 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] is the last. The data points are in chronological order. DATA->Data[n] is the data point at bar number n, and its timestamp is therefore wdateBar(n). The function can be used for retrieving the plot curve, for analyzing it, for modifying data before plotting, or for exporting it to other charting tools.

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. Exports it to a CSV file when PL_EXPORT 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].

Chart with candles and indicators, created with plot commands

Autocorrelation histogram created with plotBar commands

MAE scatter plot, created with plotGraph commands.



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 in the -4000..4000 range. Determines the bar's position on the horizontal axis. All plotBar commands with the same bar number affect the height of the bar in various ways, dependent on the Type parameter.
X,Y In a histogram, X is the bar number in -4000..4000 range, and Y is the position on the vertical axis.
In a scatter plot, X and Y are horizontal and vertical coordinates in arbitrary units.
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 Pos position, or NIL for no label. For better readability, label numbers should be in the ±0.1 .. ±1000 range and should be not too tight together.
Value The data value to be plotted or added to the bar. Use 1 in combination with SUM for counting events. For plotting an int, cast it to var.
Text Short text to be plotted on the chart; up to 15 characters. For longer texts put several plotText calls together.
Data The data series whose most recent value is plotted.

The type of the data curve or element in the chart or histogram. All elements with the same Name must be of same Type. Use 0 for a simple line on the chart, 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.
AVG - for plot, use the average of all sample cycles.

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 bar values at the current x position.
- for plotBar, plot the standard deviation of all values at 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 bars to 1.

LINE - for plotGraph, draw a straight line from the last position to the current position.
SPLINE - for plotGraph, draw a curved line from the last position to the current position.
END - for plotGraph, end point of a line or polygon started with LINE.
GRAPH - for plotGraph, plot the element to a scatter plot. 
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; all texts with the same Name must have the same Style. 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 Color and transparency of the data curve, bar, symbol, or text, in the format as described under Colors.. Elements on a histogram or scatter plot can have different colors; on a chart all elements with the same Name must have the same Color. 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, and the plot2 function for plotting curves in two colors.


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, dataChart, Colors, color

► latest version online