Liquidity Heatmap Script
Creado el: 10 de enero de 2025
Creado el: 10 de enero de 2025
Evaluating Pine Script
I'm thinking through a Pine Script code for TradingView. The code looks at pivot highs and pivot lows across multiple timeframes. The user might need explanations, debugging, or help with potential errors.
Assessing Pine Script validity
I'm validating the Pine Script for TradingView V6, ensuring it checks pivot highs and lows across various timeframes. The user might need a bug fix or a finalized version.
Figuring out the details
The user posted a Pine Script code snippet for a Liquidity Heatmap indicator in TradingView. It ends with a watermark and likely needs a review or compiling instructions.
Laying out the options
The user likely needs a code analysis or explanation, rather than asking for something specific. I might suggest a valid final code snippet for them.
Thought about liquidity heatmap script pendant 9 secondes
Below is the code you provided, with commentary on how it works and what you need to watch out for when using it in TradingView (Pine Script v6). Although you mentioned that all inputs remain unchanged (i.e., the input(...)
declarations in the original script), keep in mind that these references must exist somewhere in your full code for the script to compile successfully on TradingView.
If you’ve simply omitted the inputs here for brevity, you can insert them back in as-is. If, however, you’re trying to build a minimal example, make sure you declare and initialize all variables and settings that are referenced (like ltimeframe1
, lineLength1
, hideLTF
, etc.) before using them.
// 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=6 indicator('Liquidity Heatmap (Nephew_Sam_)', overlay=true, max_bars_back=500, max_lines_count=500, max_boxes_count=500, max_labels_count=500) // ----------------------------------------------------------------------------- // 1. INPUTS SECTION // ----------------------------------------------------------------------------- // NOTE: The full script presumably has `input(...)` declarations here such as: // - ltimeframe1, lleftBars1, lrightBars1, htimeframe1, hleftBars1, hrightBars1 // - topColor1, bottomColor1, lineLength1, etc. // - hideLTF, ltimeframe1Show, htimeframe1Show, etc. // // They are crucial for the script’s operation. If you're missing them, re-insert // or create them so the references below don’t break. // ----------------------------------------------------------------------------- // 2. UTILITY FUNCTIONS // Returns chart resolution in minutes. If `tf` (timeframe) is given, requests it on security(). 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) // Helper function: returns a time offset in ms from current time // based on 'length' and '_units'. f_timeFrom(length, _units) => int _timeFrom = na _unit = str.replace_all(_units, 's', '') _timeFrom := int(time + resolutionInMinutes() * 60 * 1000 * length) _timeFrom // If `hideLTF` is true, checks whether current resolution is smaller // than the requested `tf`. If smaller, returns false. notLowerTimeframe(tf) => _cond = hideLTF ? resolutionInMinutes() < resolutionInMinutes(tf) : true _cond // Generates text used for labels generateText(_n = 5, _large = false) => _symbol = "░" _text = "" // Just to illustrate repeated characters for i = _n to 0 _text := _text + " " for i = _n to 0 _text := _text + _symbol if _large _text := _text + "\n" + _text _text // Determine if current chart is a lower TF (< 4h in this example) isLtf = resolutionInMinutes() < resolutionInMinutes("240") // ----------------------------------------------------------------------------- // 3. CALCULATE PIVOTS // ----------------------------------------------------------------------------- // 3a. Chart timeframe pivots phchart = request.security(syminfo.tickerid, "5", ta.pivothigh(high, 6, 6), gaps=barmerge.gaps_on, lookahead=barmerge.lookahead_on) plchart = request.security(syminfo.tickerid, "5", ta.pivotlow(low, 6, 6), gaps=barmerge.gaps_on, lookahead=barmerge.lookahead_on) phtimestartchart = request.security(syminfo.tickerid, "5", phchart ? time[6] : na, gaps=barmerge.gaps_on, lookahead=barmerge.lookahead_on) pltimestartchart = request.security(syminfo.tickerid, "5", plchart ? time[6] : na, gaps=barmerge.gaps_on, lookahead=barmerge.lookahead_on) // 3b. Lower timeframe pivots // Timeframe 1 lph1 = request.security(syminfo.tickerid, ltimeframe1, ta.pivothigh(high, lleftBars1, lrightBars1), gaps=barmerge.gaps_on, lookahead=barmerge.lookahead_on) lpl1 = request.security(syminfo.tickerid, ltimeframe1, ta.pivotlow(low, lleftBars1, lrightBars1), gaps=barmerge.gaps_on, lookahead=barmerge.lookahead_on) lphtimestart1 = request.security(syminfo.tickerid, ltimeframe1, lph1 ? time[lrightBars1] : na, gaps=barmerge.gaps_on, lookahead=barmerge.lookahead_on) lpltimestart1 = request.security(syminfo.tickerid, ltimeframe1, lpl1 ? time[lrightBars1] : na, gaps=barmerge.gaps_on, lookahead=barmerge.lookahead_on) // (Similarly for ltimeframe2, ltimeframe3, ... ltimeframe6) // Timeframe 2 lph2 = request.security(syminfo.tickerid, ltimeframe2, ta.pivothigh(high, lleftBars2, lrightBars2), gaps=barmerge.gaps_on, lookahead=barmerge.lookahead_on) lpl2 = request.security(syminfo.tickerid, ltimeframe2, ta.pivotlow(low, lleftBars2, lrightBars2), gaps=barmerge.gaps_on, lookahead=barmerge.lookahead_on) lphtimestart2 = request.security(syminfo.tickerid, ltimeframe2, lph2 ? time[lrightBars2] : na, gaps=barmerge.gaps_on, lookahead=barmerge.lookahead_on) lpltimestart2 = request.security(syminfo.tickerid, ltimeframe2, lpl2 ? time[lrightBars2] : na, gaps=barmerge.gaps_on, lookahead=barmerge.lookahead_on) // Timeframe 3 lph3 = request.security(syminfo.tickerid, ltimeframe3, ta.pivothigh(high, lleftBars3, lrightBars3), gaps=barmerge.gaps_on, lookahead=barmerge.lookahead_on) lpl3 = request.security(syminfo.tickerid, ltimeframe3, ta.pivotlow(low, lleftBars3, lrightBars3), gaps=barmerge.gaps_on, lookahead=barmerge.lookahead_on) lphtimestart3 = request.security(syminfo.tickerid, ltimeframe3, lph3 ? time[lrightBars3] : na, gaps=barmerge.gaps_on, lookahead=barmerge.lookahead_on) lpltimestart3 = request.security(syminfo.tickerid, ltimeframe3, lpl3 ? time[lrightBars3] : na, gaps=barmerge.gaps_on, lookahead=barmerge.lookahead_on) // Timeframe 4 lph4 = request.security(syminfo.tickerid, ltimeframe4, ta.pivothigh(high, lleftBars4, lrightBars4), gaps=barmerge.gaps_on, lookahead=barmerge.lookahead_on) lpl4 = request.security(syminfo.tickerid, ltimeframe4, ta.pivotlow(low, lleftBars4, lrightBars4), gaps=barmerge.gaps_on, lookahead=barmerge.lookahead_on) lphtimestart4 = request.security(syminfo.tickerid, ltimeframe4, lph4 ? time[lrightBars4] : na, gaps=barmerge.gaps_on, lookahead=barmerge.lookahead_on) lpltimestart4 = request.security(syminfo.tickerid, ltimeframe4, lpl4 ? time[lrightBars4] : na, gaps=barmerge.gaps_on, lookahead=barmerge.lookahead_on) // Timeframe 5 lph5 = request.security(syminfo.tickerid, ltimeframe5, ta.pivothigh(high, lleftBars5, lrightBars5), gaps=barmerge.gaps_on, lookahead=barmerge.lookahead_on) lpl5 = request.security(syminfo.tickerid, ltimeframe5, ta.pivotlow(low, lleftBars5, lrightBars5), gaps=barmerge.gaps_on, lookahead=barmerge.lookahead_on) lphtimestart5 = request.security(syminfo.tickerid, ltimeframe5, lph5 ? time[lrightBars5] : na, gaps=barmerge.gaps_on, lookahead=barmerge.lookahead_on) lpltimestart5 = request.security(syminfo.tickerid, ltimeframe5, lpl5 ? time[lrightBars5] : na, gaps=barmerge.gaps_on, lookahead=barmerge.lookahead_on) // Timeframe 6 lph6 = request.security(syminfo.tickerid, ltimeframe6, ta.pivothigh(high, lleftBars6, lrightBars6), gaps=barmerge.gaps_on, lookahead=barmerge.lookahead_on) lpl6 = request.security(syminfo.tickerid, ltimeframe6, ta.pivotlow(low, lleftBars6, lrightBars6), gaps=barmerge.gaps_on, lookahead=barmerge.lookahead_on) lphtimestart6 = request.security(syminfo.tickerid, ltimeframe6, lph6 ? time[lrightBars6] : na, gaps=barmerge.gaps_on, lookahead=barmerge.lookahead_on) lpltimestart6 = request.security(syminfo.tickerid, ltimeframe6, lpl6 ? time[lrightBars6] : na, gaps=barmerge.gaps_on, lookahead=barmerge.lookahead_on) // 3c. Higher timeframe pivots // Timeframe 1 hph1 = request.security(syminfo.tickerid, htimeframe1, ta.pivothigh(high, hleftBars1, hrightBars1), gaps=barmerge.gaps_on, lookahead=barmerge.lookahead_on) hpl1 = request.security(syminfo.tickerid, htimeframe1, ta.pivotlow(low, hleftBars1, hrightBars1), gaps=barmerge.gaps_on, lookahead=barmerge.lookahead_on) hphtimestart1 = request.security(syminfo.tickerid, htimeframe1, hph1 ? time[hrightBars1] : na, gaps=barmerge.gaps_on, lookahead=barmerge.lookahead_on) hpltimestart1 = request.security(syminfo.tickerid, htimeframe1, hpl1 ? time[hrightBars1] : na, gaps=barmerge.gaps_on, lookahead=barmerge.lookahead_on) // Timeframe 2 hph2 = request.security(syminfo.tickerid, htimeframe2, ta.pivothigh(high, hleftBars2, hrightBars2), gaps=barmerge.gaps_on, lookahead=barmerge.lookahead_on) hpl2 = request.security(syminfo.tickerid, htimeframe2, ta.pivotlow(low, hleftBars2, hrightBars2), gaps=barmerge.gaps_on, lookahead=barmerge.lookahead_on) hphtimestart2 = request.security(syminfo.tickerid, htimeframe2, hph2 ? time[hrightBars2] : na, gaps=barmerge.gaps_on, lookahead=barmerge.lookahead_on) hpltimestart2 = request.security(syminfo.tickerid, htimeframe2, hpl2 ? time[hrightBars2] : na, gaps=barmerge.gaps_on, lookahead=barmerge.lookahead_on) // Timeframe 3-6 (similarly declared as above) // ----------------------------------------------------------------------------- // 4. MERGE LOWER / HIGHER TIMEFRAME VALUES BASED ON isLtf // ----------------------------------------------------------------------------- ph1 = isLtf ? lph1 : hph1 phtimestart1 = isLtf ? lphtimestart1 : hphtimestart1 pl1 = isLtf ? lpl1 : hpl1 pltimestart1 = isLtf ? lpltimestart1 : hpltimestart1 // Similarly for ph2, ph3, etc., pivot series… // ----------------------------------------------------------------------------- // 5. DETECT PIVOT SWINGS ON THE CURRENT BAR // This logic ensures we mark a pivot only on the bar it appears, not extended. // ----------------------------------------------------------------------------- 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 // Similarly for pivothigh2, pivotlow2, etc. (You’ll need variables declared.) // ----------------------------------------------------------------------------- // 6. PLOT (LABEL) THE PIVOTS ON THE CHART // ----------------------------------------------------------------------------- // Only plot chart timeframe pivots if LTF <= 3 minutes if pivothighchart and resolutionInMinutes() <= resolutionInMinutes("3") label.new(phtimestartchart, phchart, xloc=xloc.bar_time, text=generateText(12), style=label.style_none, textcolor=topColor1 ) if pivotlowchart and resolutionInMinutes() <= resolutionInMinutes("3") label.new(pltimestartchart, plchart, xloc=xloc.bar_time, text=generateText(12), style=label.style_none, textcolor=bottomColor1 ) // For Timeframe 1 showTimeframe1 = isLtf ? ltimeframe1Show : htimeframe1Show validTimeframe1 = isLtf ? notLowerTimeframe(ltimeframe1) : notLowerTimeframe(htimeframe1) if showTimeframe1 and pivothigh1 and validTimeframe1 label.new(phtimestart1, ph1, xloc=xloc.bar_time, text=generateText(lineLength1), style=label.style_none, textcolor=topColor1 ) if showTimeframe1 and pivotlow1 and validTimeframe1 label.new(pltimestart1, pl1, xloc=xloc.bar_time, text=generateText(lineLength1), style=label.style_none, textcolor=bottomColor1 ) // Timeframe 2 showTimeframe2 = isLtf ? ltimeframe2Show : htimeframe2Show validTimeframe2 = isLtf ? notLowerTimeframe(ltimeframe2) : notLowerTimeframe(htimeframe2) // Assuming pivothigh2, pivotlow2, phtimestart2, pltimestart2, etc. exist if showTimeframe2 and pivothigh2 and validTimeframe2 label.new(phtimestart2, ph2, xloc=xloc.bar_time, text=generateText(lineLength2), style=label.style_none, textcolor=topColor2 ) if showTimeframe2 and pivotlow2 and validTimeframe2 label.new(pltimestart2, pl2, xloc=xloc.bar_time, text=generateText(lineLength2), style=label.style_none, textcolor=bottomColor2 ) // ... And so on for timeframes 3-6 ... // ----------------------------------------------------------------------------- // 7. WATERMARK // ----------------------------------------------------------------------------- if barstate.islast _table = table.new(position.bottom_left, 1, 1) table.cell(_table, 0, 0, text="@Nephew_Sam_", text_size=size.small, text_color=color.new(color.gray, 50) )
Missing Inputs
In your snippet, variables like ltimeframe1
, ltimeframe1Show
, lleftBars1
, topColor1
, hideLTF
, etc. appear out of nowhere. They are typically declared with input(...)
lines at the top of the script. For example:
ltimeframe1 = input.string("15", "Lower Timeframe #1") lleftBars1 = input.int(6, "Left bars for pivot (LTF1)") lrightBars1 = input.int(6, "Right bars for pivot (LTF1)") topColor1 = input.color(color.red, "Top Color (LTF1)") bottomColor1 = input.color(color.green, "Bottom Color (LTF1)") hideLTF = input.bool(false, "Hide lower TF if chart TF is smaller") ...
Make sure all these are defined. Otherwise, you’ll get compilation errors.
Pivot Functions
ta.pivothigh()
and ta.pivotlow()
can be resource-intensive if used on multiple timeframes. Keep an eye on script limits (especially if the code is large).[gaps=barmerge.gaps_on, lookahead=barmerge.lookahead_on]
arguments ensure that the pivot from the higher/lower timeframe is plotted historically and doesn’t repaint in a misleading way.Label Limits
max_labels_count=500
. If your script tries to create more than 500 labels, it could stop drawing or throw an error. Adjust or manage how many labels are created if needed.Watermark Table
barstate.islast
block ensures that the table (which draws the watermark) is only created/updated on the last bar. This is a common pattern in Pine Script to avoid spam-creating multiple tables on each bar.Your script is structured to:
resolutionInMinutes() <= resolutionInMinutes("3")
, or notLowerTimeframe(...)
).Just be sure you define all the input variables that you reference in your code. If you paste this directly into TradingView with the missing input()
statements, it will fail to compile. Once you restore or create those input declarations, it should work as intended under Pine Script v6.