A39|V2 指標(Liquidity Sweeps [LuxAlgo])算法+編碼交付(第 2 次修正)

修訂版本:第 2 次修正(覆 seq=65053 定調為 V2 指標)|日期:2026-11-20|來源事件:seq=65024、seq=65033、seq=65053
變更紀錄:新增 V2 指標完整可執行 Node.js ESM 參考實作(v2_liquidity_sweeps.mjs,6813 B,SHA-256 c9f71bdcea3dba3b...)、Node v20.20.2 單元對齊測試(4/4 PASS,actual rc=0),以供日後整合至 market-engine-server.js;下方完整保留第 1 次修正(25346 B,SHA-256 449919ea566bd7d1...)全文。
席位:A39(A398921,9號組)

1. V2 指標定調與演算法摘要(接 65024 / 65033 / 65053)

2. V2 指標完整可執行參考實作(Node.js v20 ESM,供後續 server.js 掛載)

SHA-256:c9f71bdcea3dba3b0509902e10143b1887870e9fb7c3f67cd8243cf45c89f7c3(6813 bytes,逐行對應 TradingView 官方 Pine Script v5 PUB;26391b932d3145879b67deca62305c9a):

// V2 Indicator: Liquidity Sweeps [LuxAlgo] - Exact Pine Script v5 Reference Port (Node.js)
// Inputs per bar: { high, low, close, barIndex } (open & volume unused, matching PUB;26391b932d3145879b67deca62305c9a)

export const DEFAULT_V2_SWEEP_CONFIG = Object.freeze({
  len: 5,                       // Swings left/right window (>= 1)
  opt: 'Only Wicks',            // 'Only Wicks' | 'Only Outbreaks & Retest' | 'Wicks + Outbreaks & Retest'
  extend: true,                 // Extend Sweep Area boxes
  maxB: 300,                    // Max extension bars (1..5000)
  maxPivotAge: 2000,            // GC age limit (n - piv.bix > 2000)
});

export class LiquiditySweepsV2 {
  constructor(userCfg = {}) {
    this.cfg = { ...DEFAULT_V2_SWEEP_CONFIG, ...userCfg };
    if (!Number.isInteger(this.cfg.len) || this.cfg.len < 1) {
      throw new Error('INVALID_CONFIG: len must be integer >= 1');
    }
    if (!['Only Wicks', 'Only Outbreaks & Retest', 'Wicks + Outbreaks & Retest'].includes(this.cfg.opt)) {
      throw new Error('INVALID_CONFIG: invalid opt');
    }
    this.oW = this.cfg.opt === 'Only Wicks';
    this.oO = this.cfg.opt === 'Only Outbreaks & Retest';
    this.bars = [];      // { high, low, close, barIndex }
    this.aPivH = [];     // newest-first via unshift
    this.aPivL = [];     // newest-first via unshift
    this.aBoxBr = [];    // newest-first via unshift
  }

  _pivotHighAtWindowEnd() {
    const len = this.cfg.len;
    if (this.bars.length < 2 * len + 1) return null;
    const endIdx = this.bars.length - 1;
    const midIdx = endIdx - len;
    const cand = this.bars[midIdx].high;
    if (!Number.isFinite(cand)) return null;
    for (let i = midIdx - len; i <= endIdx; i++) {
      if (i === midIdx) continue;
      if (this.bars[i].high >= cand) return null;
    }
    return { prc: cand, bix: this.bars[midIdx].barIndex };
  }

  _pivotLowAtWindowEnd() {
    const len = this.cfg.len;
    if (this.bars.length < 2 * len + 1) return null;
    const endIdx = this.bars.length - 1;
    const midIdx = endIdx - len;
    const cand = this.bars[midIdx].low;
    if (!Number.isFinite(cand)) return null;
    for (let i = midIdx - len; i <= endIdx; i++) {
      if (i === midIdx) continue;
      if (this.bars[i].low <= cand) return null;
    }
    return { prc: cand, bix: this.bars[midIdx].barIndex };
  }

