← К каталогу
Исходный код · ID 4879

Nambou FVG Radar

indicator nambou fvg radar fair value gaps with live fill tracking for tradingview.pine
Вы автор или правообладатель?

Сообщите нам, если считаете, что материал размещён без разрешения.

Краткий обзор

О программе

Индикатор Nambou FVG Radar предназначен для обнаружения и визуализации зон справедливой стоимости (Fair Value Gaps) на ценовых графиках. Он автоматически определяет бычьи и медвежьи разрывы, отслеживает степень их заполнения ценой и отображает зоны в виде цветных прямоугольников с информацией о текущем состоянии.

Индикатор поддерживает анализ как текущего таймфрейма, так и более высоких через запрос данных с других инструментов и периодов, что позволяет видеть значимые разрывы с разных уровней. Зоны отображаются с текстовыми метками, показывающими процент заполнения, а также центральной пунктирной линией разрыва.

Встроенная таблица отображает список ближайших разрывов по обе стороны от цены с информацией о расстоянии до цены и состоянии. Доступны настраиваемые оповещения на формирование новых разрывов, достижение ценой зоны, удержание, полное заполнение и пробой за пределы разрыва.

Настройки программы

НастройкаОписание
minAtr Игнорировать разрывы меньше указанного значения ATR (средний истинный диапазон последних 14 баров); ноль — отслеживать все
maxN Максимальное количество отслеживаемых открытых разрывов на каждую сторону
mergeOn Объединять разрыв с предыдущим, если сильное движение оставило разрыв на нескольких барах подряд
keepFilled Сохранять разрыв после полного заполнения: включено — до закрытия бара за дальним краем, выключено — удаление сразу при достижении края
htfIn Отслеживать разрывы с указанного более высокого таймфрейма или автоматически выбирать следующий вверх
maxH Максимальное количество отслеживаемых разрывов высокого таймфрейма на каждую сторону
extBars Зоны продлеваются на указанное количество баров после последнего бара для отображения
showText Показывать текст с информацией о разрыве и степени заполнения внутри каждой зоны
showCE Показывать пунктирную линию в середине каждого разрыва, как она была при формировании
showMarks Отмечать первое удержание каждого разрыва меткой на графике — когда бар достигает зоны и закрывается обратно
showTable Показывать таблицу с информацией о разрывах
rowsN Количество разрывов, отображаемых в таблице с каждой стороны от цены
showGone Показывать пробитые и удалённые разрывы в таблице
tablePosIn Положение таблицы разрывов на графике
txtSizeIn Размер текста в таблице и на зонах
cBull Цвет для бычьих разрывов
cBear Цвет для медвежьих разрывов
cGone Цвет для пробитых разрывов
cTxt Цвет нейтрального текста в таблице и на зонах
aNew Оповещение при формировании нового разрыва
aEnter Оповещение при первом достижении ценой разрыва
aHold Оповещение при первом удержании разрыва — когда бар достигает зоны и закрывается обратно с той же стороны
aFill Оповещение при полном заполнении разрыва
aBreak Оповещение при закрытии бара за пределами разрыва

Поиск по коду файла

indicator("Nambou FVG Radar", "FVG Radar", overlay = true, max_boxes_count = 500, max_lines_count = 500, max_labels_count = 500, max_bars_back = 1000)

gG = "Gaps"
minAtr     = input.float(0.3, "Ignore gaps smaller than this many ATR", minval = 0.0, maxval = 5.0, step = 0.05, group = gG, tooltip = "ATR is the average true range of the last 14 bars. 0 keeps every gap.")
maxN       = input.int(8, "Max open gaps tracked per side", minval = 1, maxval = 40, group = gG)
mergeOn    = input.bool(true, "Merge a gap into the one formed just before it", group = gG, tooltip = "A strong move can leave a gap on several bars in a row. Merged, they show as one zone.")
keepFilled = input.bool(true, "Keep a gap after it is completely filled", group = gG, tooltip = "On keeps a filled gap until a bar closes beyond its far edge. Off removes it as soon as price reaches that edge.")

gH = "Higher-timeframe gaps"
htfIn = input.string("Auto", "Also track gaps from", options = ["Auto", "Off", "1H", "4H", "Daily", "Weekly"], group = gH, tooltip = "Auto picks the next timeframe up: 1H on charts below one hour, 4H on 1H to 3H, Daily on 4H to 12H, Weekly on Daily. A gap is added when its higher-timeframe bar has closed, so it never repaints.")
maxH  = input.int(4, "Max higher-timeframe gaps tracked per side", minval = 1, maxval = 20, group = gH)

