# 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="" 的語法

例如：

```
if (longCondition)
    strategy.entry("LE", strategy.long)
```

加入後

```
if (longCondition)
    strategy.entry("LE", strategy.long, alert_message="")
```

調整後的程式語法如下

{% hint style="warning" %}
請特別注意在每個進出的語法都要加上 , alert\_message=""。
{% endhint %}

```
// 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, alert_message="")

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

{% hint style="warning" %}
完成策略的調整，請一點要按更新策略，將調整後的内容更新到圖表。
{% endhint %}

<figure><img src="/files/AREfe6qmw9nklAev1wja" alt=""><figcaption></figcaption></figure>

### 建立 TradingView 快訊下單

### 達錢專用下單字串説明

使用達錢專用的下單字串

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

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

* 你的交易帳號
  * 取得方式可以參考 v5 的設定教學影片
  * <https://youtu.be/JCNOT3kI-Vc?si=2i29VEVsbHwWtBST&t=1208>
* 下單代碼
  * 台指 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
  * 設定不同的策略代號可以避免多個策略如果在同一個時間點下單被系統濾掉的問題。

### 設定下單快訊

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

* 點擊快訊按鈕<br>

  <figure><img src="/files/HAY2if8HslLweFzUnhx9" alt=""><figcaption></figcaption></figure>

* 於彈出的視窗選擇你的策略名稱\ <br>

  <figure><img src="/files/qn4lN7GQWrpVXnnjHU4i" alt=""><figcaption></figcaption></figure>

* 點擊【訊息】切換到快訊内容頁面\ <br>

  <figure><img src="/files/QZKrWRWj3v8oHfg1al6r" alt=""><figcaption></figcaption></figure>

* 移除原本的内容，替換達錢專用的下單字串\
  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

{% hint style="warning" %}
上方的字串是示範用，請更換成正確的交易帳號才能使用。
{% endhint %}

* 確認内容正確後，點擊【建立】完成快訊設定。<br>

<figure><img src="/files/iTQEpMwhxOvZODt7LbXz" alt=""><figcaption></figcaption></figure>

* 快訊建立成功<br>

  <figure><img src="/files/PDmtvRVaw3Ik2B0zCkHj" alt=""><figcaption></figcaption></figure>

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

{% hint style="danger" %}
啓動【快訊下單】前，請務必確認：

* 交易帳號正確
* 下單商品正確
* 確認實際部位與策略同步，避免部位錯亂
  {% endhint %}

<figure><img src="/files/8f1igQ7Nh7dDDKb43IJQ" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://touchance-1.gitbook.io/touchance/tradingview-kuai-xun-zi-dong-jiao-yi/zi-dong-jiao-yi/pinescript-v6-fan-li-cheng-shi.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