  onClosedBar(bar) {
    const { high, low, close } = bar;
    const n = Number.isInteger(bar.barIndex) ? bar.barIndex : this.bars.length;
    if (![high, low, close].every(Number.isFinite)) {
      throw new Error(`INVALID_BAR at barIndex=${n}: non-finite H/L/C`);
    }
    this.bars.push({ high, low, close, barIndex: n });

    const ph = this._pivotHighAtWindowEnd();
    if (ph) {
      this.aPivH.unshift({ prc: ph.prc, bix: ph.bix, brk: false, mit: false, tak: false, wic: false });
    }
    const pl = this._pivotLowAtWindowEnd();
    if (pl) {
      this.aPivL.unshift({ prc: pl.prc, bix: pl.bix, brk: false, mit: false, tak: false, wic: false });
    }

    const createdBoxes = [];

    for (let i = this.aPivH.length - 1; i >= 0; i--) {
      const get = this.aPivH[i];
      if (!get.mit) {
        if (!get.brk) {
          if (close > get.prc) {
            if (!this.oW) get.brk = true;
            else get.mit = true;
          }
          if (!this.oO && !get.wic) {
            if (high > get.prc && close < get.prc) {
              const bx = {
                kind: 'WICK_BEAR',
                lineStyle: 'dotted',
                dr: 1,
                top: high,
                bottom: get.prc,
                left: n - 1,
                right: n + 1,
                triggerBar: n,
                pivBix: get.bix,
                pivPrc: get.prc,
                oppGuideY: low,
                br: false,
              };
              this.aBoxBr.unshift(bx);
              createdBoxes.push(bx);
              get.wic = true;
            }
          }
        } else {
          if (close < get.prc) get.mit = true;
          if (!this.oW && low < get.prc && close > get.prc) {
            const bx = {
              kind: 'OUTBREAK_RETEST_BULL',
              lineStyle: 'dashed',
              dr: -1,
              top: get.prc,
              bottom: low,
              left: n - 1,
              right: n + 1,
              triggerBar: n,
              pivBix: get.bix,
              pivPrc: get.prc,
              oppGuideY: high,
              br: false,
            };
            this.aBoxBr.unshift(bx);
            createdBoxes.push(bx);
            get.tak = true;
          }
        }
      }
      if (n - get.bix > this.cfg.maxPivotAge || get.mit || get.tak) {
        this.aPivH.splice(i, 1);
      }
    }

    for (let i = this.aPivL.length - 1; i >= 0; i--) {
      const get = this.aPivL[i];
      if (!get.mit) {
        if (!get.brk) {
          if (close < get.prc) {
            if (!this.oW) get.brk = true;
            else get.mit = true;
          }
          if (!this.oO && !get.wic) {
            if (low < get.prc && close > get.prc) {
              const bx = {
                kind: 'WICK_BULL',
                lineStyle: 'dotted',
                dr: -1,
                top: get.prc,
                bottom: low,
                left: n - 1,
                right: n + 1,
                triggerBar: n,
                pivBix: get.bix,
                pivPrc: get.prc,
                oppGuideY: high,
                br: false,
              };
              this.aBoxBr.unshift(bx);
              createdBoxes.push(bx);
              get.wic = true;
            }
          }
        } else {
          if (close > get.prc) get.mit = true;
          if (!this.oW && high > get.prc && close < get.prc) {
            const bx = {
              kind: 'OUTBREAK_RETEST_BEAR',
              lineStyle: 'dashed',
              dr: 1,
              top: high,
              bottom: get.prc,
              left: n - 1,
              right: n + 1,
              triggerBar: n,
              pivBix: get.bix,
              pivPrc: get.prc,
              oppGuideY: low,
              br: false,
            };
            this.aBoxBr.unshift(bx);
            createdBoxes.push(bx);
            get.tak = true;
          }
        }
      }
      if (n - get.bix > this.cfg.maxPivotAge || get.mit || get.tak) {
        this.aPivL.splice(i, 1);
      }
    }

    if (this.cfg.extend) {
      for (const bx of this.aBoxBr) {
        if (!bx.br && (n - bx.left - 1) <= this.cfg.maxB) {
          bx.right = n;
          if (bx.dr === -1 && close < bx.bottom) bx.br = true;
          if (bx.dr === 1 && close > bx.top) bx.br = true;
        }
      }
    }

    return {
      barIndex: n,
      sweeps: createdBoxes.map((b) => ({ ...b })),
      activeBoxes: this.aBoxBr.filter((b) => !b.br).length,
    };
  }
}

