返回帮助中心
藍圖

藍圖節點詳細文件

閱讀 8 min read
風險提示:藍圖節點可以產生自動交易動作,但節點組合本身不保證獲利。實盤前必須先回測,再用模擬交易或小資金驗證。交易所 API 不要開啟提幣權限。

1. 藍圖的基本運作方式

藍圖可以理解為「事件驅動的策略流程圖」。一個可執行藍圖通常由以下幾類節點組成:

  • 事件節點:決定策略何時執行,例如啟動時、每根 K 線、逐筆 Tick、計時器、訂單回執。
  • 行情節點:讀取目前掛載交易對、K 線、最新價、盤口、帳戶和持倉。
  • 指標節點:基於 K 線或數值序列計算技術指標。
  • 信號/邏輯節點:把指標和價格轉換成布林條件,決定是否開倉、平倉或繪圖。
  • 風控節點:為訂單增加限頻、熔斷、最小數量、最大倉位、冷卻、止盈止損等約束。
  • 下單/函式節點:產生開倉、平倉、撤單、退出規則等交易動作。
  • 狀態節點:保存變數、維護計數、持久化狀態、判斷信號變化。
  • 工具節點:做表達式、型別轉換、加減乘除、歸一化、精度處理等中間計算。
  • 圖表節點:把指標線、水平線、背景、標記、表格和訂單標記顯示到圖表上。

一個最常見的策略鏈路如下:

OnBar / OnBarClose
  -> Symbol Selector
  -> Get OHLCV
  -> 指標節點
  -> 信號/邏輯節點
  -> 風控節點
  -> strategy.entry / strategy.close / 下單節點

如果執行週期是 15m,但行情判斷看 1h,通常這樣配置:

event.on_bar(timeframe=15m)
  -> market.symbol_selector
  -> market.get_ohlcv(timeframe=1h, limit=200)
  -> 1h 指標和過濾條件
  -> 15m 執行鏈路

2. 連接埠、連線和參數

每個節點由 輸入連接埠輸出連接埠參數 組成。

概念說明
輸入連接埠接收事件或資料。未連接時,部分節點會使用參數預設值。
輸出連接埠輸出事件、數值、布林、交易對、下單意圖、圖表引用等。
參數在右側屬性面板配置。標記為「暴露」的參數會出現在策略參數面板,掛載時可調整。
multi 輸入允許同一個輸入連接埠接多條連線,常見於 riskInputs、訂單 plotchart.plotchar.shape

流類型

流類型用途常見場景
event控制執行順序和副作用觸發eventIn -> 下單、寫狀態、繪製圖表
data傳遞資料值價格、指標、布林條件、交易對、風控意圖
ui圖表/介面視覺鏈路的歷史類型目前圖表節點多作為末端視覺節點使用

值類型

類型含義常見來源
any任意類型表達式輸入、動態標籤、相容連接埠
voidType無資料事件事件節點的觸發輸出
number / integer / doubleType數值、整數、雙精度指標、價格計算、計數器
boolType布林條件Compare、AND/OR、信號節點
text文字標籤、註解、狀態文字
symbol交易對Symbol Selector
timeframe週期週期過濾
timestamp時間日期過濾、圖表時間區間
seriesNumber數值序列成交量、時間序列
ohlcvSeriesK 線序列Get OHLCV 的 open/high/low/close
chartVisualRef / chartPlotRef / chartHLineRef圖表物件引用Plot、HLine、Fill、訂單標記模板
price價格Last Price、Bid/Ask、Mark Price
orderIntent風控或下單意圖風控節點輸出、下單節點輸入
orderUpdate訂單回執訂單事件節點
position / balance / account倉位、餘額、帳戶快照帳戶/持倉行情節點

編譯和連線規則

  • 藍圖必須至少有一個事件源節點,否則不會執行。
  • 資料流必須是無環圖;如果資料節點互相形成閉環,編譯會失敗。
  • 事件流出現循環時必須放入 logic.gate 做節流,否則可能造成高頻重複觸發。
  • 資料連接埠類型要匹配。類型不匹配時,用 tool.cast_numbertool.cast_integertool.cast_bool 顯式轉換。
  • 普通輸入連接埠只允許一條連線;支援多連線的輸入連接埠會在節點定義裡標記。
  • 下單節點必須接 eventIn,否則事件不觸發時不會執行。
  • 有下單節點時建議至少連接一個風控節點到 riskInputs。編譯器會提示「存在下單節點,但未配置任何風控節點」或「下單節點未連接任何風控輸入」。
  • market.symbol_selector 輸出的是目前回測、掛載或除錯上下文裡的交易對,適合做通用藍圖模板,不建議在模板裡寫死交易對。
  • market.get_ohlcvtimeframe=runtime 表示跟隨執行週期;如果要用大週期過濾,應明確選擇 1h15m 等週期。

