PineScript v6 範例程式

我們直接使用 TradingView 官方提供的 AlertMessage 示範程式。

v6 的 Alert Message 無法像 V5 一樣直接宣告成自己可以組合的字串,因此最終輸出只能是一種結果。

首先我們看下方的官方原始 MA CrossOver 範例程式:

  1. 原始的程式沒有設定 alert_message

  2. 因此建立快訊時無法讓用戶自己定義快訊的内容

// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © TCGM

//@version=6
strategy("TC_PineScriptV6", overlay=true )

longCondition = ta.crossover(ta.sma(close, 14), ta.sma(close, 28))
if (longCondition)
    strategy.entry("LE", strategy.long)

shortCondition = ta.crossunder(ta.sma(close, 14), ta.sma(close, 28))
if (shortCondition)
    strategy.entry("SE", strategy.short)

加入自定義快訊的設定

要加入自定義快訊的設定,請在買賣條件的指令加入 alert_message="" 的語法

例如:

加入後

調整後的程式語法如下

circle-exclamation
circle-exclamation

建立 TradingView 快訊下單

達錢專用下單字串説明

使用達錢專用的下單字串

TOTC.{{timenow}}@account=你的交易帳號,sym=下單代碼,side={{strategy.order.action}},qty={{strategy.order.contracts}},p={{strategy.order.price}},ordertype=2,tif=1,ts={{timenow}},tvorderID=你的策略代號

上面的字串能夠調整的部分如下:

  • 你的交易帳號

  • 下單代碼

    • 台指 TC.F.TWF.TXF.HOT

    • 小臺 TC.F.TWF.MXF.HOT

    • 微小 TC.F.TWF.TMF.HOT

    • NQ TC.F.CME.NQ.HOT

    • 其他不知道可以向客服查詢

  • ordertype

    • 目前預設為 2,代表以市價送出委託。

    • 如果要使用一定範圍市價可以改成 25。

  • tif

    • 目前設定為 1,代表 IOC。

    • 搭配市價或是一定範圍市價不需要改變。

  • 你的策略代號

    • 可以依照喜歡設定,不要使用特殊字元或是中文。

    • A~Z, a~z, 0~9

    • 設定不同的策略代號可以避免多個策略如果在同一個時間點下單被系統濾掉的問題。

設定下單快訊

  • 完成策略程式的設定後,就可以開始設定快訊。

  • 點擊快訊按鈕

  • 於彈出的視窗選擇你的策略名稱

  • 點擊【訊息】切換到快訊内容頁面

  • 移除原本的内容,替換達錢專用的下單字串 TOTC.{{timenow}}@account=000-888888,sym=TC.F.TWF.TMF.HOT,side={{strategy.order.action}},qty={{strategy.order.contracts}},p={{strategy.order.price}},ordertype=2,tif=1,ts={{timenow}},tvorderID=SAMPLE001

circle-exclamation
  • 確認内容正確後,點擊【建立】完成快訊設定。

  • 快訊建立成功

  • 切換到日志,啓動【快訊下單】即可開始自動交易。

triangle-exclamation

Last updated