文字繪製#

文字繪製讓你可以在圖表上顯示交易資訊和訊息。常用的文字繪製函數包含建立和刪除設定文字內容和位置設定外觀

文字繪製函數的用法,主要分成兩個動作:

  1. 建立文字物件並獲取 TextID: 使用 Text_New 函數建立文字物件,回傳這個文字物件的唯一 ID,儲存在變數 TextID 中。
  2. 使用 TextID 操作文字物件: 有了 TextID,就可以對已經建立的文字進行各種操作,如修改、移動或刪除。
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
Variables: TextID(0);

// 建立文字物件並獲取 TextID,文字為 "Buy Signal",位置為當前的日期、時間和收盤價
TextID = Text_New(Date, Time, Close, "Buy Signal");

// 使用 TextID 進一步操作文字物件
Text_SetColor(TextID, RGB(255, 0, 0));
Text_SetFontName(TextID, "Arial");
Text_SetSize(TextID, 12);
Text_SetAttribute(TextID, 1, true);
Text_SetString(TextID, "Updated Text Here!");

範例#

下面程式碼使用文字繪製,在圖表上產生上一次平倉的持倉資訊(獲利、入場價格、出場價格)。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
Variables: MP(0);

MP = MarketPosition * CurrentContracts;

If MP = 0 and MP[1] <> 0 Then Begin
  Value1 = Text_New(Date, Time, High, "");
  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_SetStyle(Value1, 2, 1);
  Text_SetColor(Value1, RGB(232, 232, 0));
  Text_SetFontName(Value1, "Showcard Gothic");
  Text_SetSize(Value1, 14);
  Text_SetAttribute(Value1, 1, true);
  Text_SetBorder(Value1, true);
  Text_SetLocation(Value1, Date, Time, High + 200);
End;

上面的程式碼將產生類似下面的輸出:

常用的文字繪製函數#

文字繪製函數的回傳值如果是 0 代表操作成功,-2 代表 ObjectID 無效。

建立和刪除#

Text_New(BarDate, BarTime, PriceValue, "Text")#

在圖表上建立一個文字物件,位於指定的K棒和價格上,回傳這個文字物件的 TextID

項目說明
BarDate數值,指定要放置物件的K棒日期。日期以 YYYMMdd 格式表示,其中 YYY 是自 1900 年以來的年數,MM 是月份,dd 是日
BarTime數值,指定要放置物件的K棒時間。時間以 24 小時 HHmm 格式表示,例如 1300 = 下午 1:00
PriceValue數值,指定文字物件的垂直位置,對應圖表價格刻度上的值
Text要顯示的字串
回傳值TextID,代表這個文字物件的唯一 ID

Text_Delete(ObjectID)#

刪除指定的文字物件。

項目說明
ObjectID文字物件的 ID

設定文字內容和位置#

Text_SetString(ObjectID, "Text")#

設定文字物件顯示的字串。

項目說明
ObjectID文字物件的 ID
Text要顯示的字串

Text_SetLocation(ObjectID, BarDate, BarTime, PriceValue)#

設定文字物件的位置。參數格式同 Text_New

項目說明
ObjectID文字物件的 ID
BarDateK棒日期,YYYMMdd 格式
BarTimeK棒時間,24 小時 HHmm 格式
PriceValue垂直位置,對應圖表價格刻度上的值

設定外觀#

Text_SetColor(ObjectID, TextColor)#

設定文字的顏色。

項目說明
ObjectID文字物件的 ID
TextColor顏色值,可使用 RGB(R, G, B) 或顏色名稱(如 Blue)

Text_SetBGColor(ObjectID, BGColor)#

設定文字的背景顏色。

項目說明
ObjectID文字物件的 ID
BGColor背景顏色值,可使用 RGB(R, G, B) 或顏色名稱

Text_SetFontName(ObjectID, "FontName")#

設定文字的字體,可使用 Windows 已安裝的字體。

項目說明
ObjectID文字物件的 ID
FontName字體名稱,例如 "Arial""Verdana"

Text_SetSize(ObjectID, FontSize)#

設定文字的字體大小。

項目說明
ObjectID文字物件的 ID
FontSize字體大小

Text_SetStyle(ObjectID, HorizPl, VertPl)#

設定文字物件相對於K棒和價格的對齊方式。

項目說明
ObjectID文字物件的 ID
HorizPl水平對齊。0: K棒右側。1: K棒左側。2: K棒中央
VertPl垂直對齊。0: 價格下方。1: 價格上方。2: 價格中央

Text_SetAttribute(ObjectID, Attribute, LogicalExpression)#

設定文字的樣式屬性。

項目說明
ObjectID文字物件的 ID
Attribute0: 邊框。1: 粗體。2: 斜體。3: 刪除線。4: 底線
LogicalExpressiontrue: 啟用。false: 停用

Text_SetBorder(ObjectID, LogicalExpression)#

設定文字物件是否顯示邊框,邊框顏色與文字顏色相同。

項目說明
ObjectID文字物件的 ID
LogicalExpressiontrue: 顯示邊框。false: 隱藏邊框

Reference#

https://www.multicharts.com/trading-software/index.php?title=Category:Text_Drawing

© 2026 CodeReindeer. All rights reserved.