TOUCHANCE
  • 關於 TOUCHANCE
  • 註冊下載
    • 申請 TOUCHANCE 帳號
    • 安裝 TOUCHANCE
  • TOUCHANCE 基本操作
    • 開始使用
    • 設定
      • 交易連線
      • 報價連線
      • 交易安全設定
      • 系統設定
    • 應用程式
      • 行情總管
      • 交易總管
      • LINE 通知
        • 安裝
        • 設定
          • 申請 LINE Notify 權杖
          • 預設系統通知
          • 交易下單通知
    • 幫助
  • MultiCharts
    • 行情串接
    • 交易串接
      • 下單機設定
      • Symbol Mapping
    • 加值函數
      • 匯入函數
      • MCExtendQuote
        • GetHotChange
        • GetContractsExpire
        • CallPut
        • StrikePrice
        • UnderlyingSymbol
        • GetHotSpread
        • GetHisTick
        • GetRealTimeValue
        • GetRealTimeString
        • GetRealTimeGreeks
      • GV-Plus
        • PutMCDataD
        • GetMCDataD
        • PutMCDataT
        • GetMCDataT
        • SaveMCDB
        • LoadMCDB
        • RemoveMCDB
        • RemoveMCDBall
      • 價差還原 Back-Adjustment
    • 籌碼函數
      • GetChip
    • 自定連續月
      • 安裝
      • 設定
        • 換月日期檔
        • 行情串接
        • 交易串接
  • TradingView 快訊自動交易
    • 簡介
    • 安裝
    • 自動交易
      • 登入 TradingView 會員
      • 設定自動交易
      • 範例程式
      • 快訊設定説明
      • 新增快訊
      • 啓動快訊下單
    • 更新記錄
  • Python API
    • 開始使用
    • 交易串接
      • 下單設定
Powered by GitBook
On this page

Was this helpful?

  1. TradingView 快訊自動交易
  2. 自動交易

範例程式

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 )

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

Previous設定自動交易Next快訊設定説明

Last updated 3 months ago

Was this helpful?