3. 高頻策略建立建議

高頻或偏高頻策略要優先控制觸發頻率和訂單頻率:

  • 優先使用 event.on_barevent.on_bar_close 做主觸發;只有明確需要逐筆回應時才使用 event.on_tick
  • 如果使用 event.on_tick 或較短 event.on_timer,下游必須加 logic.gaterisk.max_order_ratelogic.once_per_bar 中的一個或多個。
  • 同一根 K 線不希望重複開倉時,使用 logic.once_per_barstate.last_signal
  • 避免在 Tick 級別反覆拉很大的 K 線數量。market.get_ohlcv.limit 按指標需要設定,常見 100-300 即可。
  • 執行週期和判斷週期可以分離。例如 15m 執行、1h 過濾:事件節點設 15m,行情節點設 1h
  • 實盤鏈路中建議固定接入 risk.kill_switchrisk.order_validationrisk.max_position_sizerisk.max_order_rate
  • 虧損後暫停類策略建議加入 risk.cooldown_after_lossrisk.daily_consecutive_loss_cooldown

4. 事件節點

事件節點是藍圖執行入口。沒有事件節點,行情、指標、邏輯和訂單不會形成執行幀。

節點 ID名稱主要輸入主要輸出參數用途和注意事項
event.on_startOnStartout 觸發策略啟動時觸發一次,適合初始化變數、讀取初始快照。
event.on_stopOnStopenabledout 觸發策略停止時觸發一次,可用於收尾邏輯;未連接 enabled 時按預設啟用處理。
event.on_barOnBartimeframeout 觸發timeframe 預設 1m,可選 1s/1m/5m/15m/1h按指定週期觸發,適合作為預設策略入口。
event.on_bar_openOnBarOpentimeframeout 觸發同 OnBar每根 K 線開盤時觸發,適合開盤執行。
event.on_bar_closeOnBarClosetimeframeout 觸發同 OnBar每根 K 線收盤時觸發,適合用已確認 K 線減少重繪。
event.on_tickOnTickout 觸發逐筆行情觸發,頻率最高;必須搭配限頻和風控。
event.on_timerOnTimerenabledintervalSecout 觸發intervalSec=60,範圍 1-86400 秒固定間隔觸發;輸入連接埠可覆蓋參數。
event.on_order_updateOnOrderUpdatesymbolsidestatus 過濾eventorder訂單/成交回執觸發,適合成交後更新狀態或補充止盈止損。
event.on_trade_transactionOnTradeTransactionsymbolsidestatus 過濾eventorder交易事務更新觸發,適合更細粒度的訂單狀態處理。
event.on_position_updateOnPositionUpdatesymbolside 過濾eventposition持倉變化觸發,適合倉位同步、風險狀態更新。

5. 行情節點

行情節點負責從目前執行上下文讀取交易對、K 線、價格、帳戶和持倉資料。

節點 ID名稱主要輸入主要輸出參數用途和注意事項
market.symbol_selectorSymbol SelectoreventIneventOutsymbol輸出目前掛載或回測交易對,不在藍圖中寫死 symbol。
market.get_ohlcvGet OHLCVsymbolseries/open/high/low/close/hlc3/ohlc4/volume/timelimit=200timeframe=runtime/1m/5m/15m/1h取得最近 N 根 K 線。指標一般接 seriesclose,波動類可接 high/low/close。
market.last_priceGet Last Pricesymbolprice讀取最新成交價,適合即時條件或圖表價位。
market.bid_askGet Bid/Asksymbolbidask讀取買一賣一,適合估算滑點或主動/被動方向。
market.mark_priceGet Mark Pricesymbolprice讀取永續合約標記價格,適合合約風控和強平相關判斷。
market.account_snapshotGet Balance/PositioneventIneventOutbalanceposition讀取帳戶餘額和持倉快照;接事件輸入可控制讀取時機。
market.position_stateGet Position Statesymbolqty/absQty/side/entryPrice/openTimeMs/unrealizedPnl/isFlat輸出目前交易對倉位狀態,常用於「空倉才開倉」「有倉才平倉」。

6. 指標節點

指標節點多數接收 ohlcvSeries,輸出目前 bar 的數值。需要多週期過濾時,把 Get OHLCV.timeframe 設定為目標週期。

