plot (string name, var value, int type, int color)

plot (string name, vars data, int type, int color)

Plots a variable or the recent value of a series on the current bar position of a new curve on the chart, and exports it optionally to a CSV file. The plot curve is linked to the current asset. Not for histograms.

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 plotted and 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 xy position with the given color into the recent chart or histogram. Call this function to mark certain events in the price chart, or to plot a scatter graph in a histogram.

plotData (string name): DATA*

Returns a pointer to the DATA struct with the data stored by a chart plot or histogram. 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.



name The name for the chart legend; must be a string constant with less than 16 characters. Different curves - including the upper and lower curve of a band - must have different names. If the name begins with '#', the 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 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.
data The data series whose recent value is plotted.

The type of the data curve in the chart; must normally not change during the plot. 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.

LBL2 - for plotBar, label only every second x axis position.
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.

color The color and transparency of the data curve in the chart, in the form as described under Colors. Symbols and lines on a histogram can have different colors; on a chart all elements belonging to a certain name must have the same color. If at 0, no curve is plotted (for merely collecting data for later analyzing by plotData). Use the color function for assigning different colors to numbers.



// 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); } }
// Plotting a histogram bar
void plotHistogram(string Name,var Value,var Step,int Color)
  var Bin = floor(Value/Step);
plotBar(Name,Bucket,Step*Bin,1,SUM+BARS+LBL2,Color); }
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