0% found this document useful (0 votes)
97 views3 pages

Trading Liquidity Indicator Script

1. This document defines an indicator for displaying liquidity levels on a chart with options to show daily, weekly, and monthly liquidity. 2. It contains functions for drawing, updating, and clearing different colored lines on the chart to represent high and low liquidity levels over various timeframes. 3. The indicator will draw and update lines for high and low liquidity levels from the previous day, week, and month if the relevant input options are enabled.

Uploaded by

mehmetceren837
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
97 views3 pages

Trading Liquidity Indicator Script

1. This document defines an indicator for displaying liquidity levels on a chart with options to show daily, weekly, and monthly liquidity. 2. It contains functions for drawing, updating, and clearing different colored lines on the chart to represent high and low liquidity levels over various timeframes. 3. The indicator will draw and update lines for high and low liquidity levels from the previous day, week, and month if the relevant input options are enabled.

Uploaded by

mehmetceren837
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

//@version=5

indicator("Liquidity", max_lines_count=500, max_lines_count = 500, max_boxes_count


= 500, max_bars_back = 500, overlay = true)

show_liquidity = input(true,"Show Liquidity? (Daily, Weekly, Monthly)",inline='Show


Liquidity'
, group = 'Configuration')

var gStartOffset = 0
var gEndOffset = 25

// DEFINE COLORS of the lines displayed on the chart


// --> Blue lines: Daily liquidity
// --> Yellow lines: Weekly Liquidity
// --> Purple lines: Monthly liquidity