節點 ID名稱主要輸入主要輸出關鍵參數適用場景
indicator.smaSMAseriesvalueperiod=20簡單均線,趨勢方向、均值回歸基準。
indicator.emaEMAseriesvalueperiod=21指數均線,反應速度快於 SMA。
indicator.kamaKAMAseriesvalue/previous/slope/trenderPeriod=10fastPeriod=2slowPeriod=30slopeLookback=5自適應均線,適合過濾震盪雜訊。
indicator.rsiRSIseries 或 high/low/closevalueperiod=14超買超賣、動量背離、回調確認。
indicator.atrATRseries 或 high/low/closevalueperiod=14波動率、止損距離、過濾低波動行情。
indicator.atr_medianATR Medianhigh/low/closeatr/medianatrPeriod=14medianPeriod=50判斷目前波動是否高於常態。
indicator.bbBollinger Bandsseriesupper/middle/lowerperiod=20布林帶突破、回歸、帶寬過濾。
indicator.macdMACDseriesmacd/signal/histfastPeriod=12slowPeriod=26signalPeriod=9趨勢動量和零軸過濾。
indicator.donchianDonchianseriesupper/middle/lowerperiod=20區間突破、海龜類策略。
indicator.candle_streakCandle Streakopen/high/low/closebullStreak/bearStreak/bullMoveAtr/bearMoveAtr/bodyAtr/directionatrPeriod=14minBodyPct=0.00005連續陽線/陰線和實體強度過濾,防追漲殺跌。
indicator.adxADXseries 或 high/low/closevalueperiod=14趨勢強度過濾,常用閾值 20/25。
indicator.chopCHOPseries 或 high/low/closevalueperiod=14識別趨勢/震盪,值高偏震盪,值低偏趨勢。
indicator.vwapVWAPseriesvalueperiod=20成交量加權均價,適合日內價格偏離判斷。
indicator.stochStochseriesk/dperiod=14smoothK=3smoothD=3隨機指標,震盪市場入場/離場。
indicator.stoch_rsiStochastic RSIseriesk/dperiod=14smoothK=3smoothD=3對 RSI 再隨機化,信號更敏感。
indicator.highestHighest Nseriesvalueperiod=20最近 N 根最高值,突破閾值。
indicator.lowestLowest Nseriesvalueperiod=20最近 N 根最低值,跌破閾值。
indicator.ichimokuIchimokuseriesconversion/base/spanA/spanB/laggingconversionPeriod=9basePeriod=26spanBPeriod=52displacement=26一目均衡表,多維趨勢結構。
indicator.supertrendSupertrendseriesvalue/trendperiod=10multiplier=3.0趨勢跟蹤和止損參考。
indicator.fibonacciFibonacci Retracementserieslevel0/236/382/500/618/786/100period=100近期區間斐波那契回撤位。
indicator.cciCCIseriesvalueperiod=20順勢指標,趨勢和極值判斷。
indicator.williams_rWilliams %Rseriesvalueperiod=14超買超賣振盪器。
indicator.parabolic_sarParabolic SARseriesvalue/trendafStart=0.02afStep=0.02afMax=0.2趨勢反轉和移動止損。
indicator.obvOBVseriesvalue能量潮,價格與成交量方向確認。
indicator.mfiMFIseriesvalueperiod=14資金流量指標,帶成交量的超買超賣。
indicator.volumeVolumeseriesNumbervalue/averageperiod=20目前量與均量對比,可過濾假突破。
indicator.keltnerKeltner Channelsseriesupper/middle/loweremaPeriod=20atrPeriod=10multiplier=2.0基於 ATR 的通道突破和回調。
indicator.rocROCseriesvalueperiod=12變動率,判斷價格速度。
indicator.momentumMomentumseriesvalueperiod=10動量振盪器。
indicator.smoothed_momentumSmoothed Momentumseriesmomentum/value/bull/bearperiod=10smooth=3平滑動量,並直接輸出多空布林。
indicator.wavetrendWaveTrendserieswt1/wt2/bull/bear/crossOver/crossUnderchannelLength=9averageLength=12maLength=3overbought=60oversold=-60振盪器和交叉信號,適合回調確認。
indicator.aroonAroonseriesup/down/oscillatorperiod=25識別新高/新低驅動的趨勢強弱。
indicator.cmfCMFseriesvalueperiod=20Chaikin Money Flow,資金流入/流出過濾。
indicator.pivot_pointsPivot Pointsseriespp/r1/r2/r3/s1/s2/s3period=20支撐阻力、突破和回撤目標。

7. 信號和邏輯節點

信號節點通常輸出布林值,邏輯節點可以組合條件或控制事件流。