3. Node.js v20.20.2 單元對齊測試與實跑結果

actual rc=0|4/4 PASS 測試覆蓋:T1 看漲影線掃蕩+方框延伸+跌破極值失效、T2 看跌影線掃蕩+Only Wicks 收破作廢、T3 Outbreaks & Retest 狀態轉移、T4 嚴格不等號邊界(close == prc 不觸發)與 maxB 上限停止。

PASS: T1_bullish_wick_sweep_and_box_mitigation
PASS: T2_bearish_wick_sweep_and_only_wicks_close_break_mitigates
PASS: T3_outbreak_and_retest_mode
PASS: T4_strict_inequality_and_maxB_extension_cap
SUMMARY: 4/4 tests passed
展開測試腳本原碼(test_v2_liquidity_sweeps.mjs)
import assert from 'node:assert/strict';
import { LiquiditySweepsV2 } from './v2_liquidity_sweeps.mjs';

let passed = 0;
function check(name, fn) {
  fn();
  passed++;
  console.log(`PASS: ${name}`);
}

// T1: Bullish Wick Sweep (len=2) + box extension + close below wick low mitigates box
check('T1_bullish_wick_sweep_and_box_mitigation', () => {
  const eng = new LiquiditySweepsV2({ len: 2, opt: 'Only Wicks', extend: true, maxB: 300 });
  const seq = [
    { high: 105, low: 100, close: 102 },
    { high: 104, low: 98, close: 99 },
    { high: 101, low: 95, close: 97 },   // pivot low = 95 @ bar 2
    { high: 103, low: 97, close: 101 },
    { high: 104, low: 99, close: 103 },  // bar 4 confirms pl=95
    { high: 103, low: 93, close: 96 },   // bar 5: low 93 < 95 && close 96 > 95 -> WICK_BULL!
    { high: 105, low: 96, close: 102 },  // bar 6: extends box (right=6), active
    { high: 98, low: 91, close: 92 },    // bar 7: close 92 < bottom 93 -> box br=true
  ];
  const outs = seq.map((b, i) => eng.onClosedBar({ ...b, barIndex: i }));
  assert.equal(outs[4].sweeps.length, 0);
  assert.equal(outs[5].sweeps.length, 1);
  assert.equal(outs[5].sweeps[0].kind, 'WICK_BULL');
  assert.equal(outs[5].sweeps[0].top, 95);
  assert.equal(outs[5].sweeps[0].bottom, 93);
  assert.equal(outs[5].sweeps[0].br, false);
  assert.equal(outs[6].activeBoxes, 1);
  assert.equal(outs[7].activeBoxes, 0);
  assert.equal(eng.aBoxBr[0].br, true);
  assert.equal(eng.aBoxBr[0].right, 7);
});

// T2: Bearish Wick Sweep (len=2) + close > prc under Only Wicks mitigates pivot without sweep
check('T2_bearish_wick_sweep_and_only_wicks_close_break_mitigates', () => {
  const eng = new LiquiditySweepsV2({ len: 2, opt: 'Only Wicks' });
  const seq = [
    { high: 100, low: 95, close: 98 },
    { high: 105, low: 98, close: 103 },
    { high: 110, low: 102, close: 106 }, // pivot high = 110 @ bar 2
    { high: 106, low: 100, close: 102 },
    { high: 104, low: 99, close: 101 },  // bar 4 confirms ph=110
    { high: 112, low: 104, close: 108 }, // bar 5: high 112 > 110 && close 108 < 110 -> WICK_BEAR
    { high: 115, low: 109, close: 113 }, // bar 6: close 113 > 110 -> mitigates pivot & box
    { high: 111, low: 105, close: 107 }, // bar 7: old pivot mitigated, no duplicate sweep
  ];
  const outs = seq.map((b, i) => eng.onClosedBar({ ...b, barIndex: i }));
  assert.equal(outs[5].sweeps.length, 1);
  assert.equal(outs[5].sweeps[0].kind, 'WICK_BEAR');
  assert.equal(outs[5].sweeps[0].top, 112);
  assert.equal(outs[5].sweeps[0].bottom, 110);
  assert.equal(outs[6].activeBoxes, 0);
  assert.equal(outs[7].sweeps.length, 0);
});

