Liquidity Heatmap (Nephew_Sam_)

nephew_sam_ · study · 224 行 · 点赞 11,079 · TradingView 原页

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

Pine Script

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Nephew_Sam_
 
 
//@version=5
indicator('Liquidity Heatmap (Nephew_Sam_)', overlay=true, max_bars_back=500, max_lines_count=500, max_boxes_count=500, max_labels_count=500)
 
// --------------- INPUTS ---------------
var GRP1 = "•••••••••• Timeframe 1 ••••••••••"
timeframe1Show = input.bool(true, title='', inline='1', group=GRP1)
timeframe1 = input.timeframe('15', title='', inline='1', group=GRP1)
leftBars1 = input.int(defval=7, title='Left', minval=2, maxval=20, group=GRP1, inline='1')
rightBars1 = input.int(defval=7, title='Right', minval=2, maxval=20, group=GRP1, inline='1', tooltip="Highest/lowest point in x right and left bars.")
 
topColor1 = input.color(color.new(color.red, 70), "Top", group = GRP1, inline="3")
bottomColor1 = input.color(color.new(color.green, 70), "Bottom", group = GRP1, inline="3")
lineLength1 = input.int(6, 'Length', minval=1, maxval=100, group = GRP1, inline="3")
 
var GRP2 = "•••••••••• Timeframe 2 ••••••••••"
timeframe2Show = input.bool(true, title='', inline='1', group=GRP2)
timeframe2 = input.timeframe('30', title='', inline='1', group=GRP2)
leftBars2 = input.int(defval=7, title='Left', minval=2, maxval=20, group=GRP2, inline='1')
rightBars2 = input.int(defval=7, title='Right', minval=2, maxval=20, group=GRP2, inline='1', tooltip="Highest/lowest point in x right and left bars.")
 
topColor2 = input.color(color.new(color.red, 60), "Top", group = GRP2, inline="3")
bottomColor2 = input.color(color.new(color.green, 60), "Bottom", group = GRP2, inline="3")
lineLength2 = input.int(10, 'Length', minval=1, maxval=100, group = GRP2, inline="3")
 
var GRP3 = "•••••••••• Timeframe 3 ••••••••••"
timeframe3Show = input.bool(true, title='', inline='1', group=GRP3)
timeframe3 = input.timeframe('60', title='', inline='1', group=GRP3)
leftBars3 = input.int(defval=7, title='Left', minval=2, maxval=20, group=GRP3, inline='1')
rightBars3 = input.int(defval=6, title='Right', minval=2, maxval=20, group=GRP3, inline='1', tooltip="Highest/lowest point in x right and left bars.")
 
topColor3 = input.color(color.new(color.red, 50), "Top Color", group = GRP3, inline="3")
bottomColor3 = input.color(color.new(color.green, 50), "Bottom", group = GRP3, inline="3")
lineLength3 = input.int(10, 'Length', minval=1, maxval=100, group = GRP3, inline="3")
 
var GRP4 = "•••••••••• Timeframe 4 ••••••••••"
timeframe4Show = input.bool(true, title='', inline='1', group=GRP4)
timeframe4 = input.timeframe('120', title='', inline='1', group=GRP4)
leftBars4 = input.int(defval=7, title='Left', minval=2, maxval=20, group=GRP4, inline='1')
rightBars4 = input.int(defval=7, title='Right', minval=2, maxval=20, group=GRP4, inline='1', tooltip="Highest/lowest point in x right and left bars.")
 
topColor4 = input.color(color.new(color.red, 40), "Top Color", group = GRP4, inline="3")
bottomColor4 = input.color(color.new(color.green, 40), "Bottom", group = GRP4, inline="3")
lineLength4 = input.int(10, 'Length', minval=1, maxval=100, group = GRP4, inline="3")
 
var GRP5 = "•••••••••• Timeframe 5 ••••••••••"
timeframe5Show = input.bool(true, title='', inline='1', group=GRP5)
timeframe5 = input.timeframe('240', title='', inline='1', group=GRP5)
leftBars5 = input.int(defval=7, title='Left', minval=2, maxval=20, group=GRP5, inline='1')
rightBars5 = input.int(defval=7, title='Right', minval=2, maxval=20, group=GRP5, inline='1', tooltip="Highest/lowest point in x right and left bars.")
 
topColor5 = input.color(color.new(color.red, 30), "Top Color", group = GRP5, inline="3")
bottomColor5 = input.color(color.new(color.green, 30), "Bottom", group = GRP5, inline="3")
lineLength5 = input.int(15, 'Length', minval=1, maxval=100, group = GRP5, inline="3")
 
var GRP6 = "•••••••••• Timeframe 6 ••••••••••"
timeframe6Show = input.bool(true, title='', inline='1', group=GRP6)
timeframe6 = input.timeframe('D', title='', inline='1', group=GRP6)
leftBars6 = input.int(defval=5, title='Left', minval=2, maxval=20, group=GRP6, inline='1')
rightBars6 = input.int(defval=5, title='Right', minval=2, maxval=20, group=GRP6, inline='1', tooltip="Highest/lowest point in x right and left bars.")
 