節點 ID名稱主要輸入主要輸出參數用途和注意事項
logic.compareCompareleft/rightresultoperator 可選 > = true 時放行事件,避免條件持續為 true 時重複下單。
logic.if_elseIf-ElseeventIn/conditiontrueOut/falseOut按條件拆分事件流。
bool.expressionBool Expression動態變數輸入resultexpressionvariableCount、變數別名用表達式替代多級 Compare/AND/OR/NOT,支援 and/or/not、`&&/
logic.bool_exprBool Expra/b/c/dresultexpression舊版布林表達式,變數固定為 a-d。
logic.ternarySelect / Ternary動態變數輸入resultexpression、變數別名三元表達式,例如 a ? b : c,適合顏色、數值、文字二選一。
logic.select_valueSelect Valuecondition/trueValue/falseValueresult按布林條件在兩個值中選擇一個。
logic.gateGateeventIneventOutcooldownSec=10事件流限流;高頻、Tick、循環事件必須重點使用。
logic.once_per_barOnce Per BareventIneventOut同一根 K 線只放行一次事件。

表達式節點說明:

  • bool.expressionmath.expressiontool.number_expr 支援動態變數數量,variableCount 範圍為 1-32。
  • 變數預設是 a/b/c...,可以用變數別名改成 closeemaFastatr 等更易讀的名字。
  • 布林表達式適合寫 `close > ema and rsi 下單節點 riskInputs

## 9. 函式節點和下單節點

函式節點是 Pine Script 風格的交易函式,會輸出 `eventOut`、`triggered` 和 `label`,適合在策略鏈路中繼續串聯。下單節點更像終端動作節點,通常作為交易動作的末端。

### 函式節點

| 節點 ID                 | 名稱                | 主要輸入                                | 主要輸出                     | 關鍵參數                                                                                                      | 用途和注意事項                                                                      |
| ----------------------- | ------------------- | --------------------------------------- | ---------------------------- | ------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------- |
| `strategy.entry`      | strategy.entry      | `eventIn/when/symbol/riskInputs/plot` | `eventOut/triggered/label` | `enabled`、`entryId`、`direction`、`orderType`、`qtyMode`、`qty`、`limitOffsetPct`、`comment` | 滿足 `when` 時產生多頭或空頭入場意圖。`entryId` 是策略標籤,不是交易所訂單 ID。 |
| `strategy.cancel`     | strategy.cancel     | `eventIn/when/riskInputs/plot`        | `eventOut/triggered/label` | `enabled`、`orderId`、`comment`                                                                         | 撤銷指定交易所委託;live 撤單通常需要真實 `orderId`。                             |
| `strategy.close`      | strategy.close      | `eventIn/when/symbol/riskInputs/plot` | `eventOut/triggered/label` | `enabled`、`entryId`、`orderType`、`qtyMode`、`qty`、`limitOffsetPct`、`comment`                | 平目前交易對倉位,可按全部、數量或百分比平倉。                                      |
| `strategy.cancel_all` | strategy.cancel_all | `eventIn/when/riskInputs/plot`        | `eventOut/triggered/label` | `enabled`、`comment`                                                                                      | 滿足條件時產生全部撤單意圖。                                                        |
| `strategy.close_all`  | strategy.close_all  | `eventIn/when/symbol/riskInputs/plot` | `eventOut/triggered/label` | `enabled`、`orderType`、`limitOffsetPct`、`comment`                                                   | 滿足條件時對目前交易對執行全平。                                                    |
| `strategy.exit`       | strategy.exit       | `eventIn/when/symbol/riskInputs/plot` | `eventOut/triggered/label` | `exitId`、`fromEntry`、`stop`、`limit`、`profit`、`loss`、`trailPoints`、`trailOffset`        | Pine 風格退出規則,可配置止盈、止損、追蹤止損。                                     |

### 下單節點

