Volume Footprint Voids [StratifyTrade]

BigBeluga · study · 261 行 · 点赞 8,636 · TradingView 原页

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

Pine Script

// 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/
// © StratifyTrade
//@version=5
 
 
indicator(
       "Volume Footprint Voids [StratifyTrade]"
     , "StratifyTrade - Volume Footprint Voids [1.0]"
     , overlay = true
     , max_labels_count = 500
     , max_lines_count = 500
         )
 
 
const string tlM = 
     "[POC] Display point of control of the most closes\n
     [▲▼] Display Delta volume coloring\n
     [▲▼ Gradient] Display Delta gradient volume\n
     [Total Volume] Display net volume color\n
     [POC + Gaps] Display POC and void gaps\n
     [Gaps] Display void gaps only"
 
const string tlL = 
     "The Lot inputs is the ammount of point the script will assign to each candle, 
     this mean that on each candle, the script will assign 0.25 lot size to fit the 
     entire candle untill it fully fit, start with 0.01 and ride your way untill it 
     fit the best size. This is the starting Lot size"
 
const string tlT = 
     "POC/Delta LTF Volume calculation\TIP: To spot volume voids use a close LTF to the 
     main one, for less void, use a smaller LTF"
 
const string tlX =
     "Display Lots size text"
 
 
mode = input.string(
       "POC"
     , "Window    "
     , ["POC", "▲▼", "▲▼ Gradient", "Total Volume", "POC + Gaps", "Gaps"]
     , tlM
     , "mode"
     , "Coloring"
                  )
 
