# PineScript v5 範例程式

均線交叉範例程式

```
// 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=5
//@strategy_alert_message {{strategy.order.alert_message}}

strategy( "MA_CROSS_OVER_ENTRY", initial_capital = 100000, overlay = true, default_qty_value = 1 )
import TradingView/ta/5

SN = input("stg_name", "strategy id")
ta = input("Branch-Account", "Trading Account")
ts = input("TC.F.TWF.TMF.HOT", "Trading Symbol")

sma_length = input( 5, "sma Length")
lma_length = input( 15, "lma Length")
sma = ta.sma( close, sma_length )
lma = ta.sma( close, lma_length )

alertEntryMessage = "TOTC.{{timenow}}@account="+ ta +",sym="+ ts +",side={{strategy.order.action}},qty={{strategy.order.contracts}},p={{strategy.order.price}},ordertype=1,tif=2,ts={{timenow}},tvorderID="+ SN
if ta.crossover( sma, lma )
    strategy.entry("EL", strategy.long, alert_message=alertEntryMessage )

alertExitMessage = "TOTC.{{timenow}}@account="+ ta +",sym="+ ts +",side={{strategy.order.action}},qty={{strategy.order.contracts}},p={{strategy.order.price}},ordertype=1,tif=2,ts={{timenow}},tvorderID="+ SN
if ta.crossunder( sma, lma )
    strategy.close("EL", comment="Exit Long" , alert_message=alertExitMessage )
```

你可以直接複製後，套用到你的圖表，結果如下：

<figure><img src="/files/MievzMeZBeCrIgd4McrQ" 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-v5-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.