// T3: Outbreaks & Retest mode (close > ph sets brk=true, later low < ph && close > ph triggers dashed bull)
check('T3_outbreak_and_retest_mode', () => {
  const eng = new LiquiditySweepsV2({ len: 2, opt: 'Only Outbreaks & Retest' });
  const seq = [
    { high: 100, low: 95, close: 98 },
    { high: 105, low: 98, close: 103 },
    { high: 110, low: 102, close: 106 }, // ph=110 @ bar 2
    { high: 106, low: 100, close: 102 },
    { high: 104, low: 99, close: 101 },  // bar 4 confirms ph=110
    { high: 112, low: 104, close: 108 }, // bar 5: wick only, ignored in oO mode
    { high: 114, low: 108, close: 113 }, // bar 6: close 113 > 110 -> brk=true
    { high: 115, low: 109, close: 112 }, // bar 7: low 109 < 110 && close 112 > 110 -> OUTBREAK_RETEST_BULL
  ];
  const outs = seq.map((b, i) => eng.onClosedBar({ ...b, barIndex: i }));
  assert.equal(outs[5].sweeps.length, 0);
  assert.equal(outs[7].sweeps.length, 1);
  assert.equal(outs[7].sweeps[0].kind, 'OUTBREAK_RETEST_BULL');
  assert.equal(outs[7].sweeps[0].lineStyle, 'dashed');
});

// T4: Strict boundary equality (close == prc does NOT trigger sweep) + maxB cap
check('T4_strict_inequality_and_maxB_extension_cap', () => {
  const eng = new LiquiditySweepsV2({ len: 1, opt: 'Only Wicks', extend: true, maxB: 2 });
  const seq = [
    { high: 100, low: 95, close: 98 },
    { high: 100, low: 90, close: 95 },  // pl=90 @ bar 1
    { high: 101, low: 94, close: 99 },  // confirms pl=90
    { high: 95, low: 89, close: 90 },   // close == 90 -> NOT > 90 -> no sweep
    { high: 96, low: 88, close: 92 },   // bar 4: WICK_BULL (left=3, right=5)
    { high: 97, low: 91, close: 95 },   // bar 5: (5-3-1)=1 <= 2 -> right=5
    { high: 97, low: 91, close: 95 },   // bar 6: (6-3-1)=2 <= 2 -> right=6
    { high: 97, low: 91, close: 95 },   // bar 7: (7-3-1)=3 > 2 -> stops at right=6
  ];
  const outs = seq.map((b, i) => eng.onClosedBar({ ...b, barIndex: i }));
  assert.equal(outs[3].sweeps.length, 0);
  assert.equal(outs[4].sweeps.length, 1);
  assert.equal(eng.aBoxBr[0].right, 6);
});

console.log(`SUMMARY: ${passed}/4 tests passed`);
以下保留第 1 次修正原文(2026-11-20,25346 B,SHA-256:449919ea566bd7d1c9e4cb9a6df05fed25823ad5344759a83fd6b8bcca9c65c7)

A39|Liquidity Sweeps [LuxAlgo] 指標拆解與核實報告(seq=65024)

修訂版本:第 1 次修正(初版)|日期:2026-11-20|來源事件:seq=65024(dj_host1 / Owner 臨時加插)
席位:A39(A398921,9號組)|核實來源:api.fxtwitter.com、publish.twitter.com/oembed、r.jina.ai、Twitter 原圖實讀、TradingView 腳本頁 JRqryeJ5、pine-facade.tradingview.com 實碼(5793 B,SHA-256 18be09f34ebf371e...)、LuxAlgo Library。

1. X 原帖全文、作者與圖表內容(實取原文,零臆測)

目標帖文:https://x.com/foodloss_otoko/status/2123461381030834442
作者:べーた(@foodloss_otoko,user_id 1935277322825089024,自介:「専業トレーダー、EA×裁量で生活してます。」)
發布時間:2026-11-19T17:00:19Z(Thu Nov 19 17:00:19 +0000 2026)

主帖全文(引原文)

マジで全トレーダーに「Liquidity Sweeps」を使ってほしい。 「これブレイクじゃなくてダマシやん」って場所が一瞬で分かる。 俺もずっと使ってるけど、これだけで月+100万ならガチで初心者でもいけそう。 具体的な使い方なんだけど、、、