gD = "Display"
extBars    = input.int(25, "Zones run this many bars past the last bar", minval = 1, maxval = 200, group = gD, tooltip = "Higher-timeframe zones run 24 bars further, so their text sits beyond the others.")
showText   = input.bool(true, "Write the gap and how much of it is filled inside each zone", group = gD)
showCE     = input.bool(true, "Show the middle of each gap", group = gD, tooltip = "A dashed line halfway through the gap, as it was when it formed.")
showMarks  = input.bool(true, "Mark the first time each gap holds", group = gD, tooltip = "A gap holds when a bar reaches it and closes back out of it on the side it was approached from. Only the first hold is marked; the table counts them all.")
showTable  = input.bool(true, "Show the gap table", group = gD)
rowsN      = input.int(8, "Table: gaps listed on each side of the price", minval = 1, maxval = 40, group = gD, tooltip = "The nearest gaps above and below the price.")
showGone   = input.bool(false, "List broken and removed gaps in the table", group = gD)
tablePosIn = input.string("Auto", "Table position", options = ["Auto", "Top center", "Bottom center", "Top right", "Bottom right", "Bottom left", "Top left"], group = gD, tooltip = "Auto looks at the left, middle and right of the visible chart and puts the table at the top or the bottom where the candles leave the most room.")
txtSizeIn  = input.string("Small", "Text size", options = ["Tiny", "Small", "Normal"], group = gD)
cBull = input.color(#00E5A0, "Bullish gaps", group = gD)
cBear = input.color(#FF3D71, "Bearish gaps", group = gD)
cGone = input.color(#787B86, "Broken gaps", group = gD)
cTxt  = input.color(#D1D4DC, "Neutral text", group = gD)

gA = "Alerts"
aNew   = input.bool(false, "Alert when a new gap forms", group = gA)
aEnter = input.bool(true, "Alert when price first reaches a gap", group = gA)
aHold  = input.bool(true, "Alert the first time a gap holds", group = gA, tooltip = "A gap holds when a bar reaches it and closes back out of it on the side it was approached from.")
aFill  = input.bool(true, "Alert when a gap is completely filled", group = gA)
aBreak = input.bool(true, "Alert when a bar closes beyond a gap", group = gA)

txtSize = txtSizeIn == "Tiny" ? size.tiny : txtSizeIn == "Normal" ? size.normal : size.small

type Gap
    float top
    float bot
    float reach
    box   bx
    box   gh
    line  ce
    int   x1
    bool  bull
    int   born
    int   st     = 0
    int   ev     = 0
    int   holds  = 0
    bool  inside = false
    int   touch  = -2
    bool  heldVisit = false
    string tf = ""

var array<Gap> bulls = array.new<Gap>()
var array<Gap> bears = array.new<Gap>()
var array<Gap> gone  = array.new<Gap>()
var array<Gap> hBulls = array.new<Gap>()
var array<Gap> hBears = array.new<Gap>()

atr = ta.atr(14)

col(Gap g) => g.bull ? cBull : cBear

zoneText(Gap g) => str.tostring(g.bot, format.mintick) + " to " + str.tostring(g.top, format.mintick)

kind(Gap g) => (g.bull ? "bullish " : "bearish ") + (g.tf != "" ? g.tf + " " : "") + "gap"

fillPct(Gap g) =>
    float h = g.top - g.bot
    h <= 0 ? 0.0 : g.bull ? (g.top - math.max(g.reach, g.bot)) / h * 100.0 : (math.min(g.reach, g.top) - g.bot) / h * 100.0

paint(Gap g) =>
    color c = col(g)
    if g.st == 2
        box.set_top(g.bx, g.top)
        box.set_bottom(g.bx, g.bot)
        box.set_bgcolor(g.bx, color.new(c, 90))
        box.set_border_color(g.bx, color.new(c, 45))
        box.set_border_style(g.bx, line.style_dashed)
        box.set_bgcolor(g.gh, color.new(c, 100))
        box.set_border_color(g.gh, color.new(c, 100))
    else
        float edge = g.bull ? math.max(g.reach, g.bot) : math.min(g.reach, g.top)
        box.set_top(g.bx, g.bull ? edge : g.top)
        box.set_bottom(g.bx, g.bull ? g.bot : edge)
        box.set_bgcolor(g.bx, color.new(c, 70))
        box.set_border_color(g.bx, color.new(c, 20))
        box.set_border_style(g.bx, line.style_solid)
        box.set_top(g.gh, g.bull ? g.top : edge)
        box.set_bottom(g.gh, g.bull ? edge : g.bot)
        box.set_bgcolor(g.gh, color.new(c, g.st == 1 ? 92 : 100))
        box.set_border_color(g.gh, color.new(c, g.st == 1 ? 70 : 100))

retire(Gap g) =>
    if g.tf == ""
        box.set_right(g.bx, bar_index)
    else
        box.set_right(g.bx, time)
    box.set_top(g.bx, g.top)
    box.set_bottom(g.bx, g.bot)
    box.set_text(g.bx, "")
    box.set_bgcolor(g.bx, color.new(cGone, 90))
    box.set_border_color(g.bx, color.new(cGone, 60))
    box.set_border_style(g.bx, line.style_dotted)
    box.delete(g.gh)
    if not na(g.ce)
        line.delete(g.ce)
    gone.push(g)
    while gone.size() > maxN * 2
        Gap old = gone.shift()
        box.delete(old.bx)

drop(Gap g) =>
    box.delete(g.bx)
    box.delete(g.gh)
    if not na(g.ce)
        line.delete(g.ce)

add(array<Gap> a, bool bull, float top, float bot, string tf, int lt) =>
    bool merged = false
    if mergeOn and tf == "" and a.size() > 0
        Gap last = a.last()
        if last.st == 0 and bar_index - last.born <= 1 and bot <= last.top and top >= last.bot
            last.top := math.max(last.top, top)
            last.bot := math.min(last.bot, bot)
            last.reach := bull ? last.top : last.bot
            last.born := bar_index
            paint(last)
            if not na(last.ce)
                float m = (last.top + last.bot) / 2.0
                line.set_y1(last.ce, m)
                line.set_y2(last.ce, m)
            merged := true
    if not merged
        color c = bull ? cBull : cBear
        float m = (top + bot) / 2.0
        bool hi = tf != ""
        int x0 = hi ? lt : bar_index - 1
        int x9 = hi ? time : bar_index
        string xl = hi ? xloc.bar_time : xloc.bar_index
        box b = box.new(x0, top, x9, bot, border_color = color.new(c, 20), border_width = hi ? 2 : 1, bgcolor = color.new(c, 70), text_halign = text.align_right, text_valign = text.align_center, text_size = txtSize, xloc = xl)
        box gb = box.new(x0, top, x9, top, border_color = color.new(c, 100), bgcolor = color.new(c, 100), xloc = xl)
        line l = showCE ? line.new(x0, m, x9, m, color = color.new(c, 40), style = line.style_dashed, width = 1, xloc = xl) : na
        Gap g = Gap.new(top, bot, bull ? top : bot, b, gb, l, x0, bull, bar_index)
        g.tf := tf
        a.push(g)
        while a.size() > (hi ? maxH : maxN)
            drop(a.shift())
        if aNew
            alert("FVG Radar: " + syminfo.ticker + " formed a " + (bull ? "bullish " : "bearish ") + (hi ? tf + " " : "") + "gap, " + str.tostring(bot, format.mintick) + " to " + str.tostring(top, format.mintick), alert.freq_once_per_bar_close)

scan(array<Gap> a) =>
    bool held = false
    int i = 0
    while i < a.size()
        Gap g = a.get(i)
        bool removed = false
        if g.born < bar_index
            bool reached = g.bull ? low <= g.top : high >= g.bot
            if reached
                g.reach := g.bull ? math.min(g.reach, low) : math.max(g.reach, high)
                if bar_index - g.touch > 1
                    g.heldVisit := false
                g.touch := bar_index
                if not g.inside
                    g.inside := true
                    if aEnter
                        alert("FVG Radar: " + syminfo.ticker + " reached the " + kind(g) + " at " + zoneText(g), alert.freq_once_per_bar_close)
                bool broke = g.bull ? close < g.bot : close > g.top
                bool full = g.bull ? low <= g.bot : high >= g.top
                if broke
                    g.st := 3
                    g.ev := bar_index
                    retire(g)
                    a.remove(i)
                    removed := true
                    if aBreak
                        alert("FVG Radar: " + syminfo.ticker + " closed beyond the " + kind(g) + " at " + zoneText(g), alert.freq_once_per_bar_close)
                else
                    if full and g.st < 2
                        g.st := 2
                        g.ev := bar_index
                        if aFill
                            alert("FVG Radar: " + syminfo

Показано первые 50% кода (символов: 13130)