topColor6 = input.color(color.new(color.red, 20), "Top Color", group = GRP6, inline="3")
bottomColor6 = input.color(color.new(color.green, 20), "Bottom", group = GRP6, inline="3")
lineLength6 = input.int(15, 'Length', minval=1, maxval=100, group = GRP6, inline="3")
 
 
var GRP7 = "•••••••••• Other Settings ••••••••••"
hideLTF = input.bool(true, "Hide lines lower than enabled timeframes?", group = GRP7)
// --------------- INPUTS ---------------
 
 
// --------------- FUNCTIONS ---------------
getPivotData(lb, rb) =>
    ph = ta.pivothigh(lb, rb)
    phtimestart = ph ? time[rb] : na
    
    pl = ta.pivotlow(lb, rb)
    pltimestart = pl ? time[rb] : na
    
    [ph, phtimestart, pl, pltimestart]
 
getLineStyle(_style) =>
    _linestyle = _style == "Solid" ? line.style_solid : _style == "Dashed" ? line.style_dashed : line.style_dotted
    _linestyle
 
resolutionInMinutes(tf = "") =>
    chartTf = timeframe.multiplier * (timeframe.isseconds ? 1. / 60 : timeframe.isminutes ? 1. : timeframe.isdaily ? 60. * 24 : timeframe.isweekly ? 60. * 24 * 7 : timeframe.ismonthly ? 60. * 24 * 30.4375 : na)
    float result = tf == "" ? chartTf : request.security(syminfo.tickerid, tf, chartTf)
 
f_timeFrom(length, _units) =>
    int _timeFrom = na
    _unit = str.replace_all(_units, 's', '')
    _timeFrom := int(time + resolutionInMinutes() * 60 * 1000 * length)
    _timeFrom
 
notLowerTimeframe(tf) =>
    _cond = hideLTF ? resolutionInMinutes() < resolutionInMinutes(tf) : true
    _cond
 
 
//  ▓ ▒ ░ ░ 
 
generateText(_n = 5, _large = false) =>
    _symbol = "░"  
    _text = ""
    for i = _n to 0
        _text := _text + " "
    for i = _n to 0
        _text := _text + _symbol
    if _large
        _text := _text + "\n" + _text
 
    _text
// --------------- FUNCTIONS ---------------
 
 
// --------------- Calculate Pivots ---------------
[phchart, phtimestartchart, plchart, pltimestartchart] = request.security(syminfo.tickerid, "5", getPivotData(6, 6), lookahead = barmerge.lookahead_on)
[ph1, phtimestart1, pl1, pltimestart1] = request.security(syminfo.tickerid, timeframe1, getPivotData(leftBars1, rightBars1), lookahead = barmerge.lookahead_on)
[ph2, phtimestart2, pl2, pltimestart2] = request.security(syminfo.tickerid, timeframe2, getPivotData(leftBars2, rightBars2), lookahead = barmerge.lookahead_on)
[ph3, phtimestart3, pl3, pltimestart3] = request.security(syminfo.tickerid, timeframe3, getPivotData(leftBars3, rightBars3), lookahead = barmerge.lookahead_on)
[ph4, phtimestart4, pl4, pltimestart4] = request.security(syminfo.tickerid, timeframe4, getPivotData(leftBars4, rightBars4), lookahead = barmerge.lookahead_on)
[ph5, phtimestart5, pl5, pltimestart5] = request.security(syminfo.tickerid, timeframe5, getPivotData(leftBars5, rightBars5), lookahead = barmerge.lookahead_on)
[ph6, phtimestart6, pl6, pltimestart6] = request.security(syminfo.tickerid, timeframe6, getPivotData(leftBars6, rightBars6), lookahead = barmerge.lookahead_on)
 
pivothighchart = na(phchart[1]) and phchart ? phchart : na
pivotlowchart  = na(plchart[1]) and plchart ? plchart : na
 
pivothigh1 = na(ph1[1]) and ph1 ? ph1 : na
pivotlow1  = na(pl1[1]) and pl1 ? pl1 : na
 
pivothigh2 = na(ph2[1]) and ph2 ? ph2 : na
pivotlow2  = na(pl2[1]) and pl2 ? pl2 : na
 
pivothigh3 = na(ph3[1]) and ph3 ? ph3 : na
pivotlow3  = na(pl3[1]) and pl3 ? pl3 : na
 
pivothigh4 = na(ph4[1]) and ph4 ? ph4 : na
pivotlow4  = na(pl4[1]) and pl4 ? pl4 : na
 
pivothigh5 = na(ph5[1]) and ph5 ? ph5 : na
pivotlow5  = na(pl5[1]) and pl5 ? pl5 : na
 