串連回覆全文(引原文)

三張附圖實讀內容

圖片實見圖表內容
圖 1
HXgMkl3bMAAZINR
左上角標示 TradingView 圖示與指標名稱 Liquidity Sweeps [LuxAlgo],時間軸為 10/5~10/7,價位範圍 4120.00~4220.00。圖上出現 2 處紅色看跌掃蕩(× Sweep 標籤+水平紅線自前高連至突破 K 棒+垂直紅色半透明區間方框框住上影線至前高,約 ~4181 與 ~4203)及 2 處藍色看漲掃蕩(× Sweep 標籤+水平藍線自前低連至下探 K 棒+垂直藍色半透明方框,約 ~4140 與 ~4119)。(備註:圖1視覺屬社交媒體美化示意風格,原版官方 TradingView 指標實際繪圖為點線/虛線+垂直粗線+延伸半透明方框+3棒小點線,並不畫出「× Sweep」圓角文字標籤。)
圖 2
HXgMrG2aIAA0NZw
做多進場與止損示意圖:以白色水平線穿過兩個白色空心圓圈標示近期低點(雙底流動性水平);隨後紅燭下影線插穿該水平線,接著陽燭實體收盤站回水平線之上並標出綠色打勾圓圈(進場位置),白色箭頭斜指右上綠色漸層盈利目標區;掃蕩最低影線尖端處引出紅色水平虛線連接紅叉圓圈,表示止損(SL)置於掃蕩影線低點之外。
圖 3
HXgMu5yaIAAETFz
做多/做空雙向對稱示意圖:左側底部對兩個白圈支撐位出現長下影線掃蕩(黃色虛線橢圓框住下插影線、下方紅色虛線+紅叉標示 SL),陽燭收復水平線白圈後白色弧形箭頭向上;右側頂部對兩個白圈阻力位出現長上影線掃蕩(黃色虛線橢圓框住上插影線、上方紅色虛線+紅叉標示 SL),陰燭實體收跌回水平線下方白圈後白色弧形箭頭向下。

2. 指標完整計法:基礎理論、輸入、參數與逐步驟數學定義

2.1 理論與演算法基礎(由什麼基礎發展出來)

  1. 價格行為與流動性基礎:衍生自 SMC / ICT 流動性掃蕩(Liquidity Sweep / Stop Hunt) 與經典 Swing Failure Pattern (SFP)(亦與 Turtle Soup/Wyckoff Spring & Upthrust 同源)。核心邏輯:顯著波段高/低點(Swing High / Swing Low,程式中稱為 Liquidity Level LqL)外側聚集止損單與突破追蹤單(Liquidity Pool);價格短暫刺穿 LqL 觸發單量後無法在該側收盤站穩,反而收盤回到區間內部形成影線,代表假突破與流動性吸收。
  2. 程式演算法基礎:由 LuxAlgo(2024-02-08 發布於 TradingView,Pine Script v5)實作,以 TradingView 內建對稱分形極值函式 ta.pivothigh(len, len) 與 ta.pivotlow(len, len) 為波段水平偵測引擎,並結合狀態機(Broken / Mitigated / Taken / Wicked)與矩形延伸管理 Sweep Area。之後 LuxAlgo 於 2024-08 另由此演進開發出無固定棒數參數的遞迴 3-K 線分形版本 Pure Price Action Liquidity Sweeps。

2.2 輸入序列與全部參數(核對官方 Pine Script v5 原碼)

類別名稱 / 變數預設值 / 範圍實際作用
輸入序列high, low, close, bar_index每根 K 線逐棒提供只用最高、最低、收盤價與棒索引;不用 open 及 volume。
參數 1len(Swings)5(minval=1)左右各 len 根 K 線視窗偵測波段高/低點(總窗寬 2*len + 1 棒)。
參數 2opt(options)'Only Wicks'
可選:'Only Wicks' / 'Only Outbreaks & Retest' / 'Wicks + Outbreaks & Retest'
oW=只偵測影線掃蕩;oO=只偵測先實體突破後回踩掃蕩;WO=兩者皆偵測。預設 Only Wicks 與原帖教學完全對應。
參數 3extend(Extend)true是否將 Sweep Area 方框隨新 K 線向右延伸。
參數 4maxB(Max bars)300(1..5000)方框最大向右延伸 K 棒數上限。
參數 5colBl/colBr 等 6 個顏色看漲 #089981、看跌 #f23645(含 80/41 透明階)僅影響線條、觸發棒粗線與方框底色。

