market-engine-server.js,待後續改程式階段再掛載)。{ high, low, close, barIndex }(open 與 volume 均不用),無外部 feed / 盤口依賴,可直接由伺服器既有 1m/3m/15m/60m canonical K 線陣列驅動。[n - 2*len, n](預設 len=5)確認 n - len 處之 pivothigh / pivotlow,推入 aPivH / aPivL(2000 棒逾時淘汰)。Only Wicks(預設):前高未突破時,若 close > prc 則作廢;若 high > prc && close < prc 觸發看跌掃蕩(WICK_BEAR),前低對稱觸發看漲掃蕩(WICK_BULL)。Only Outbreaks & Retest / Wicks + Outbreaks & Retest:收破後設 brk=true,其後反影線刺回且收復觸發 OUTBREAK_RETEST_BULL/BEAR。extend=true 且 n - left - 1 <= maxB(預設 300),每棒更新右界;收盤破極值(看漲 close < bottom/看跌 close > top)即止延。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,
};
}
}
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
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`);
目標帖文: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万ならガチで初心者でもいけそう。 具体的な使い方なんだけど、、、
HXgMkl3bMAAZINR):
① TradingViewのインジケーターから **「Liquidity Sweeps [LuxAlgo]」**を表示する。 これだけで、高値・安値の流動性を取りに行った場所が自動で見える。
HXgMrG2aIAA0NZw):
② ロングの場合は、 直近安値をヒゲで一度下抜けて、実体が安値の上に戻って確定したらエントリー。 ヒゲで抜けただけでは入らない。
HXgMu5yaIAAETFz):
③ 損切りは、 スイープした直近安値の外に置く。 ショートはこの逆で、直近高値をヒゲで上抜けて、実体が高値の下に戻って確定したら入る。
5年間バックテストして作った、 ナンピンなし・安定重視のEA を無料配布します。 プロフのリンク ↓ LINE登録 これだけで受け取れます。(註:作者個人簡介網站欄位為
https://lin.ee/yx9eCqY。)
| 圖片 | 實見圖表內容 |
|---|---|
圖 1HXgMkl3bMAAZINR |
左上角標示 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」圓角文字標籤。) |
圖 2HXgMrG2aIAA0NZw |
做多進場與止損示意圖:以白色水平線穿過兩個白色空心圓圈標示近期低點(雙底流動性水平);隨後紅燭下影線插穿該水平線,接著陽燭實體收盤站回水平線之上並標出綠色打勾圓圈(進場位置),白色箭頭斜指右上綠色漸層盈利目標區;掃蕩最低影線尖端處引出紅色水平虛線連接紅叉圓圈,表示止損(SL)置於掃蕩影線低點之外。 |
圖 3HXgMu5yaIAAETFz |
做多/做空雙向對稱示意圖:左側底部對兩個白圈支撐位出現長下影線掃蕩(黃色虛線橢圓框住下插影線、下方紅色虛線+紅叉標示 SL),陽燭收復水平線白圈後白色弧形箭頭向上;右側頂部對兩個白圈阻力位出現長上影線掃蕩(黃色虛線橢圓框住上插影線、上方紅色虛線+紅叉標示 SL),陰燭實體收跌回水平線下方白圈後白色弧形箭頭向下。 |
LqL)外側聚集止損單與突破追蹤單(Liquidity Pool);價格短暫刺穿 LqL 觸發單量後無法在該側收盤站穩,反而收盤回到區間內部形成影線,代表假突破與流動性吸收。ta.pivothigh(len, len) 與 ta.pivotlow(len, len) 為波段水平偵測引擎,並結合狀態機(Broken / Mitigated / Taken / Wicked)與矩形延伸管理 Sweep Area。之後 LuxAlgo 於 2024-08 另由此演進開發出無固定棒數參數的遞迴 3-K 線分形版本 Pure Price Action Liquidity Sweeps。| 類別 | 名稱 / 變數 | 預設值 / 範圍 | 實際作用 |
|---|---|---|---|
| 輸入序列 | high, low, close, bar_index | 每根 K 線逐棒提供 | 只用最高、最低、收盤價與棒索引;不用 open 及 volume。 |
| 參數 1 | len(Swings) | 5(minval=1) | 左右各 len 根 K 線視窗偵測波段高/低點(總窗寬 2*len + 1 棒)。 |
| 參數 2 | opt(options) | 'Only Wicks'可選: 'Only Wicks' / 'Only Outbreaks & Retest' / 'Wicks + Outbreaks & Retest' | oW=只偵測影線掃蕩;oO=只偵測先實體突破後回踩掃蕩;WO=兩者皆偵測。預設 Only Wicks 與原帖教學完全對應。 |
| 參數 3 | extend(Extend) | true | 是否將 Sweep Area 方框隨新 K 線向右延伸。 |
| 參數 4 | maxB(Max bars) | 300(1..5000) | 方框最大向右延伸 K 棒數上限。 |
| 參數 5 | colBl/colBr 等 6 個顏色 | 看漲 #089981、看跌 #f23645(含 80/41 透明階) | 僅影響線條、觸發棒粗線與方框底色。 |
記當前 K 線索引為 n = bar_index。對每根 K 線依序執行以下 4 步:
步驟 1:波段流動性水平(LqL)偵測與入池(確認延遲 len 棒)
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。pl = ta.pivotlow(low, len, len):同理於 k = n - len 檢查區間最低點,若非 na 則壓入 aPivL 前端。len 根 K 線走完才入池;入池後才會被之後的新棒判斷是否掃蕩。步驟 2:逐一掃描高點池 aPivH(對每個 get,當 not get.mit)
not get.brk):
close[n] > get.prc:
not oW(即允許 Outbreaks),設 get.brk := true(轉入「已突破,待回踩」狀態)。oW(預設 Only Wicks),設 get.mit := true(此高點直接作廢淘汰)。d = 1):若 not oO and not get.wic 且同時滿足:
high[n] > get.prc AND close[n] < get.prc(註:兩側皆為嚴格不等號;上影線刺破
get.prc 但同一棒收盤收於 get.prc 之下):
y1 = high[n]、下界 y2 = get.prc、左界 n - 1、初右界 n + 1,並於第 n 棒繪製寬度 3 的垂直線 (n, get.prc) ↔ (n, high[n])。dotted)由 (get.bix, get.prc) 連至 (n, get.prc)。low[n] 繪製 3 棒長水平輔助點線 (n, low[n]) → (n + 3, low[n])。get.wic := true(防止該 piv 未突破前重複觸發)。get.brk == true,僅 oO/WO 會進入):
close[n] < get.prc:設 get.mit := true(重新跌回破位水平下方,作廢)。not oW 且滿足 low[n] < get.prc AND close[n] > get.prc:觸發看漲突破回踩掃蕩(d = -1),繪水平虛線(dashed),建方框 [low[n], get.prc],於 high[n] 畫 3 棒點線,置 get.tak := true。n - get.bix > 2000 或 get.mit == true 或 get.tak == true,自 aPivH 移除並刪除暫存線條句柄。步驟 3:逐一掃描低點池 aPivL(完全鏡像對稱)
not get.brk):
close[n] < get.prc:not oW 時設 get.brk := true;oW 時設 get.mit := true。not oO and not get.wic 且滿足:
low[n] < get.prc AND close[n] > get.prc觸發看漲影線掃蕩(Wick Bullish Sweep,
d = -1):畫水平點線 (get.bix, get.prc) → (n, get.prc)、垂直粗線及 Sweep Area 方框 [y2, y1] = [low[n], get.prc]、對側 3 棒點線 (n, high[n]) → (n + 3, high[n]),並設 get.wic := true。get.brk == true):
close[n] > get.prc:設 get.mit := true。not oW 且滿足 high[n] > get.prc AND close[n] < get.prc:觸發看跌突破回踩掃蕩(d = 1),畫水平虛線、方框 [get.prc, high[n]],於 low[n] 畫 3 棒點線,置 get.tak := true。n - get.bix > 2000 或 get.mit == true 或 get.tak == true,自 aPivL 移除。步驟 4:Sweep Area 方框延伸與失效停止(Mitigation)
若 extend == true,對 aBoxBr 中每個尚未失效(not bx.br)且 n - bx.bx.get_left() - 1 <= maxB 的方框執行:
bx.bx.set_right(bar_index)。bx.dr == -1):若 close[n] < bx.bx.get_bottom()(即收盤跌破該次掃蕩影線最低點),置 bx.br := true,停止延伸。bx.dr == 1):若 close[n] > bx.bx.get_top()(即收盤漲破該次掃蕩影線最高點),置 bx.br := true,停止延伸。附註(原碼實測邊界特性):
barstate.isconfirmed,K 線未收線前會以即時價格計算;這亦解釋為何原帖主強調「實体が戻って確定したらエントリー」(等收盤確定)。alertcondition() 或 alert()。method p(piv, val) => (100 / piv.prc * val) - 100(計算相對百分比偏離),但執行段未調用。TradingViewのインジケーターから「Liquidity Sweeps [LuxAlgo]」を表示する。「TeamViewer」屬讀音/字面誤聽。https://www.tradingview.com/script/JRqryeJ5-Liquidity-Sweeps-LuxAlgo/(標示 OPEN-SOURCE SCRIPT,2024-02-08 發布)。CC BY-NC-SA 4.0),免費帳戶亦可在 TradingView 圖表搜尋 Liquidity Sweeps [LuxAlgo] 直接掛上圖表,並可點「Source code」查閱/複製全部代碼。https://www.luxalgo.com/library/indicator/liquidity-sweeps/ 亦標明免費使用(Free to use)及支援複製 Pine Script 源碼。https://lin.ee/yx9eCqY)加 LINE 可領取「5年回測、無馬丁/無ナンピン」EA;本席未加入該 LINE、未取得或審計該第三方 EA 檔,對該 EA 是否使用同一指標或其安全性標記為未驗證。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(無外連資源)。