pivothigh6 = na(ph6[1]) and ph6 ? ph6 : na
pivotlow6  = na(pl6[1]) and pl6 ? pl6 : na
// --------------- Calculate Pivots ---------------
 
//  --------------- Add to array ---------------
var float[] pivothighs1 = array.new_float(0)
var float[] pivotlows1 = array.new_float(0)
 
var float[] pivothighs2 = array.new_float(0)
var float[] pivotlows2 = array.new_float(0)
 
var float[] pivothighs3 = array.new_float(0)
var float[] pivotlows3 = array.new_float(0)
 
var float[] pivothighs4 = array.new_float(0)
var float[] pivotlows4 = array.new_float(0)
 
var float[] pivothighs5 = array.new_float(0)
var float[] pivotlows5 = array.new_float(0)
 
var float[] pivothighs6 = array.new_float(0)
var float[] pivotlows6 = array.new_float(0)
//  --------------- Add to array ---------------
 
 
// --------------- Plot pivot points ---------------
// if barstate.islast
//     label.new(bar_index, high, str.tostring(resolutionInMinutes()) +"\n"+ str.tostring(resolutionInMinutes("3")))
 
// Timeframe m5
if timeframe1Show and pivothighchart and resolutionInMinutes() <= resolutionInMinutes("3")
    label.new(phtimestartchart, phchart, xloc=xloc.bar_time, text=generateText(12), style=label.style_none, textcolor=topColor1)
if timeframe1Show and pivotlowchart and resolutionInMinutes() <= resolutionInMinutes("3")
    label.new(pltimestartchart, plchart, xloc=xloc.bar_time, text=generateText(12), style=label.style_none, textcolor=bottomColor1)
 
// Timeframe 1
if timeframe1Show and pivothigh1 and notLowerTimeframe(timeframe1)
    label.new(phtimestart1, ph1, xloc=xloc.bar_time, text=generateText(lineLength1), style=label.style_none, textcolor=topColor1)
if timeframe1Show and pivotlow1 and notLowerTimeframe(timeframe1)
    label.new(pltimestart1, pl1, xloc=xloc.bar_time, text=generateText(lineLength1), style=label.style_none, textcolor=bottomColor1)
 
// Timeframe 2
if timeframe2Show and pivothigh2 and notLowerTimeframe(timeframe2)
    label.new(phtimestart2, ph2, xloc=xloc.bar_time, text=generateText(lineLength2), style=label.style_none, textcolor=topColor2)
if timeframe2Show and pivotlow2 and notLowerTimeframe(timeframe2)
    label.new(pltimestart2, pl2, xloc=xloc.bar_time, text=generateText(lineLength2), style=label.style_none, textcolor=bottomColor2)
 
// Timeframe 3
if timeframe3Show and pivothigh3 and notLowerTimeframe(timeframe3)
    label.new(phtimestart3, ph3, xloc=xloc.bar_time, text=generateText(lineLength3), style=label.style_none, textcolor=topColor3)
if timeframe3Show and pivotlow3 and notLowerTimeframe(timeframe3)
    label.new(pltimestart3, pl3, xloc=xloc.bar_time, text=generateText(lineLength3), style=label.style_none, textcolor=bottomColor3)
 
// Timeframe 4
if timeframe4Show and pivothigh4 and notLowerTimeframe(timeframe4)
    label.new(phtimestart4, ph4, xloc=xloc.bar_time, text=generateText(lineLength4), style=label.style_none, textcolor=topColor4)
if timeframe4Show and pivotlow4 and notLowerTimeframe(timeframe4)
    label.new(pltimestart4, pl4, xloc=xloc.bar_time, text=generateText(lineLength4), style=label.style_none, textcolor=bottomColor4)
 
// Timeframe 5
if timeframe5Show and pivothigh5 and notLowerTimeframe(timeframe5)
    label.new(phtimestart5, ph5, xloc=xloc.bar_time, text=generateText(lineLength5, true), style=label.style_none, textcolor=topColor5)
if timeframe5Show and pivotlow5 and notLowerTimeframe(timeframe5)
    label.new(pltimestart5, pl5, xloc=xloc.bar_time, text=generateText(lineLength5, true), style=label.style_none, textcolor=bottomColor5)
 
// Timeframe 6
if timeframe6Show and pivothigh6 and notLowerTimeframe(timeframe6)
    label.new(phtimestart6, ph6, xloc=xloc.bar_time, text=generateText(lineLength6, true), style=label.style_none, textcolor=topColor6)
if timeframe6Show and pivotlow6 and notLowerTimeframe(timeframe6)
    label.new(pltimestart6, pl6, xloc=xloc.bar_time, text=generateText(lineLength6, true), style=label.style_none, textcolor=bottomColor6)
 
// --------------- Plot pivot points ---------------
 
 
// WATERMARK
if barstate.islast    
    _table = table.new("bottom_left", 1, 1)
    table.cell(_table, 0, 0, text="@Nephew_Sam_", text_size=size.small, text_color=color.new(color.gray, 50))

← 返回列表