tf=input.timeframe("60")
gIstEnabled = input(false)
gtAboveLiquidityColor =input.color( color.new(#b9c5d4, 13))
gtBelowLiquidityColor = input.color(color.new(#b9c5d4, 43))
gtWidth = 1

gIshEnabled = input(false)
ghAboveLiquidityColor =input.color( color.new(#b9c5d4, 13))
ghBelowLiquidityColor = input.color(color.new(#bfc8d4, 43))
ghWidth = 1

//daily liquidity
gIsDailyEnabled = input(true)
gDailyAboveLiquidityColor =input.color( color.new(#4987d3, 13))
gDailyBelowLiquidityColor = input.color(color.new(#4987d3, 43))
gDailyWidth = 1

//weekly liquidity
gIsWeeklyEnabled = input(true)
gWeeklyAboveLiquidityColor =input.color(color.new(#f6eb54, 13))
gWeeklyBelowLiquidityColor =input.color( color.new(#f6eb54, 4))
gWeeklyWidth = 1

//month liquidity
gIsMonthlyEnabled = input(true)
gMonthlyAboveLiquidityColor =input.color( color.new(#f66ecf, 13))
gMonthlyBelowLiquidityColor = input.color(color.new(#f66ecf, 43))
gMonthlyWidth = 1

cleanedLevelColor = color.new(#ffffff, 100)


cleanedLevelStyle = "Dashed"

var highArray = array.new_float()


var lowArray = array.new_float()
var highLinesArray = array.new_line()
var lowLinesArray = array.new_line()
var purgedLinesArray = array.new_line()
[prevDayHigh, prevDayLow] = request.security(syminfo.tickerid, "D",
[high[1], low[1]], lookahead=barmerge.lookahead_on)
[prevWeekHigh, prevWeekLow] = request.security(syminfo.tickerid, "W",
[high[1], low[1]], lookahead=barmerge.lookahead_on)
[prevMonthHigh, prevMonthLow] = request.security(syminfo.tickerid, "M",
[high[1], low[1]], lookahead=barmerge.lookahead_on)

[prev4HHigh, prev4HLow] = request.security(syminfo.tickerid, "240",


[high[1], low[1]], lookahead=barmerge.lookahead_on)
[prev1HHigh, prev1HLow] = request.security(syminfo.tickerid, tf, [high[1],
low[1]], lookahead=barmerge.lookahead_on)
//edited berkusa

// Functions
f_drawLine(_y, _c, _w=1) => line.new(bar_index, _y, bar_index, _y, color=_c,
width=_w)

f_create(_high, _low, _upperColor, _lowerColor, _linewidth) =>


array.push(highArray, _high)
array.push(lowArray, _low)
array.push(highLinesArray, f_drawLine(_high, _upperColor, _linewidth))
array.push(lowLinesArray, f_drawLine(_low, _lowerColor, _linewidth))

f_updateStickyLevels(_levels) =>
for _line in _levels
line.set_x1(_line, bar_index + gStartOffset)
line.set_x2(_line, bar_index + gEndOffset)

f_moveLevel(_from, _to, _level, _index) =>


array.push(_to, _level)
array.remove(_from, _index)

f_highlightPurgedLevel(_level) =>
_style = cleanedLevelStyle == "Solid" ? line.style_solid : cleanedLevelStyle ==
"Dashed" ? line.style_dashed : line.style_dotted
line.set_color(_level, cleanedLevelColor)
line.set_style(_level, _style)

f_updateUpperLevels(_high, _highs, _levels, _purgedLevels) =>


while array.min(_highs) < _high
for [_index, _value] in _highs
if _high > _value
_line = array.get(_levels, _index)
f_highlightPurgedLevel(_line)
f_moveLevel(_levels, _purgedLevels, _line, _index)
array.remove(_highs, _index)
f_updateLowerLevels(_low, _lows, _levels, _purgedLevels) =>
while array.max(_lows) > _low
for [_index, _value] in _lows
if _low < _value
_line = array.get(_levels, _index)
f_highlightPurgedLevel(_line)
f_moveLevel(_levels, _purgedLevels, _line, _index)
array.remove(_lows, _index)

f_clearLevels(_levels) =>
while array.size(_levels) > 0
for [_index, _line] in _levels
line.delete(array.remove(_levels, _index))

f_isHigherTimeframe(_timeframe) => timeframe.in_seconds() <=


timeframe.in_seconds(_timeframe)

//Draw Lines if liquidity is enabled


if show_liquidity
if gIstEnabled and f_isHigherTimeframe(tf) and ta.change(time(tf))
f_create(prev1HHigh, prev1HLow, gtAboveLiquidityColor,
gtBelowLiquidityColor, gtWidth)
if gIshEnabled and f_isHigherTimeframe("240") and ta.change(time("240"))
f_create(prev4HHigh, prev4HLow, ghAboveLiquidityColor,
ghBelowLiquidityColor, ghWidth)

if gIsDailyEnabled and f_isHigherTimeframe("D") and ta.change(time("D"))


f_create(prevDayHigh, prevDayLow, gDailyAboveLiquidityColor,
gDailyBelowLiquidityColor, gDailyWidth)

if gIsWeeklyEnabled and f_isHigherTimeframe("W") and ta.change(time("W"))


f_create(prevWeekHigh, prevWeekLow, gWeeklyAboveLiquidityColor,
gWeeklyBelowLiquidityColor, gWeeklyWidth)

if gIsMonthlyEnabled and f_isHigherTimeframe("M") and ta.change(time("M"))


f_create(prevMonthHigh, prevMonthLow, gMonthlyAboveLiquidityColor,
gMonthlyBelowLiquidityColor, gMonthlyWidth)

if barstate.islast
f_updateStickyLevels(highLinesArray)
f_updateStickyLevels(lowLinesArray)
f_updateStickyLevels(purgedLinesArray)

// Highlight the levels that got their liquidity taken

f_updateUpperLevels(high, highArray, highLinesArray, purgedLinesArray)


f_updateLowerLevels(low, lowArray, lowLinesArray, purgedLinesArray)

// Clean the levels that had their liquidity taken on a daily basis
if ta.change(time("D"))
f_clearLevels(purgedLinesArray)

You might also like