public method host:execute("drawLabel1", ...)

Brief

Creates or replaces a label (advanced version).

Declaration
Lua
string host:execute ("drawLabel1", id, x, xType, y, yType, halign, valign, font, color, text)

Parameters
id

Integer. The label identifier.

x

Double. X-coordinate of the label. The meaning of the value depends on the value of xType parameter.

xType

Integer. The parameter can be one of the following values:

core.CR_CHART

The value of the x parameter is date/time. The label will move when chart is moved.

core.CR_LEFT

The value of the x parameter is number of points (a point is 1/72 of inch) from the left side of the chart area.

core.CR_RIGHT

The value of the x parameter is number of points (a point is 1/72 of inch) from the right side of the chart area.

core.CR_CENTER

The value of the x parameter is number of points (a point is 1/72 of inch) from the center of the chart area.

y

Double. Y-coordinate of the label. The meaning of the value depends on the value of yType parameter.

yType

Integer. The parameter can be one of the following values:

core.CR_CHART

The value of the y parameter is price. The label will move when chart is moved.

core.CR_TOP

The value of the y parameter is number of points (a point is 1/72 of inch) from the top side of the chart area.

core.CR_BOTTOM

The value of the y parameter is number of points (a point is 1/72 of inch) from the bottom side of the chart area.

core.CR_CENTER

The value of the y parameter is number of points (a point is 1/72 of inch) from the center of the chart area.

halign

Integer. The horizontal alignment of the label agains the points specified by x and y coordinates.

The horizontal alignment. Can be core.H_Left, core.H_Center or core.H_Right

core.H_Left

The label must be located at left of the data/time line. The right border of the text area must touch the date/time line.

core.H_Center

The label must be centered against the date/time line.

core.H_Right

The label must be located at right of the data/time line. The left border of the text area must touch the date/time line.

valign

Integer. The vertical alignment of the label against the points specified by x and y coordinates.

Can be core.V_Top, core.V_Center or core.V_Bottom

core.V_Top

The label must be located at above the price line. The bottom border of the text area must touch the price line.

core.V_Center

The label must be centered against the price line.

core.V_Bottom

The label must be located below the price line. The top border of the text area must touch the price line.

font

String. The font previously created using host:execute("createFont") or nil to use the default chart label font.

color

Integer. The color of the label. You can either create your own color using core.rgb(), choose one of the color returned by core.colors(), or specify one of the following constants: core.COLOR_LABEL, core.COLOR_LINE, core.COLOR_UPCANDLE, core.COLOR_DOWNCANDLE, core.COLOR_CUSTOMLEVEL, core.COLOR_BACKGROUND to use the Marketscope's default colors.

text

The label text.

Details

Note: This function is optional and may be not supported by the host application.

To remove the line use the host:execute("removeLabel"); method.

The method can be used in indicators only.

Example: Create custom labels [hide]

   function Init()
       indicator:name("testlabel");
       indicator:requiredSource(core.Bar);
       indicator:type(core.Indicator);
   end
 
   local font;
   local font2;
   local source;
 
   function Prepare()
       source = instance.source;
       instance:name(profile:id());
       font = core.host:execute("createFont", "Courier", 10, true, false);
       font2 = core.host:execute("createFont", "Wingdings", 10, false, false);
   end
 
   function Update(period, mode)
       if source:size() > 0 and period == source:size() - 1 then
           local id = 1;
 
           local min, max;
           min, max = mathex.minmax(source, source:first(), source:size() - 1);
 
           core.host:execute("drawLabel1", id, 0, core.CR_LEFT, 0, core.CR_TOP, core.H_Right, core.V_Bottom,
                             font, core.rgb(255, 0, 0), "top-left");
           id = id + 1;
           core.host:execute("drawLabel1", id, 0, core.CR_LEFT, 0, core.CR_BOTTOM, core.H_Right, core.V_Top,
                             font, core.rgb(0, 255, 0), "bottom-left");
           id = id + 1;
           core.host:execute("drawLabel1", id, 0, core.CR_RIGHT, 0, core.CR_TOP, core.H_Left, core.V_Bottom,
                             font, core.rgb(0, 0, 255), "top-right");
           id = id + 1;
           core.host:execute("drawLabel1", id, 0, core.CR_RIGHT, 0, core.CR_BOTTOM, core.H_Left, core.V_Top,
                             font, core.rgb(0, 255, 255), "right-bottom");
           id = id + 1;
           core.host:execute("drawLabel1", id, 0, core.CR_CENTER, 0, core.CR_CENTER, core.H_Center, core.V_Center,
                             font, core.rgb(0, 255, 255), "center");
           id = id + 1;
           core.host:execute("drawLabel1", id + 5, 0, core.CR_CENTER, min, core.CR_CHART, core.H_Center, core.V_Bottom,
                             font2, core.rgb(0, 255, 255), "\225");
           id = id + 1;
           core.host:execute("drawLabel1", id + 5, 0, core.CR_CENTER, max, core.CR_CHART, core.H_Center, core.V_Top,
                             font2, core.rgb(0, 255, 255), "\226");
       end
   end
 
   function ReleaseInstance()
       core.host:execute("deleteFont", font);
       core.host:execute("deleteFont", font2);
   end

back