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].

Parameters:
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. |
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. recent value is plotted. |
Type |
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:
BARS - 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. |
Remarks:
- In [Test] mode the chart
viewer either appears automatically after the test, or at pressing [Result], dependent on
PLOTNOW. In [Trade]
mode a chart is plotted every day or in shorter intervals, dependent
on PlotPeriod. In [Train]
mode no charts are plotted; instead parameter histograms are displayed
in a browser that show the objective value and the number of winning and losing trades for each parameter.
Histograms and charts can not be plotted at the same time; plotBar overrides plot.
- The vertical axis of charts and histograms is
automatically
scaled so that all elements are visible. This causes 'flat
lines' when elements are too far apart or at wrong positions,
for instance a plot at position 0 on a chart with a 1.1 - 1.2
price range. Elements by plotGraph can affect
the scale even when they are outside the visible chart section.
- Zorro charts are very informative, but
not particularly pretty. For
better looking charts, set
LOGFILE. The data from the histogram or chart is
then stored in a *_plot.csv file in the Log folder
that can be further evaluated and made into a more colorful chart
with Excel™ or other spreadsheet programs.
- When extra charts are opened with NEW, the order of plot calls determines in which chart the curves are plotted. The order is determined by the first plot call in or after the FIRSTRUN. Subsequent calls can then be in arbitrary order. When plot order matters and plots depend on if(...) conditions, enforce the right order in the first run f.i. with if(is(FIRSTRUN)).
Candles and bands are only plotted in the main chart.
- If plot is called several times with the same
Name in the same run cycle, only the last data value is plotted. If a
plot command is not called during a bar, the plotted curve will
have gaps at the skipped bars.
This can be used for plotting dotted lines.
- Every plot on a chart must have the same Type and
Color. For plotting a curve in different colors, use alternating curves with the same value and different
Name. In a histogram, any graph or symbol can
have an individual color.
- plotGraph and plotText limit to the number of elements (lines, symbols,
texts) per plot to the number of bars on the chart. Exceeding the limit causes an
Error 038 message. For adding more elements to the chart, use
another plotGraph with a different Name.
- Any plot command is normally
linked to the current asset. When
multiple assets are traded, only prices, trades, and curves linked to the asset selected with the [Asset] scrollbox are plotted; curves linked to other assets are only plotted when
PlotMode got set to PL_ALL. For plotting parameters of different assets together, store them in different variables and then plot all together without calling
asset() inbetween.
For instance, inside an asset loop you can
store them in a var array with one element per asset, then plot all elements of the array after the asset loop. The curves are then visible on the chart when you select the last asset of the loop and click [Result].
- For removing chart elements such as price candles or equity curves, set their
Color to 0.
- Use the color function for setting
color ranges in multicolor
histograms. An example can be found in profile.c for the heatmap plotting.
- Use plotData for
exporting plots to data files and displaying them with
other charting software. The equity curve can be
exported to a CSV file.
- Example for plotting a symbol only at every second bar:
if(Bar%1) plot(...);.
- For adjusting scale, colors,
symbol sizes, x axis labels etc, set up the corresponding
plot variable.
- Special histograms, such as trade profiles, MAE graphs, seasonal profiles, correlograms or heatmaps can be plotted with the functions from the
profile library.
- Curves can be plotted even without a run function - f.i. for
HFT simulation - when the bars are increased by
priceQuote. Make sure that the plot function is then called at every bar for avoiding gaps in the curve.
Examples (see also profile.c):
// Compare price distribution (red) with random distribution (blue)
function run()
{
vars Price = series(price(0));
int num = NumRiseFall(Price,20);
plotBar("Price",2*num,num,1,SUM|BARS,RED);
vars Random = series(0);
Random[0] = Random[1] + random();
num = NumRiseFall(Random,20);
plotBar("Random",2*num+1,0,1,SUM|BARS,BLUE);
}
// plotGraph test
function run()
{
set(PLOTNOW);
// plot green dots above the price at every 20th bar
if(Bar%20 == 0)
plot("Dotted",1.01*price(),DOT,GREEN);
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);
}
// Plotting 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