| 節點 ID                  | 名稱                 | 主要輸入                                                        | 輸出 | 關鍵參數                                                                                          | 用途和注意事項                                                               |
| ------------------------ | -------------------- | --------------------------------------------------------------- | ---- | ------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------- |
| `strategy.entry_block` | Strategy Entry Block | `eventIn/longCondition/shortCondition/symbol/riskInputs/plot` | 無   | `orderType`、`qtyMode`、`qty`、`preferLongWhenBoth`、`longLabel`、`shortLabel`        | 策略級入場塊,同時接多空條件;兩邊同時觸發時可配置優先多頭。                 |
| `strategy.exit_block`  | Strategy Exit Block  | `eventIn/longCondition/shortCondition/symbol/riskInputs/plot` | 無   | `orderType`、`qtyMode`、`qty`、`longLabel`、`shortLabel`                                | 策略級出場塊,直接根據多/空退出條件產生平倉意圖。                            |
| `order.place_market`   | Place Market Order   | `eventIn/sideInput/riskInputs/plot`                           | 無   | `side=buy/sell/auto`、`qtyMode=fixed/percent/quantity`、`qty`                               | 產生市價單意圖。`qty` 目前按 USDT 金額解釋,`percent` 按可用資金百分比。 |
| `order.place_limit`    | Place Limit Order    | `eventIn/sideInput/riskInputs/plot`                           | 無   | `side`、`qtyMode`、`qty`、`priceOffsetPct`                                                | 產生限價單意圖;BUY 向下偏移,SELL 向上偏移。                                |
| `order.cancel_order`   | Cancel Order         | `eventIn/riskInputs/plot`                                     | 無   | `orderId`                                                                                       | 撤銷指定交易所委託。                                                         |
| `order.close_position` | Close Position       | `eventIn/riskInputs/plot`                                     | 無   | `qtyMode=all/quantity/percent`、`qty`、`orderType`、`priceOffsetPct`、`reduceOnly=true` | 平目前倉位;預設僅減倉。                                                     |
| `order.set_tpsl`       | Set TP/SL            | `eventIn/riskInputs/plot`                                     | 無   | `stopLossPct=1.0`、`takeProfitPct=2.0`                                                        | 為倉位或訂單設定止盈止損意圖。                                               |

下單鏈路範例:

OnBarClose(15m).out

-> Edge Trigger.eventIn

Compare.result

-> Edge Trigger.condition

Edge Trigger.eventOut

-> strategy.entry.eventIn

Symbol Selector.symbol

-> strategy.entry.symbol

risk.max_order_rate.intent

risk.max_position_size.intent

risk.stop_take_rule.intent

-> strategy.entry.riskInputs


## 10. 狀態節點

狀態節點用於記憶目前執行過程中的變數和信號。需要跨重啟保留時,用 `persistent_*`。

| 節點 ID                  | 名稱              | 主要輸入                | 主要輸出                           | 參數                              | 用途和注意事項                                   |
| ------------------------ | ----------------- | ----------------------- | ---------------------------------- | --------------------------------- | ------------------------------------------------ |
| `state.var_set`        | Var Set           | `value`               | `value`                          | `key=signal`                    | 設定目前策略變數,生命週期通常跟隨執行實例。     |
| `state.var_get`        | Var Get           | 無                      | `value`                          | `key=signal`                    | 讀取目前策略變數。                               |
| `state.counter`        | Counter           | `eventIn`             | `value/eventOut`                 | `initialValue=0`、`step=1`    | 每次事件觸發時計數,適合統計觸發次數。           |
| `state.persistent_set` | Persistent KV Set | `eventIn/value`       | `value/eventOut`                 | `key=last_signal`               | 寫入跨重啟持久化變數。                           |
| `state.persistent_get` | Persistent KV Get | 無                      | `value`                          | `key=last_signal`、`fallback` | 讀取跨重啟變數;不存在時返回預設值。             |
| `state.rolling_window` | Rolling Window    | `eventIn/value`       | `values/latest/count/eventOut`   | `size=20`                       | 維護最近 N 個數值窗口。                          |
| `state.last_signal`    | Last Signal       | `eventIn/signal`      | `signal/changed/eventOut`        | `key=signal`                    | 保存上次信號,並輸出是否變化;適合避免重複下單。 |
| `state.overbought`     | Overbought State  | `value/threshold`     | `result`                         | `threshold=70`                  | 指標值大於等於閾值。                             |
| `state.oversold`       | Oversold State    | `value/threshold`     | `result`                         | `threshold=30`                  | 指標值小於等於閾值。                             |
| `state.midline`        | Midline State     | `value/threshold`     | `result`                         | `threshold=50`                  | 指標值大於等於中線閾值。                         |
| `strategy.trend_state` | Trend State       | `changeUp/changeDown` | `state/stateCode/isLong/isShort` | `longCode=B`、`shortCode=S`   | 也屬於狀態類節點,用於根據切換信號維護趨勢狀態。 |

## 11. 工具節點

工具節點負責中間計算和格式處理。複雜計算優先用表達式節點,簡單計算可用加減乘除節點。

