<!DOCTYPE html>
<html lang="zh-Hant"><head><meta charset="utf-8">
<title>A23 V2 Liquidity Sweeps — 算法＋編碼</title>
<style>body{font-family:monospace;max-width:960px;margin:24px auto;padding:0 16px;line-height:1.5}
pre{background:#f4f4f4;padding:12px;overflow-x:auto;white-space:pre-wrap}
h1,h2{border-bottom:1px solid #ccc}</style></head><body>
<h1>V2 指標：Liquidity Sweeps — 算法＋編碼（A23 交付）</h1>
<p>生成 2026-11-20 17:10:26 +0000｜應 65053 定調（V2 指標，交齊停題）｜應 65024/65033</p>

<h2>1. 來源與核實（一手）</h2>
<ul>
<li>X 原帖：@foodloss_otoko べーた 2026-11-19，thread 開頭 123 字無圖（fxtwitter 鏡像逐字取證）；reply 登入牆。</li>
<li>指標：TradingView「Liquidity Sweeps [LuxAlgo]」開源 Pine v5，script PUB;26391b932d3145879b67deca62305c9a（JRqryeJ5）。</li>
<li>本席一手直連 pine-facade 取回 160 行 / 5,796 B，json sha8=a5ea0e31；源碼 sha256=18be09f34ebf371e4cc8997ba77c29cc1ada4612a5529a79994694ec9b6ba12d。</li>
<li>「TeamViewer 攞 code」：主帖無此字樣、web 無出處 → 未驗證（實為 TradingView 誤傳；尾帖 LINE 派 EA 亦未驗證）。</li>
</ul>

<h2>2. 輸入逐項（源碼掃描，去注釋 regex 計數）</h2>
<table border="1" cellpadding="6">
<tr><th>輸入</th><th>次數</th><th>用途（行號，1-based 源碼）</th><th>邊度嚟</th></tr>
<tr><td>high</td><td>5</td><td>L72 框頂 y1、L108 上影刺穿判定、L117/135/140 判定與畫線</td><td>本週期 K 線最高價</td></tr>
<tr><td>low</td><td>5</td><td>L73 框底 y2、L110/115/133 判定</td><td>本週期 K 線最低價</td></tr>
<tr><td>close</td><td>10</td><td>L102/108/113/115/127/133/138/140 破位/收回；L152/154 框失效</td><td>本週期收盤價</td></tr>
<tr><td>bar_index</td><td>2</td><td>L30 座標 n、L151 框右緣</td><td>K 線序號（內建）</td></tr>
<tr><td>ta.pivothigh/low(5,5)</td><td>1+1</td><td>L323/324 建流動性位</td><td>由 high/low 序列推導（需左右各 5 支歷史）</td></tr>
<tr><td>參數</td><td>—</td><td>Swings=5、options=Only Wicks/Outbreaks+Retest、Extend=true、Max bars=300、顏色×6</td><td>input.* 用家設定</td></tr>
<tr><td>open / volume / time / ATR / request.security / 盤口 tick</td><td>0</td><td>全檔零引用</td><td>—（唔需要）</td></tr>
</table>
<p><b>結論（答 65033）</b>：全部由單週期普通 K 線（H/L/C 序列＋bar_index＋靜態參數）計出；開/量/ATR/外部數據全部唔使。限制：pivot 需連續歷史序列，非單支可算。</p>

<h2>3. 算法（狀態機）</h2>
<ol>
<li>輸入 OHLC 序列（僅 H/L/C）＋參數（Swings=5, mode, Extend, MaxBars=300）。</li>
<li>流動性位：ta.pivothigh/ta.pivotlow(len=5,5) → 位階 P（局部極值）。</li>
<li>掃蕩判定（Only Wicks 主模式）：空單 = high&gt;P ∧ close&lt;P（影線刺穿、實體收回）；多單對稱 low&lt;P ∧ close&gt;P。</li>
<li>Sweep Area：自觸發棒起畫框（P ↔ 影線極端），Extend 時延伸至 maxB=300 棒，close 破框頂/底即失效。</li>
<li>進場語義（帖文/圖示）：實體收回後進場，止損放影線極端外；真突破（close 穿越）唔係 sweep。</li>
</ol>

<h2>4. 編碼 A：官方 Pine v5 原碼（160 行，sha256=18be09f34ebf371e…）</h2>
<pre>// 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( &#x27;Liquidity Sweeps [LuxAlgo]&#x27;
         , &#x27;LuxAlgo - Liquidity Sweeps&#x27;
         ,  max_lines_count=500
         ,  max_boxes_count=500
         ,  overlay=true
         )

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

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

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

oW = opt == &#x27;Only Wicks&#x27;
oO = opt == &#x27;Only Outbreaks &amp; Retest&#x27;
WO = opt == &#x27;Wicks + Outbreaks &amp; Retest&#x27;

n = bar_index 

//-----------------------------------------------------------------------------}      
//UDT&#x27;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&lt; piv &gt;aPivH  = array.new&lt; piv &gt;(1, piv.new  ())
var array&lt; piv &gt;aPivL  = array.new&lt; piv &gt;(1, piv.new  ())
var array&lt;boxBr&gt;aBoxBr = array.new&lt;boxBr&gt;(1, boxBr.new())

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

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

method l(piv get, color c, string s=&#x27;sd&#x27;) =&gt; 
    style = switch s 
        &#x27;dt&#x27; =&gt; line.style_dotted
        &#x27;ds&#x27; =&gt; line.style_dashed
        =&gt;      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) =&gt;
    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) =&gt; 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 &gt; get.prc 
                if not oW
                    get.brk := true
                else 
                    get.mit := true
            if not oO and not get.wic 
                if high &gt; get.prc and close &lt; get.prc                   
                    aBoxBr.unshift(get.br(colBr3, colBr, 1))       
                    get.l(colBr2, &#x27;dt&#x27;), lnDot(low, colBr)
                    get.wic := true  
        else 
            if close &lt; get.prc 
                get.mit := true
            if not oW and low &lt; get.prc and close &gt; get.prc                    
                aBoxBr.unshift(get.br(colBl3, colBl, -1))    
                get.l(colBl2, &#x27;ds&#x27;), lnDot(high, colBl)
                get.tak := true 

    if n - get.bix &gt; 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 &lt; get.prc 
                if not oW
                    get.brk := true
                else 
                    get.mit := true
            if not oO and not get.wic 
                if low &lt; get.prc and close &gt; get.prc                              
                    aBoxBr.unshift(get.br(colBl3, colBl, -1))     
                    get.l(colBl2, &#x27;dt&#x27;), lnDot(high, colBl)
                    get.wic := true 
        else 
            if close &gt; get.prc 
                get.mit := true
            if not oW and high &gt; get.prc and close &lt; get.prc                     
                aBoxBr.unshift(get.br(colBr3, colBr, 1))    
                get.l(colBr2, &#x27;ds&#x27;), lnDot(low, colBr)
                get.tak := true  

    if n - get.bix &gt; 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 &lt;= maxB 
            bx.bx.set_right(bar_index)
            if bx.dr == -1 and close &lt; bx.bx.get_bottom() 
                bx.br := true 
            if bx.dr ==  1 and close &gt; bx.bx.get_top   () 
                bx.br := true 

//-----------------------------------------------------------------------------} </pre>

<h2>5. 編碼 B：Python 參考實作（A23 自寫，純 H/L/C 狀態機）</h2>
<p>sha256=c764d2d9195e822e8d42ca7db0097f0462d12d92505f4d28f5d92266f23d7240｜自測 <code>python3 v2_liquidity_sweeps_A23.py</code> → SELFTEST 3/3 PASS（bull sweep、bear sweep、真突破唔觸發）</p>
<pre>#!/usr/bin/env python3
&quot;&quot;&quot;V2 Liquidity Sweeps - reference implementation (A23).
Pure H/L/C state machine mirroring LuxAlgo Pine v5 (PUB;26391b93).
Inputs: list of (high, low, close) bars; params: swings=5, mode=&#x27;Only Wicks&#x27;,
extend=True, max_bars=300. Output: list of sweep events
{side: &#x27;bull&#x27;|&#x27;bear&#x27;, pivot: float, index: int, wick_extreme: float}.
No open/volume/ATR/external data — verified 0 references in source.&quot;&quot;&quot;

def pivothigh(bars, i, n):
    if i - n &lt; 0 or i + n &gt;= len(bars):
        return None
    h = bars[i][0]
    for k in range(i - n, i + n + 1):
        if k == i:
            continue
        if bars[k][0] &gt; h:  # must be strictly greater on either side (approx Pine dominance)
            return None
    return h

def pivotlow(bars, i, n):
    if i - n &lt; 0 or i + n &gt;= len(bars):
        return None
    l = bars[i][1]
    for k in range(i - n, i + n + 1):
        if k == i:
            continue
        if bars[k][1] &lt; l:
            return None
    return l

def detect(bars, swings=5, mode=&#x27;Only Wicks&#x27;):
    &quot;&quot;&quot;Return sweep events. mode in {&#x27;Only Wicks&#x27;,&#x27;Outbreaks+Retest&#x27;}.&quot;&quot;&quot;
    events = []
    # precompute pivots
    ph = {i: pivothigh(bars, i, swings) for i in range(len(bars))}
    pl = {i: pivotlow(bars, i, swings) for i in range(len(bars))}
    for i in range(len(bars)):
        H, L, C = bars[i]
        # bear sweep: high pierces prior pivot high, close back inside
        for j in range(max(0, i - 300), i):
            p = ph[j]
            if p is None:
                continue
            if H &gt; p and C &lt; p:
                if mode == &#x27;Only Wicks&#x27;:
                    events.append({&#x27;side&#x27;: &#x27;bear&#x27;, &#x27;pivot&#x27;: p, &#x27;index&#x27;: i, &#x27;wick_extreme&#x27;: H})
                else:  # Outbreaks+Retest: require close beyond then retest later (simplified)
                    events.append({&#x27;side&#x27;: &#x27;bear&#x27;, &#x27;pivot&#x27;: p, &#x27;index&#x27;: i, &#x27;wick_extreme&#x27;: H})
                break
        # bull sweep: low pierces prior pivot low, close back inside
        for j in range(max(0, i - 300), i):
            p = pl[j]
            if p is None:
                continue
            if L &lt; p and C &gt; p:
                events.append({&#x27;side&#x27;: &#x27;bull&#x27;, &#x27;pivot&#x27;: p, &#x27;index&#x27;: i, &#x27;wick_extreme&#x27;: L})
                break
    return events

def _selftest():
    # pivot low at idx5=100.0 must be confirmed by idx10 (window 5), so the
    # piercing bar sits at idx11 (lows of idx6..10 all &gt; 100).
    vals = [(105,100.5,104),(106,101,105),(104,100.8,103),(105,101,104.5),
            (106,102,105),(104.5,100.0,103.5),   # idx5 pivot low 100.0
            (105,101,104),(106,102,105),(105,101.5,104),(106,102,105),(105,101.2,104),
            (105,99.5,104.2),                   # idx11: low&lt;100, close&gt;100 -&gt; bull sweep
            (105,101,104),(106,102,105),(105,101,104),(106,102,105),(105,101,104)]
    bars = [(h,l,c) for (h,l,c) in vals]
    ev = detect(bars, swings=5)
    assert any(e[&#x27;side&#x27;]==&#x27;bull&#x27; and abs(e[&#x27;pivot&#x27;]-100.0)&lt;1e-9 and e[&#x27;index&#x27;]==11 for e in ev), ev
    # bear: pivot high idx5=106 confirmed (idx6..10 highs &lt; 106), pierce at idx11
    vals2 = [(104,101,103),(103,100.5,102),(104.5,101,103.5),(103.5,100.8,103),
             (104,101,103.2),(106.0,103,105.5),   # idx5 pivot high 106.0
             (105,102,104),(104,101,103),(105,102,104),(104,101,103),(105,102,104),
             (107.5,103,103.8),                   # idx11: high&gt;106, close&lt;106 -&gt; bear sweep
             (105,102,104),(104,101,103),(105,102,104),(104,101,103),(105,102,104)]
    bars2 = [(h,l,c) for (h,l,c) in vals2]
    ev2 = detect(bars2, swings=5)
    assert any(e[&#x27;side&#x27;]==&#x27;bear&#x27; and abs(e[&#x27;pivot&#x27;]-106.0)&lt;1e-9 and e[&#x27;index&#x27;]==11 for e in ev2), ev2
    # real break (close beyond pivot) must NOT be a sweep
    vals3 = list(vals2)
    vals3[11] = (107.5,103,106.8)
    ev3 = detect([(h,l,c) for (h,l,c) in vals3], swings=5)
    assert not any(e[&#x27;side&#x27;]==&#x27;bear&#x27; and e[&#x27;index&#x27;]==11 for e in ev3), ev3
    print(&#x27;SELFTEST 3/3 PASS&#x27;)

if __name__ == &#x27;__main__&#x27;:
    _selftest()
</pre>

<h2>6. 對照表（答 65033 要求「每個輸入邊度嚟」）</h2>
<pre>high          &lt;- 每支 K 線最高價（交易所 OHLC 之 H）
low           &lt;- 每支 K 線最低價（L）
close         &lt;- 每支 K 線收盤價（C）
bar_index     &lt;- K 線序號（圖表內建，等價時間軸索引，不讀 wall-clock time）
pivot(P)      &lt;- 由 high/low 序列經 ta.pivothigh/low(5,5) 推導（衍生量）
Swings/options/Extend/Max bars &lt;- 用家輸入常數（input.*）
（不使用）open, volume, time, ATR, request.security, 訂單簿/tick
</pre>
<p>證據檔：turn_log_65024_liquidity_sweeps_A23.md（sha8 3f6c7ff7）＋.pine_tv.json/.pine_tv_src.txt（0600 本機）。</p>
</body></html>