AlertaScript / 文件
第一個策略
測試移動平均交叉規則。
運作方式
strategy 啟用模擬訂單。範例在向上交叉時進場,反向交叉時平掉相同進場 ID。
實際應用
在策略測試器檢查逐筆交易、數量與費用。程式不會自動向交易所送出真實訂單。
程式範例
EMA(10) 向上穿越 EMA(30) 時開啟 Long,向下穿越時平倉。比較的是兩條均線,不是價格。沒有明確的 barstate.isconfirmed 條件。計算與模擬成交依策略執行設定而定;程式不會自動訂閱通知或送出實盤委託。
AlertaScript
strategy("EMA cross", overlay=true)fast = ta.ema(close, 10)slow = ta.ema(close, 30)if ta.crossover(fast, slow) strategy.entry("Long", strategy.long)if ta.crossunder(fast, slow) strategy.close("Long")plot(fast, "Fast")plot(slow, "Slow")