| 節點 ID               | 名稱            | 主要輸入     | 主要輸出      | 參數                                        | 用途和注意事項                                |
| --------------------- | --------------- | ------------ | ------------- | ------------------------------------------- | --------------------------------------------- |
| `math.expression`   | Math Expression | 動態變數輸入 | `value`     | `expression`、`variableCount`、變數別名 | 數值表達式,支援 `+ - * / %` 和括號。       |
| `tool.number_expr`  | Number Expr     | 動態變數輸入 | `value`     | `expression`、`variableCount`、變數別名 | 舊版數值表達式,適合替代 Add/Sub/Mul/Div 鏈。 |
| `tool.cast_number`  | Cast -> Number  | `value`    | `value`     | 無                                          | 顯式轉換為數值。                              |
| `tool.cast_integer` | Cast -> Int     | `value`    | `value`     | 無                                          | 顯式轉換為整數。                              |
| `tool.cast_bool`    | Cast -> Bool    | `value`    | `value`     | 無                                          | 顯式轉換為布林。                              |
| `tool.clamp`        | Clamp           | `value`    | `value`     | `min=0`、`max=100`                      | 把數值限制在區間內。                          |
| `tool.normalize`    | Normalize       | `value`    | `value`     | `min=0`、`max=100`                      | 把數值歸一化到 0-1。                          |
| `tool.add`          | Add             | `a/b`      | `value`     | 無                                          | 加法。                                        |
| `tool.sub`          | Sub             | `a/b`      | `value`     | 無                                          | 減法。                                        |
| `tool.mul`          | Mul             | `a/b`      | `value`     | 無                                          | 乘法。                                        |
| `tool.div`          | Div             | `a/b`      | `value`     | 無                                          | 除法。                                        |
| `tool.map_symbol`   | Map Symbol      | `symbol`   | `symbol`    | `exchange=binance/okx/bybit`              | 把交易對映射到目標交易所格式。                |
| `tool.tag`          | JSON/Tag        | `value`    | `value/tag` | `tag`                                     | 給資料附加文字標籤或 JSON 片段。              |
| `tool.round`        | Round/Precision | `value`    | `value`     | `precision=2`                             | 數值精度處理,適合價格、數量和圖表展示。      |

## 12. 圖表節點

圖表節點用於視覺化策略。部分節點接 `eventIn` 控制目前 bar 是否繪製,部分節點是純資料驅動。圖表節點通常不參與下單決策,建議作為策略鏈路的旁路輸出。

### 通用圖表參數

| 參數            | 說明                                                                                                          |
| --------------- | ------------------------------------------------------------------------------------------------------------- |
| `pane`        | 顯示區域:`main` 主圖、`chart` 圖表層、`volume` 成交量、`indicator:0/1` 指標面板。                    |
| `visible`     | 是否顯示。                                                                                                    |
| `zIndex`      | 層級,範圍 -200 到 200,越大越靠上。                                                                          |
| `layer`       | 渲染層:`background`、`underlay`、`overlay`、`annotation`。                                           |
| `style`       | Plot 樣式:`line`、`linebr`、`stepline`、`area`、`histogram`、`columns`、`circles`、`cross`。 |
| `strokeStyle` | 線型:`solid`、`dashed`、`dotted`。                                                                     |

### 圖表節點索引

