範例程式
TradingView 内建許多的交易策略,我們利用下面的簡單範例來説明如何設定。
均線交叉範例程式
// 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 )
你可以直接複製後,套用到你的圖表,結果如下:
Last updated
Was this helpful?