2.3 完整逐步驟計算規則(無跳步)

記當前 K 線索引為 n = bar_index。對每根 K 線依序執行以下 4 步:

步驟 1:波段流動性水平(LqL)偵測與入池(確認延遲 len 棒)

  1. 計算 ph = ta.pivothigh(high, len, len):檢查 k = n - len 位置的 high[k] 是否為區間 [n - 2*len, n] 內之最高點(左 len 棒均嚴格低於 high[k]、右 len 棒均低於或等於且無更高者)。若非 na,將新 piv 物件壓入陣列 aPivH 前端:prc = ph、bix = n - len、brk = false、mit = false、tak = false、wic = false。
  2. 計算 pl = ta.pivotlow(low, len, len):同理於 k = n - len 檢查區間最低點,若非 na 則壓入 aPivL 前端。
  3. 關鍵特性:任何波段點須等右側 len 根 K 線走完才入池;入池後才會被之後的新棒判斷是否掃蕩。

步驟 2:逐一掃描高點池 aPivH(對每個 get,當 not get.mit)

步驟 3:逐一掃描低點池 aPivL(完全鏡像對稱)

步驟 4:Sweep Area 方框延伸與失效停止(Mitigation)

若 extend == true,對 aBoxBr 中每個尚未失效(not bx.br)且 n - bx.bx.get_left() - 1 <= maxB 的方框執行:

  1. 向右延伸右界:bx.bx.set_right(bar_index)。
  2. 看漲方框失效(bx.dr == -1):若 close[n] < bx.bx.get_bottom()(即收盤跌破該次掃蕩影線最低點),置 bx.br := true,停止延伸。
  3. 看跌方框失效(bx.dr == 1):若 close[n] > bx.bx.get_top()(即收盤漲破該次掃蕩影線最高點),置 bx.br := true,停止延伸。

附註(原碼實測邊界特性):

3. 取得渠道與「TeamViewer」核實結論

4. 附錄:實取官方 Pine Script v5 完整原文(5793 bytes,SHA-256:18be09f34ebf371e4cc8997ba77c29cc1ada4612a5529a79994694ec9b6ba12d)

// This work is licensed under a Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0) https://creativecommons.org/licenses/by-nc-sa/4.0/
// © LuxAlgo

//@version=5
indicator( 'Liquidity Sweeps [LuxAlgo]'
         , 'LuxAlgo - Liquidity Sweeps'
         ,  max_lines_count=500
         ,  max_boxes_count=500
         ,  overlay=true
         )

//------------------------------------------------------------------------------
//Settings
//-----------------------------------------------------------------------------{
len    = input.int(5, 'Swings', minval=1, group='Liquidity Sweeps')
opt    = input.string('Only Wicks', 'options'
       , options=['Only Wicks', 'Only Outbreaks & Retest', 'Wicks + Outbreaks & Retest'], group='Liquidity Sweeps')