| 節點 ID                      | 名稱            | 主要輸入                                                | 主要輸出     | 關鍵參數                                                                                     | 用途和注意事項                                               |
| ---------------------------- | --------------- | ------------------------------------------------------- | ------------ | -------------------------------------------------------------------------------------------- | ------------------------------------------------------------ |
| `chart.color`              | Color           | 無                                                      | `color`    | `color=#FF38BDF8`                                                                          | 輸出顏色文字,可複用到多個圖表節點。                         |
| `chart.background`         | Background      | `eventIn/color/startValue/endValue/startTime/endTime` | 無           | `color`、`rangeMode=bars/time`、`startBarsAgo/endBarsAgo`                              | 繪製背景區域,可按 K 線區間或時間區間控制。                  |
| `chart.bar_color`          | Bar Color       | `eventIn`                                             | 無           | `colorMode=single/trend/theme`、body/wick/border/up/down 顏色                              | 修改 K 線顏色,適合趨勢狀態視覺化。                          |
| `chart.plots`              | Plot            | `color/value`                                         | `plotRef`  | `style`、`color`、`lineWidth`、`histBase`、`offset`、`showLast`、`trackPrice`  | 繪製指標線、柱狀圖、面積等,並輸出 Plot 引用。               |
| `strategy.plot_trend_line` | Plot Trend Line | `value/trend`                                         | `plotRef`  | `style`、`upColor`、`downColor`、`neutralColor`、`lineWidth`                       | 按趨勢狀態自動切換顏色的指標線。                             |
| `chart.fill`               | Fill            | `color/plot1/plot2`                                   | 無           | `color`、`showLast`、`fillGaps`                                                        | 在兩條 Plot/HLine 引用之間填充區域。兩個引用必須在同一面板。 |
| `chart.hline`              | HLine           | `price/color/startValue/endValue/startTime/endTime`   | `hlineRef` | `price`、`title`、`color`、`linestyle`、`linewidth`、`rangeMode`                 | 繪製水平線,並可作為 Fill 引用。                             |
| `chart.levels`             | Levels          | `value/color`                                         | 無           | `value`、`color`、`lineWidth`、`strokeStyle`、`label`、區間參數                    | 繪製價位線,適合支撐阻力、止盈止損參考。                     |
| `chart.line`               | Line            | `startValue/endValue`                                 | 無           | `lineColor`、`lineWidth`、`strokeStyle`、`leftBarsAgo/rightBarsAgo`                  | 繪製從歷史 bar 到目前或未來偏移的線段。                      |
| `chart.box`                | Box             | `top/bottom/text`                                     | 無           | `fillColor`、`borderColor`、`textColor`、`borderWidth`、`leftBarsAgo/rightBarsAgo` | 繪製價格區間盒,適合震盪區間、供需區。                       |
| `chart.tables`             | Tables          | `eventIn` 和動態 `value1...valueN`                  | 無           | `title`、`placement`、`itemCount=1-12`、`labelPosition`、`columnCount`、顏色和對齊 | 顯示圖表看板。`itemCount` 會動態展開輸入連接埠和標籤參數。 |
| `chart.text`               | Text            | `value`                                               | `text`     | `color`、`textFallback`、`size`、`barsAgo`                                           | 輸出文字。連接值時按「文字 + 值」拼接。                      |
| `chart.shapes`             | Shapes          | `value/series/text`                                   | `shape`    | `shape`、`location=abovebar/belowbar/absolute`、顏色、尺寸、offset                       | 繪製形狀標記;`series` 為 false 時通常不繪製。             |
| `chart.plotchar`           | PlotChar        | `series/value/text/shape`                             | 無           | `location`、`value`、`color`、`offset`、`yOffset`                                  | 按條件繪製文字或形狀標記;`shape` 支援多連接。             |
| `chart.entry_plot`         | Entry Plot      | 無                                                      | `plotRef`  | `shape=arrow_right_sharp`、`size`、`textSize`                                          | 輸出開倉圖表模板,真正繪製發生在訂單成交時。                 |
| `chart.exit_plot`          | Exit Plot       | 無                                                      | `plotRef`  | `shape=arrow_left_sharp`、`size`、`textSize`                                           | 輸出平倉圖表模板,真正繪製發生在訂單成交時。                 |

常見圖表用法:

EMA.value -> chart.plots.value

RSI.value -> chart.tables.value1

Entry Plot.plotRef -> strategy.entry.plot

Exit Plot.plotRef -> strategy.close.plot


## 13. 常見策略模板

### 15m 執行,1h 趨勢過濾

event.on_bar_close(timeframe=15m)

-> market.symbol_selector.eventIn

market.symbol_selector.symbol

-> market.get_ohlcv.symbol

market.get_ohlcv(timeframe=1h).close

-> indicator.ema(period=50)

market.get_ohlcv(timeframe=1h).close

-> indicator.ema(period=200)

EMA50.value > EMA200.value

-> logic.compare.result

logic.compare.result

-> strategy.entry.when

event.on_bar_close.out

-> logic.edge_trigger.eventIn

logic.compare.result

-> logic.edge_trigger.condition

logic.edge_trigger.eventOut

-> strategy.entry.eventIn


### 突破入場,加 ATR 風控

Get OHLCV.close -> indicator.donchian.series

Last Price.price -> signal.breakout.value

Donchian.upper -> signal.breakout.level

Get OHLCV -> indicator.atr

ATR.value -> strategy.atr_stop_block.atr

risk.max_order_rate.intent

risk.order_validation.intent

strategy.atr_stop_block.intent

-> strategy.entry.riskInputs


### 防止同一信號重複下單

Compare.result -> state.last_signal.signal

OnBar.out -> state.last_signal.eventIn

state.last_signal.changed -> strategy.entry.when

state.last_signal.eventOut -> strategy.entry.eventIn


## 14. 排錯指南

