MultiCharts | PowerLanguage Tutorials | CH12: Text Drawing

Text Drawing

Text drawing is a feature that allows the drawing of text on charts to display trading information, important messages, and more.

The usage of text drawing functions mainly involves two actions:

  1. Creating a text object and obtaining a TextID:
    • Use the Text_New function to create a text object and obtain the TextID for this text object.
    • TextID is a variable used to store the unique ID of a text object created by the Text_New function.
  2. Operating on a text object with TextID:
    • With the TextID, you can perform various operations on the already created text, such as modifying, moving, or deleting it.
Var: textID(0);

// Create a text object and obtain the TextID,
// with the text being "Buy Signal" and the location set to the current date, time, and closing price.
textID = Text_New(Date, Time, Close, "Buy Signal");

// Operate on the text object using TextID
Text_SetColor(TextID, RGB(255,0,0)); // Set the text color to red
Text_SetFont(TextID, "Arial", 12, True, False); // Set the font to Arial, size 12, bold
Text_SetString(TextID, "Updated Text Here!"); // Update the text content

Text_New Function

APIText_New(BarDate, BarTime, PriceValue, "Text")
ExplanationDisplays a text object, consisting of the specified string expression located at the specified bar and specified price value, on the chart that the study is based on.
BarDate– A numerical expression specifying the date of the bar at which the object is to be placed.
– The date is indicated in the YYYMMdd format, where YYY is the number of years since 1900, MM is the month, and dd is the day of the month.
BarTime– A numerical expression specifying the time of the bar at which the object is to be placed.
– The time is indicated in the 24-hour HHmm format, where 1300 = 1:00 PM.
PriceValueA numerical expression specifying the price value (vertical position, corresponding to a value on the price scale of a chart), where the object is to be placed.
TextThe string expression to be displayed.
ReturnTextID,the unique number represents this text object。


The following code utilizes text drawing to visualize position information for recent closures on a chart, including profit, entry price, exit price.

if MP=0 and MP[1]<>0 then begin
	value1=TEXT_New(D, T, H,""); 
	text_SetString(value1,"+$"+Numtostr(positionprofit(1),3) + NewLine
	              +"EntryPrice: " + Numtostr(EntryPrice(1), 3) + NewLine
	              +"ExitPrice: " + Numtostr(ExitPrice(1), 3) + NewLine
     	              +"PositionProfit: " + Numtostr(PositionProfit(1), 3) + NewLine
	              +"OpenPositionProfit: " + Numtostr(OpenPositionProfit, 3)

	text_setfontname(value1,"Showcard Gothic");
	Text_SetBorder(value1, true);

The above code will produce output similar to the following:


Leave a Reply