vNH   = input.color   (#f59c1c, "POC       ", inline = "net", group = "Coloring")
vNM   = input.color   (#9f9f9f, "          ", inline = "net", group = "Coloring")
vN0   = input.color   (#5c5c5c, "          ", inline = "net", group = "Coloring")
 
vGUH  = input.color   (#4cc786, "▲▼        ", inline = "grd", group = "Coloring")
vGDN  = input.color   (#cd1d28, "          ", inline = "grd", group = "Coloring")
vGDH  = input.color   (#5c5c5c, "          ", inline = "grd", group = "Coloring")
 
tVM  = input.color    (#f4f4f4, "Total     ", inline = "tvo", group = "Coloring")
tVL  = input.color    (#a8a8aa, "          ", inline = "tvo", group = "Coloring")
tVG  = input.color    (#46454b, "          ", inline = "tvo", group = "Coloring")
 
gPG  = input.color    (#cd1c28, "Gaps      ", inline = "gap", group = "Coloring")
gLV  = input.color    (#9f9f9f, "          ", inline = "gap", group = "Coloring")
gL0  = input.color    (#5c5c5e, "          ", inline = "gap", group = "Coloring")
 
Lot  = input.float    (0.25     , "Size      "                , group = "SETTINGS", tooltip = tlL, minval  = 0.01        , step = 0.01)
LTF  = input.timeframe("5"      , "LTF       "                , group = "SETTINGS", tooltip = tlT                                     )  
plN  = input.string   ("ON"     , "Lots      "                , group = "SETTINGS", tooltip = tlX,             options = ["ON", "OFF"])
 
color css = na
int     i = 0
 
 
type bin
    float[] lvls
    float[] vols
    int  [] lots
 
type voids
    float   top
    float   btm
    int     loc
    color   css
    bool    bull
 
type bar
    float   o = open
    float   h = high
    float   l = low
    float   c = close
    float   v = volume
 
 
bar               b  = bar  .new       ()
bin              ZZ  = bin  .new       (
                       array.new<float>()
                     , array.new<float>()
                     , array.new< int >()
                                       )
var voids[]    void  = array.new<voids>()
 
 
[cL, oP, hI, lO, vO] = request.security_lower_tf(
       ""
     , LTF
     , 
     [
           b.c
         , b.o
         , b.h
         , b.l
         , b.v
         
     ]
                                                 )
 
 
method pos(bin zz, float Lot, int i) =>
    if i == 0
        zz.lvls.unshift(               b.l             )
        zz.lots.unshift(                0              )
        zz.vols.unshift(                0              )
 
    else
        zz.lvls.unshift(b.l + (b.l * ((Lot * i)) / 100))
        zz.lots.unshift(                0              )
        zz.vols.unshift(                0              )
 
    zz.lvls.get(0)
 
 
method puts(bin zz, float c, float o, int x, float v) =>
    switch
        c > o => zz.lots.set(x, zz.lots.get(x) + 1), zz.vols.set(x, zz.vols.get(x) + v)
        c < o => zz.lots.set(x, zz.lots.get(x) + 1), zz.vols.set(x, zz.vols.get(x) - v)
 
 
method dLb(float y, color css, string txt, string size) =>
    label.new(
           x                = bar_index
         , y                = y
         , style            = label.style_label_center
         , color            = #ffffff00
         , textcolor        = css
         , text             = txt
         , size             = size
         , xloc             = xloc.bar_index
         , text_font_family = font.family_monospace
             )
 
 
while b.h > ZZ.pos(Lot, i)
    i   += 1
 
 
if ZZ.lvls.size() > 1
    for x = 0 to ZZ.lvls.size() - 1
        for [id, c] in cL
            o    = oP     .get( id )
            h    = hI     .get( id )
            l    = lO     .get( id )
            v    = vO     .get( id )
            lots = ZZ.lots.get( x  )
            lvls = ZZ.lvls.get( x  )
            switch
                x                             == 0 =>
                    if                     h > ZZ.lvls.get ( x + 1 )
                        ZZ                         .puts(c, o, x, v)
                        
                x != 0 and x != ZZ.lvls.size() - 1 =>
                    if c < ZZ.lvls.get(x - 1) and c > ZZ.lvls.get(x)
                        ZZ                         .puts(c, o, x, v)  
 
                x             == ZZ.lvls.size() - 1 =>
                    if                        l < ZZ.lvls.get(x - 1)
                        ZZ                         .puts(c, o, x, v)       
 
 
if ZZ.lvls.size() > 1
    for x = 0 to ZZ.lvls.size() - 1 
        if ZZ.lvls.get(x) <= b.h
            lots = ZZ.lots.get(x)
            lvls = ZZ.lvls.get(x)
            vols = ZZ.vols.get(x)
 
            switch mode
                "POC"          => css := lots <= ZZ.lots.avg() ? vN0  : lots != 0 and lots != ZZ.lots.max() and lots >= ZZ.lots.avg() ? vNM  : lots == ZZ.lots.max() ? vNH  : vN0
                "▲▼"           => css := lots == 0             ? vGDH : vols  > 0                                                     ? vGUH : vols < 0              ? vGDN : na
                "POC + Gaps"   => css := lots == ZZ.lots.max() ? vNH  : lots == 0                                                     ? vN0  : vNM
                "Gaps"         => css := lots == ZZ.lots.max() ? gL0  : lots == 0                                                     ? gPG  : gLV
                "▲▼ Gradient"  => css :=                                                          color.from_gradient(vols, ZZ.vols.min()      , ZZ.vols.max()      , vGDN, vGUH)
                "Total Volume" => css :=                                                          color.from_gradient(vols, ZZ.vols.abs().min(), ZZ.vols.abs().max(), tVL , tVM )
 
            if plN == "ON"
                lvls.dLb (
                     chart.fg_color
                     , 
                         str.tostring(lots) + 
                         (
                         str.length(str.tostring(lots)) == 1 
                         ? "    " 
                         : str.length(str.tostring(lots)) == 2 
                         ? "     " 
                         : "      "
                         )
 
                     , size.small
                         )
 
            if mode != "POC + Gaps" and mode != "Gaps" and mode != "Total Volume"
 
                if lots <= ZZ.lots.avg()
                    lvls.dLb                         (css, "▉"     , size.small)
 
                if lots != 0 and lots != ZZ.lots.max() and lots >= ZZ.lots.avg()
                    lvls.dLb                         (css, "▉"      , size.small)
                    lvls.dLb                         (css, "   ▉"   , size.small)
 
                if lots == ZZ.lots.max()
                    lvls.dLb                         (css, "▉"      , size.small)
                    lvls.dLb                         (css, "   ▉"   , size.small)
                    lvls.dLb                         (css, "      ▉", size.small)
 
            if mode == "POC + Gaps"
 
                if lots > 0 and lots < ZZ.lots.max()
                    lvls.dLb                         (css, "▉"      , size.small)
 
                if lots == 0
                    lvls.dLb                         (css, "▉"      , size.small)
                    lvls.dLb                         (css, "   ▉"   , size.small)
                    lvls.dLb                         (css, "      ▉", size.small)
 
                if lots == ZZ.lots.max()
                    lvls.dLb                         (css, "▉"      , size.small)
                    lvls.dLb                         (css, "   ▉"   , size.small)
                    lvls.dLb                         (css, "      ▉", size.small)
 
            if mode == "Gaps"
 
                if lots != 0 and lots != ZZ.lots.max()
                    lvls.dLb                         (css, "▉"      , size.small)
                    lvls.dLb                         (css, "   ▉"   , size.small)
 
                if lots == 0
                    lvls.dLb                         (css, "▉"      , size.small)
                    lvls.dLb                         (css, "   ▉"   , size.small)
                    lvls.dLb                         (css, "      ▉", size.small)
 
                if lots == ZZ.lots.max()
                    lvls.dLb                         (css, "▉"      , size.small)
 
            if mode == "Total Volume"
 
                if vols > ZZ.vols.abs().avg() and vols != ZZ.vols.abs().max()
                    lvls.dLb                         (css, "▉"      , size.small)
                    lvls.dLb                         (css, "   ▉"   , size.small)
 
                if vols == ZZ.vols.abs().max()
                    lvls.dLb                         (css, "▉"      , size.small)
                    lvls.dLb                         (css, "   ▉"   , size.small)
                    lvls.dLb                         (css, "      ▉", size.small)
 
                if vols < ZZ.vols.abs().avg() and vols != ZZ.vols.abs().max()
                    lvls.dLb                         (css, "▉"      , size.small)

← 返回列表