| 問題            | 優先檢查                                                                                                      |
| --------------- | ------------------------------------------------------------------------------------------------------------- |
| 藍圖無法編譯    | 是否有事件源;連接埠類型是否匹配;資料流是否成環;輸入連接埠是否重複連線。                                    |
| 策略不觸發      | 事件週期是否正確;`when` 是否為 true;`Edge Trigger` 是否已經觸發過;日期過濾是否過期。                   |
| 下單節點不執行  | 是否接了 `eventIn`;是否連接 `riskInputs`;風控是否拒絕;執行模式是否允許交易。                           |
| 高頻重複下單    | 增加 `logic.gate`、`logic.once_per_bar`、`state.last_signal`、`risk.max_order_rate`。                 |
| 1h 過濾沒有生效 | 檢查 `market.get_ohlcv.timeframe` 是否明確設定為 `1h`,不要誤用 `runtime`。                             |
| 指標為空或異常  | `limit` 是否足夠覆蓋指標週期;輸入是否接了正確序列;回測區間是否有足夠歷史 K 線。                           |
| 圖表不顯示      | 圖表節點是否有必要輸入;`visible` 是否開啟;`pane/layer/zIndex` 是否合理;Fill 的兩個引用是否在同一面板。 |
| 類型不匹配      | 插入 `tool.cast_number`、`tool.cast_integer` 或 `tool.cast_bool`。                                      |

## 15. 完整節點 ID 索引

以下索引用於快速核對藍圖檔案中的 `schemaId`。

| 分類 | 節點 ID                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| ---- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| 事件 | `event.on_start`, `event.on_stop`, `event.on_bar`, `event.on_bar_open`, `event.on_bar_close`, `event.on_tick`, `event.on_timer`, `event.on_order_update`, `event.on_trade_transaction`, `event.on_position_update`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| 行情 | `market.symbol_selector`, `market.get_ohlcv`, `market.last_price`, `market.bid_ask`, `market.mark_price`, `market.account_snapshot`, `market.position_state`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| 指標 | `indicator.sma`, `indicator.ema`, `indicator.kama`, `indicator.rsi`, `indicator.atr`, `indicator.atr_median`, `indicator.bb`, `indicator.macd`, `indicator.donchian`, `indicator.candle_streak`, `indicator.adx`, `indicator.chop`, `indicator.vwap`, `indicator.stoch`, `indicator.stoch_rsi`, `indicator.highest`, `indicator.lowest`, `indicator.ichimoku`, `indicator.supertrend`, `indicator.fibonacci`, `indicator.cci`, `indicator.williams_r`, `indicator.parabolic_sar`, `indicator.obv`, `indicator.mfi`, `indicator.volume`, `indicator.keltner`, `indicator.roc`, `indicator.momentum`, `indicator.smoothed_momentum`, `indicator.wavetrend`, `indicator.aroon`, `indicator.cmf`, `indicator.pivot_points` |
| 信號 | `logic.cross_over`, `logic.cross_under`, `signal.enter_range`, `signal.leave_range`, `signal.breakout`, `signal.breakdown`, `strategy.date_range_filter`, `strategy.cross_signal`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| 邏輯 | `logic.compare`, `logic.boolean_and`, `logic.boolean_or`, `logic.boolean_not`, `logic.edge_trigger`, `logic.if_else`, `bool.expression`, `logic.bool_expr`, `logic.ternary`, `logic.select_value`, `logic.gate`, `logic.once_per_bar`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| 風控 | `risk.max_order_rate`, `risk.kill_switch`, `risk.order_validation`, `risk.max_position_size`, `risk.cooldown_after_loss`, `risk.daily_consecutive_loss_cooldown`, `risk.stop_take_rule`, `strategy.atr_stop_block`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| 函式 | `strategy.entry`, `strategy.cancel`, `strategy.close`, `strategy.cancel_all`, `strategy.close_all`, `strategy.exit`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
| 下單 | `strategy.entry_block`, `strategy.exit_block`, `order.place_market`, `order.place_limit`, `order.cancel_order`, `order.close_position`, `order.set_tpsl`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| 狀態 | `strategy.trend_state`, `state.var_set`, `state.var_get`, `state.counter`, `state.persistent_set`, `state.persistent_get`, `state.rolling_window`, `state.last_signal`, `state.overbought`, `state.oversold`, `state.midline`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| 工具 | `math.expression`, `tool.number_expr`, `tool.cast_number`, `tool.cast_integer`, `tool.cast_bool`, `tool.clamp`, `tool.normalize`, `tool.add`, `tool.sub`, `tool.mul`, `tool.div`, `tool.map_symbol`, `tool.tag`, `tool.round`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| 圖表 | `chart.color`, `chart.background`, `chart.bar_color`, `chart.plots`, `strategy.plot_trend_line`, `chart.fill`, `chart.hline`, `chart.levels`, `chart.line`, `chart.box`, `chart.tables`, `chart.text`, `chart.shapes`, `chart.plotchar`, `chart.entry_plot`, `chart.exit_plot                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |

藍圖

新手工作台行情

相关文档

藍圖節點詳細文件 | NavaX