FVG Low Momentum Volume Stats

edwinardyanto · study · 114 行 · 点赞 4 · TradingView 原页

本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。

Pine Script

//@version=6
// FVG Low Momentum + Volume — penanda & statistik — @edwinardyanto (Reels seri 3 "cara terbaik", 23 Okt 2026)
// FVG naik: low candle 3 > high candle 1, candle 2 hijau. "Low momentum" (aturan video viral): badan candle 3 <= 0,5x badan candle 2
// DAN panjang candle 3 <= 0,5x panjang candle 2. Syarat tambahan dari backtest: volume candle 2 >= 1,5x rata-rata 20 candle sebelumnya.
// Masuk: limit di tepi atas gap (low candle 3) kalau harga balik dalam 20 candle. Stop loss: low candle 1. Take profit 3R. Fee 0,1%/sisi.
// Backtest BTCUSDT 4H (1 Jan 2021 - 30 Sep 2026). Panel = hasil di rentang tanggal input (default = data video).
// Bahan belajar, bukan sinyal, bukan ajakan beli/jual.
indicator("FVG Low Momentum Volume Stats", overlay = true, max_labels_count = 500, max_boxes_count = 500)
lm     = input.float(0.5, "Low momentum: candle 3 maks (x candle 2)")
volX   = input.float(1.5, "Volume candle 2 min (x rata-rata)")
lenV   = input.int(20, "Rata-rata volume N candle")
W      = input.int(20, "Tunggu harga balik maks N candle")
rr     = input.float(3.0, "Take profit (R)")
feePct = input.float(0.1, "Fee per sisi (%)")
mulai  = input.time(timestamp("05 Jan 2021 00:00 +0000"), "Mulai backtest")
sampai = input.time(timestamp("01 Oct 2026 00:00 +0000"), "Sampai")
fee = feePct / 100
// ---- buku trade (boleh tumpang tindih, sama dengan backtest Python) ----
type Book
    array<float> e
    array<float> s
    array<float> tp
    array<int> last
    int n = 0
    int win = 0
    float sumR = 0.0
    float gp = 0.0
    float gl = 0.0
 
method add(Book b, float e, float s, float tp, int last) =>
    if e - s > 0
        b.e.push(e)
        b.s.push(s)
        b.tp.push(tp)
        b.last.push(last)
 
method step(Book b, float fee, int sampai) =>
    if b.e.size() > 0
        for q = b.e.size() - 1 to 0
            e = b.e.get(q)
            s = b.s.get(q)
            tp = b.tp.get(q)
            lst = b.last.get(q)
            float R = na
            if low <= s
                R := -1.0
            else if not na(tp) and high >= tp
                R := (tp - e) / (e - s)
            else if not na(lst) and bar_index >= lst
                R := (close - e) / (e - s)
            if not na(R)
                Rn = R - 2 * fee * e / (e - s)
                if time < sampai
                    b.n += 1
                    b.win += Rn > 0 ? 1 : 0
                    b.sumR += Rn
                    b.gp += Rn > 0 ? Rn : 0
                    b.gl += Rn < 0 ? -Rn : 0
                b.e.remove(q)
                b.s.remove(q)
                b.tp.remove(q)
                b.last.remove(q)
 
newBook() => Book.new(array.new<float>(), array.new<float>(), array.new<float>(), array.new<int>())
b2 = math.abs(close[1] - open[1])
r2 = high[1] - low[1]
b3 = math.abs(close - open)
r3 = high - low
isFvg = low > high[2] and close[1] > open[1]
isLm  = b3 <= lm * b2 and r3 <= lm * r2
isVol = volume[1] >= volX * ta.sma(volume, lenV)[2]
sig   = isFvg and isLm and isVol
if sig
    box.new(bar_index - 2, low, bar_index + W, high[2], border_color = color.new(color.orange, 40), bgcolor = color.new(color.orange, 80))
plotshape(sig, "FVG low momentum + volume", shape.labelup, location.belowbar, color.new(color.orange, 0), text = "FVG", textcolor = color.white, size = size.small)
// ---- order limit menunggu ----
var array<float> pTop = array.new<float>()
var array<float> pSl  = array.new<float>()
var array<int>   pBar = array.new<int>()
var book = newBook()
if pTop.size() > 0
    for k = pTop.size() - 1 to 0
        top = pTop.get(k)
        sl  = pSl.get(k)
        b0  = pBar.get(k)
        if bar_index > b0 + W
            pTop.remove(k)
            pSl.remove(k)
            pBar.remove(k)
        else if low <= top
            m = math.min(open, top)
            book.add(m, sl, m + rr * (m - sl), na)
            pTop.remove(k)
            pSl.remove(k)
            pBar.remove(k)
book.step(fee, sampai)
if sig and time >= mulai and time < sampai
    pTop.push(low)
    pSl.push(low[2])
    pBar.push(bar_index)
var table t = table.new(position.top_right, 2, 6, bgcolor = color.new(color.white, 5), border_width = 1)
if barstate.islast
    table.cell(t, 0, 0, "FVG low momentum + volume", text_color = color.black)
    table.cell(t, 1, 0, str.tostring(book.n) + " trade", text_color = color.black)
    table.cell(t, 0, 1, "Win rate (SL candle 1, TP " + str.tostring(rr) + "R)", text_color = color.black)
    table.cell(t, 1, 1, book.n > 0 ? str.tostring(100.0 * book.win / book.n, "#.#") + "%" : "-", text_color = color.green)
    table.cell(t, 0, 2, "Titik impas (tanpa fee)", text_color = color.black)
    table.cell(t, 1, 2, str.tostring(100.0 / (1 + rr), "#.#") + "%", text_color = color.gray)
    table.cell(t, 0, 3, "Total setelah fee", text_color = color.black)
    table.cell(t, 1, 3, (book.sumR >= 0 ? "+" : "") + str.tostring(book.sumR, "#.#") + "R", text_color = book.sumR >= 0 ? color.green : color.red)
    table.cell(t, 0, 4, "Profit factor", text_color = color.black)
    table.cell(t, 1, 4, book.gl > 0 ? str.tostring(book.gp / book.gl, "#.##") : "-", text_color = color.black)
    table.cell(t, 0, 5, "Rata-rata per trade", text_color = color.black)
    table.cell(t, 1, 5, book.n > 0 ? str.tostring(book.sumR / book.n, "#.##") + "R" : "-", text_color = color.black)

← 返回列表