colBl  = input.color(#089981, 'Bull ', group='Liquidity Sweeps', inline='c1')
colBr  = input.color(#f23645, 'Bear' , group='Liquidity Sweeps', inline='c2')
colBl2 = input.color(#08998180,  ''  , group='Liquidity Sweeps', inline='c1')
colBr2 = input.color(#f2364580,  ''  , group='Liquidity Sweeps', inline='c2')

extend = input.bool(true, 'Extend', group='Sweep Area') 
maxB   = input.int(300, 'Max bars', minval=1, maxval=5000, group='Sweep Area')
colBl3 = input.color(#08998141, 'Bull ', group='Sweep Area')
colBr3 = input.color(#f2364541, 'Bear' , group='Sweep Area')

oW = opt == 'Only Wicks'
oO = opt == 'Only Outbreaks & Retest'
WO = opt == 'Wicks + Outbreaks & Retest'

n = bar_index 

//-----------------------------------------------------------------------------}      
//UDT's
//-----------------------------------------------------------------------------{
type piv
    float prc // price
    int   bix // bar_index
    bool  brk // broken
    bool  mit // mitigated
    bool  tak // taken
    bool  wic // wick
    line  lin 

type boxBr 
    box  bx 
    line ln
    bool br
    int  dr

//-----------------------------------------------------------------------------}      
//Variables
//-----------------------------------------------------------------------------{
var array< piv >aPivH  = array.new< piv >(1, piv.new  ())
var array< piv >aPivL  = array.new< piv >(1, piv.new  ())
var array<boxBr>aBoxBr = array.new<boxBr>(1, boxBr.new())

//-----------------------------------------------------------------------------}      
//Methods - functions
//-----------------------------------------------------------------------------{
method n(float piv) => bool out = not na(piv)

method p(piv piv, float val) => float out = (100 / piv.prc * val) - 100

method l(piv get, color c, string s='sd') => 
    style = switch s 
        'dt' => line.style_dotted
        'ds' => line.style_dashed
        =>      line.style_solid 
    line.new(get.bix, get.prc, n, get.prc, color=c, style = style)

method br(piv get, color c3, color c, int d) =>
    y1 = d == 1 ? high : get.prc
    y2 = d == 1 ? get.prc : low
    boxBr.new( 
     box.new(n -1, y1, n +1, y2
     , border_color
     = color.new(
       na, na   )
     , bgcolor=c3)
     , line.new(n , y1, n, y2, color=c, width=3)
     , false
     , d)

lnDot(y, c) => line.new(n, y, n+3, y, color=c, style=line.style_dotted)

//-----------------------------------------------------------------------------}      
//Execution
//-----------------------------------------------------------------------------{
ph = ta.pivothigh(len, len)
pl = ta.pivotlow (len, len)

if ph.n() 
    aPivH.unshift(piv.new(ph, n -len, false, false, false, false))

if pl.n() 
    aPivL.unshift(piv.new(pl, n -len, false, false, false, false)) 

for i = aPivH.size() -1 to 0
    get = aPivH.get(i)
    if not get.mit
        if not get.brk
            if close > get.prc 
                if not oW
                    get.brk := true
                else 
                    get.mit := true
            if not oO and not get.wic 
                if high > get.prc and close < get.prc                   
                    aBoxBr.unshift(get.br(colBr3, colBr, 1))       
                    get.l(colBr2, 'dt'), lnDot(low, colBr)
                    get.wic := true  
        else 
            if close < get.prc 
                get.mit := true
            if not oW and low < get.prc and close > get.prc                    
                aBoxBr.unshift(get.br(colBl3, colBl, -1))    
                get.l(colBl2, 'ds'), lnDot(high, colBl)
                get.tak := true 

    if n - get.bix > 2000 or get.mit or get.tak 
        aPivH.remove(i).lin.delete()

for i = aPivL.size() -1 to 0
    get = aPivL.get(i)
    if not get.mit
        if not get.brk
            if close < get.prc 
                if not oW
                    get.brk := true
                else 
                    get.mit := true
            if not oO and not get.wic 
                if low < get.prc and close > get.prc                              
                    aBoxBr.unshift(get.br(colBl3, colBl, -1))     
                    get.l(colBl2, 'dt'), lnDot(high, colBl)
                    get.wic := true 
        else 
            if close > get.prc 
                get.mit := true
            if not oW and high > get.prc and close < get.prc                     
                aBoxBr.unshift(get.br(colBr3, colBr, 1))    
                get.l(colBr2, 'ds'), lnDot(low, colBr)
                get.tak := true  

    if n - get.bix > 2000 or get.mit or get.tak 
        aPivL.remove(i).lin.delete()

if extend
    for bx in aBoxBr 
        if not bx.br and n - bx.bx.get_left() -1 <= maxB 
            bx.bx.set_right(bar_index)
            if bx.dr == -1 and close < bx.bx.get_bottom() 
                bx.br := true 
            if bx.dr ==  1 and close > bx.bx.get_top   () 
                bx.br := true 

//-----------------------------------------------------------------------------} 

第 1 次修正(初版)|2026-11-20|A39(A398921)|本檔為單一自包含靜態 HTML(無外連資源)。