With drawing functions, you can plot the results of your program on the screen (on a chart). All drawing functions need several inputs that define the name of the study object and where it is positioned on the chart. You can also use them to remove a specific study object from the chart.
Note The latest value of every study object that is plotted on the chart can also be shown in study columns in a price page.
Drawing functions do not return any values and therefore are usually used on their own, that means the function call makes up a complete command statement.
DrawLine(Name, Level) |
Draws a line study object. |
DrawArea(Name, TopLevel, BottomLevel) |
Draws an area study object. |
DrawMarker(Name, PriceArrow, Orientation, MarkerText) |
Draws a marker study object. |
EraseLine(LineName) |
Removes a line study object. |
EraseArea(AreaName) |
Removes an area study object. |
EraseMarker(MarkerName) |
Removes a marker study object. |
SetLineProperty(Name, Property, Value) |
Changes the appearance of a line study object. |
SetAreaProperty(Name, Property, Value) |
Changes the appearance of an area study object. |
RGB(R, G, B) |
Defines a custom color. |
ResetLineProperty(Name, Property) |
Resets a property of a line study object to its default value. |
ResetAreaProperty(Name, Property) |
Resets a property of an area study object to its default value. |
This function draws a line study object.
A line study object is displayed on the chart as a single line. In price pages, lines are represented as one column per line, showing the value for the latest bar.
The appearance of the line can be changed with the function SetLineProperty. The default settings are defined on the Appearance tab of the Study Editor after saving the study. See also Line Settings.
DrawLine(Name, Level)
Parameters |
Name |
Text |
Defines the name of the line study object. If the first letter of the name is a pound sign, for example "#max", the study object will be visible on the chart but will not be included in the Data Info box (transparent area in the corner of the chart). |
|
Level |
Numeric |
Defines the level at which the line study object is drawn. |
Returns |
|
Nothing |
|
Line study objects are usually used for studies that show on the chart as a line or histogram. The line can be positioned at a level that is calculated anew for each bar, like in the example below (line of the Arms Index TRIN):
DrawLine("TRIN", #movs(middle, period, shift));
You can see here that the input value for the parameter Level of the DrawLine function is the output of another function movs. When you use such constructions, make sure that the return type of the other function matches the input type that is needed. In this case, the movs function produces a numeric output and can therefore be used as the input for the Level parameter, which expects numeric data.
Lines can also be positioned at fixed levels (example: zero line of the Aroon Oscillator):
DrawLine("#0", 0);
This function draws an area study object.
An area study object is displayed on the chart as a shaded, transparent area with two lines at the borders. In price pages, areas are represented by two columns, showing the Upper and Lower values for the latest bar.
The appearance of the area can be changed with the function SetAreaProperty. The default settings are defined on the Appearance tab of the Study Editor after saving the study. See also Area Settings.
DrawArea(Name, TopLevel, BottomLevel)
Parameters |
Name |
Text |
Defines the name of the area study object. If the first letter of the name is a pound sign, for example "#max", the study object will be visible on the chart but will not be included in the Data Info box (transparent area in the corner of the chart). |
|
TopLevel |
Numeric |
Defines the level at which the top border line of the area study object is drawn. |
|
BottomLevel |
Numeric |
Defines the level at which the bottom border line of the area study object is drawn. |
Returns |
|
Nothing |
|
An area study object is used for studies such as the Bollinger Bands or the RSI, often in combination with a line study object:
DrawLine("RSI", rsi(Source, period, n));
DrawArea("#Upper", upperLevel, 100);
DrawArea("#Lower", lowerLevel, 0);
Note In the Study Editor, you have the possibility to activate the Percentage Mode for your area: The area will then be displayed with percentage values instead of absolute values, e.g. with the top border at 75% and the bottom border at 25%. The border lines of areas in percentage mode are not influenced by changes in the vertical price scale, they will always cover the set percentage of the chart pane, regardless of the settings of the vertical price scale.
This function draws a marker study object.
A marker study object is displayed on the chart as a combination of two arrows (up/down arrow and price arrow) and marker text. In price pages, markers are represented by three columns, showing the orientation of the up/down arrow, the marker text, and the price level of the price arrow.
The standard appearance of the marker can be defined on the Appearance tab of the Study Editor after saving the study. See also Marker Settings.
DrawMarker(Name, PriceArrow, Orientation, MarkerText)
Parameters |
Name |
Text |
Defines the name of the marker study object. If the first letter of the name is a pound sign, for example "#max", the study object will be visible on the chart but will not be included in the Data Info box (transparent area in the corner of the chart). |
|
PriceArrow |
Numeric |
Defines the level at which the price arrow is displayed. |
|
Orientation |
Boolean |
Defines the orientation of the up/down arrow that is drawn. If the value is True, an up arrow will be drawn; if the value is False, a down arrow will be drawn. |
|
MarkerText |
Text |
Defines the marker text that is displayed below or above the up / down arrow. |
Returns |
|
Nothing |
|
Marker study objects are typically used for displaying the signals on a chart. For example, the candlestick pattern Hammer uses a marker study object:
DrawMarker("Hammer_TM", Source.Close, True, "Hammer");
This example code draws an upwards oriented arrow which shows up under the name "Hammer_TM" in TeleTrader WorkStation. The price arrow is usually positioned at a certain price level of the underlying symbol (here at the Close).
If you want to use both an upwards and a downwards oriented arrow within one study, the two marker objects must be referred to with the same name but use a different orientation:
DrawMarker("BuySellArrow", Source.Close,
True,
"Buy");
DrawMarker("BuySellArrow", Source.Close,
False,
"Sell");
This function removes a specific line study object from the chart. The line study object does not have to be drawn in the same program in that it is later removed – it must only be referred to with its correct name.
EraseLine(LineName)
Parameters |
LineName |
Text |
Specifies the name of the line study object that should be removed. |
Returns |
|
Nothing |
|
To remove a line from the screen, it must first be drawn by the function. For example, if you draw a line called "TestLine", you can later remove it by using its name:
DrawLine("TestLine", TestLineLevel);
{... code to calculate
MyRealLevel ... }
If IsValid(MyRealLevel) Then
Begin
EraseLine("TestLine");
DrawLine("RealLine", MyRealLevel);
End;
In this example, you first draw a "TestLine". Then you try to compute the real line level – if the result is valid, you erase the "TestLine" and instead draw a "RealLine".
This function removes a specific area study object from the chart. The area study object does not have to be drawn in the same program in that it is later removed – it must only be referred to with its correct name.
EraseArea(AreaName)
Parameters |
AreaName |
Text |
Specifies the name of the area study object that should be removed. |
Returns |
|
Nothing |
|
This function removes a specific marker study object from the chart. The marker study object does not have to be drawn in the same program in that it is later removed – it must only be referred to with its correct name.
EraseMarker(MarkerName)
Parameters |
MarkerName |
Text |
Specifies the name of the marker study object that should be removed. |
Returns |
|
Nothing |
|
For example, if you want to show only the most recent occurrence of a marker on the screen, you can erase all previously drawn markers:
{Remember when
the last signal was triggered}
lastSignalOn = lastSignalOn[1];
{Add some conditions
to trigger the signal under certain conditions}
movs_fast[0] =
#movs(Source, 9, 0);
movs_slow[0] =
#movs(Source, 18, 0);
If
movs_fast Crosses movs_slow Then
Begin
{When conditions
are triggered, draw new marker and remember its position, calculate distance to
last marker and erase old marker} lastSignalOn = CurrentBar;
DrawMarker[0]("MACross",Source[0], True, "Cross");
distance = CurrentBar - lastSignalOn[1];
EraseMarker[distance]("MACross");
End;
This function lets you change the properties of a specific line study object. It must be referred to with its correct name. The properties set by this function override the settings on the Appearance tab of the Study Editor. See also Line Settings.
SetLineProperty(Name, Property, Value)
Parameters |
Name |
Text |
Specifies the name of the line study object that should be changed. |
|
Property |
Special |
Specifies the line property that you want to change. Use one of the properties listed below: Weight or Width Style Color |
|
Value |
Special |
Defines the value that you want to set for the specified property. The following options are available: Weight Number between 1 and 4 Style Solid, Dash, Dot, DashDot Color clrBlack, clrGray, clrSilver, clrWhite, clrNavy, clrBlue, clrTeal, clrAqua, clrOlive, clrGreen, clrLime, clrPurple, clrMagenta, clrRed, clrMaroon, clrYellow or use the function RGB to define a custom color (see RGB function) |
Returns |
|
Nothing |
|
You can for example use this function to change the appearance of a line based on certain conditions. The following example shows a "Volume" line that changes its color to green when the current volume exceeds the average volume of the last 10 bars:
DrawLine("Volume", Source.Vol);
If Source.Vol
> Average(Source.Vol, 10) Then
Begin
SetLineProperty("Volume", Color, clrGreen);
SetLineProperty("Volume", Width, 3);
End
Else
SetLineProperty("Volume", Style, DashDot);
This function lets you change the properties of a specific area study object. It must be referred to with its correct name. The properties set by this function override the settings on the Appearance tab of the Study Editor. See also Area Settings.
SetAreaProperty(Name, Property, Value)
Parameters |
Name |
Text |
Specifies the name of the area study object that should be changed. |
|
Property |
Special |
Specifies the area property that you want to change. Use one of the properties listed below: Weight or Width Style Line1Color Line2Color FillColor FillTransparency |
|
Value |
Special |
Defines the value that you want to set for the specified property. The following options are available: Weight Number between 1 and 4 Style Solid, Dash, Dot, DashDot Colors clrBlack, clrGray, clrSilver, clrWhite, clrNavy, clrBlue, clrTeal, clrAqua, clrOlive, clrGreen, clrLime, clrPurple, clrMagenta, clrRed, clrMaroon, clrYellow or use the function RGB to define a custom color (see RGB function) Transparency Number between 0 and 100 |
Returns |
|
Nothing |
|
The following example shows how to set the transparency of an area depending on the current bar position:
movs1 = #movs(Source, 50, 0);
movs2 = #movs(Source, 5, 0);
pos = CurrentBar/LastBar*100;
DrawArea("Area", movs2, movs1);
SetAreaProperty("Area", FillTransparency, 100 - pos );
This function lets you define a custom color that can be used in the functions SetLineProperty and SetAreaProperty.
RGB(R, G, B)
Parameters |
R |
Numeric |
Number between 0 and 255 (Red component) |
|
G |
Numeric |
Number between 0 and 255 (Green component) |
|
B |
Numeric |
Number between 0 and 255 (Blue component) |
Returns |
|
Numeric |
|
The following example shows the definition of a HeatColor with the RGB function. The HeatColor changes with the position of the current bar and can later be used to color lines or areas.
{ Define
HeatColor }
bar = CurrentBar;
If bar <= 255 Then
HeatColor = RGB(bar, 0, 0)
Else If
bar <=
510 Then
HeatColor = RGB(255, bar, 0)
Else If
bar <=
765 Then
HeatColor = RGB(255, 255, bar)
Else
HeatColor = RGB(255, 255, 255);
{ Use in Line }
DrawLine("HeatLine", Source.Close);
SetLineProperty("HeatLine", Color, HeatColor);
This function resets the specified line property of a line study object to its default value (that is, the value defined on the Appearance tab of the Study Editor).
ResetLineProperty(Name, Property)
Parameters |
Name |
Text |
Specifies the name of the line study object that should be reset to default. |
|
Property |
Special |
Specifies the line property that you want to reset to default. Use one of the properties listed below: Weight or Width Style Color |
Returns |
|
Nothing |
|
This function resets the specified area property of an area study object to its default value (that is, the value defined on the Appearance tab of the Study Editor).
ResetAreaProperty(Name, Property)
Parameters |
Name |
Text |
Specifies the name of the area study object that should be reset to default. |
|
Property |
Special |
Specifies the area property that you want to reset to default. Use one of the properties listed below: Weight or Width Style Line1Color Line2Color FillColor FillTransparency |
Returns |
|
Nothing |
|