Explore i want to merge two pine script indicators Save Share Download ▾ ReportJump to turn (6) 1 i want to merge two pine script indicators 2 this one must be added to the next 3 // This work is licensed under a Attribution-NonCommercial-ShareAlike 4.0 Intern 4 //@version=6 indicator('Liquidity Lines & Sweeps + FVG [Lucien]', overlay = true 5 recap, second indicator remain untouched. just add sessions 6 full code please i want to merge two pine script indicators
Assistant2025-05-23 08:17 UTC Copy response
Sure! I can help you merge two Pine Script indicators. Please provide the Pine Script code for the two indicators you want to combine, and let me know how you want them to be merged (for example, plotting both on the same chart, combining their logic, using one as a filter for the other, etc.).
this one must be added to the next
Assistant2025-05-23 08:19 UTC Copy response
Copy first prompt Copy first response
Details
Provider OpenAI
Model provenance As recorded by source dataset
Turns 6 (12 messages)
Language en
Conversation date May 23, 2025
Added to archive Nov 16, 2026
ID 01m7h42vn7dztm6exwq251gvw6Source & license Imported from WildChat-4.8M (AI2) (source ). Imported records earn no Research Points.
Upstream record: 8261371b9f2ac343bd815ed171ef97d5
Zhao et al., WildChat: 1M ChatGPT Interaction Logs in the Wild (ICLR 2024). Contains information from WildChat-4.8M, made available under the ODC Attribution License.
License: ODC-BY-1.0
Got it! Please share the two Pine Script indicator codes (or paste the first one now and then the second), and I’ll help you combine them as per your requirements.
// 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/
// © LuxAlgo
//@version=5
indicator("Sessions [LuxAlgo]", "LuxAlgo - Sessions", overlay = true, max_bars_back = 500, max_lines_count = 500, max_boxes_count = 500, max_labels_count = 500)
//------------------------------------------------------------------------------
//Settings
//-----------------------------------------------------------------------------{
//Session A
show_sesa = input(true, '', inline = 'sesa', group = 'Session A')
sesa_txt = input('New York', '', inline = 'sesa', group = 'Session A')
sesa_ses = input.session('1300-2200', '', inline = 'sesa', group = 'Session A')
sesa_css = input.color(#ff5d00, '', inline = 'sesa', group = 'Session A')
sesa_range = input(true, 'Range', inline = 'sesa_overlays', group = 'Session A')
sesa_tl = input(false, 'Trendline', inline = 'sesa_overlays', group = 'Session A')
sesa_avg = input(false, 'Mean', inline = 'sesa_overlays', group = 'Session A')
sesa_vwap = input(false, 'VWAP', inline = 'sesa_overlays', group = 'Session A')
sesa_maxmin = input(false, 'Max/Min', inline = 'sesa_overlays', group = 'Session A')
//Session B
show_sesb = input(true, '', inline = 'sesb', group = 'Session B')
sesb_txt = input('London', '', inline = 'sesb', group = 'Session B')
sesb_ses = input.session('0700-1600', '', inline = 'sesb', group = 'Session B')
sesb_css = input.color(#2157f3, '', inline = 'sesb', group = 'Session B')
sesb_range = input(true, 'Range', inline = 'sesb_overlays', group = 'Session B')
sesb_tl = input(false, 'Trendline', inline = 'sesb_overlays', group = 'Session B')
sesb_avg = input(false, 'Mean', inline = 'sesb_overlays', group = 'Session B')
sesb_vwap = input(false, 'VWAP', inline = 'sesb_overlays', group = 'Session B')
sesb_maxmin = input(false, 'Max/Min', inline = 'sesb_overlays', group = 'Session B')
//Session C
show_sesc = input(true, '', inline = 'sesc', group = 'Session C')
sesc_txt = input('Tokyo', '', inline = 'sesc', group = 'Session C')
sesc_ses = input.session('0000-0900', '', inline = 'sesc', group = 'Session C')
sesc_css = input.color(#e91e63, '', inline = 'sesc', group = 'Session C')
sesc_range = input(true, 'Range', inline = 'sesc_overlays', group = 'Session C')
sesc_tl = input(false, 'Trendline', inline = 'sesc_overlays', group = 'Session C')
sesc_avg = input(false, 'Mean', inline = 'sesc_overlays', group = 'Session C')
sesc_vwap = input(false, 'VWAP', inline = 'sesc_overlays', group = 'Session C')
sesc_maxmin = input(false, 'Max/Min', inline = 'sesc_overlays', group = 'Session C')
//Session D
show_sesd = input(true, '', inline = 'sesd', group = 'Session D')
sesd_txt = input('Sydney', '', inline = 'sesd', group = 'Session D')
sesd_ses = input.session('2100-0600', '', inline = 'sesd', group = 'Session D')
sesd_css = input.color(#ffeb3b, '', inline = 'sesd', group = 'Session D')
Show full message · 629 lines Assistant2025-05-23 08:19 UTC Copy response
Thanks for sharing the first indicator — the "Sessions [LuxAlgo]" session/timebox indicator in Pine Script v5.
Please share the second indicator code you'd like to merge it with. Once I have both, I can assist you with properly merging their inputs, variables, and plotting logic so they work together in a single combined indicator script.
//@version=6
indicator('Liquidity Lines & Sweeps + FVG [Lucien]', overlay = true, max_lines_count = 500)
// === LIQUIDITY SETTINGS ===
liquidityBool = input.bool(true, 'Show Liquidity Sweeps', group = 'Liquidity Settings')
liquidity_len = input.int(30, 'Liquidity Length', minval = 5, group = 'Liquidity Settings')
upColor = input.color(color.new(color.teal, 15), title = 'Bullish Liquidity Color', group = 'Liquidity Settings')
downColor = input.color(color.new(color.red, 15), title = 'Bearish Liquidity Color', group = 'Liquidity Settings')
// === EMA SETTINGS ===
showEma = input.bool(true, title="Show EMA", group="Moving Average")
emaLength = input.int(50, title="EMA Length", minval=1, group="Moving Average") // Changed EMA1 default to 50
emaSource = input.source(close, title="EMA Source", group="Moving Average")
emaTimeframe = input.timeframe("", title="EMA Timeframe (leave empty for current)", group="Moving Average")
emaColor = input.color(color.new(color.orange, 0), title="EMA Color", group="Moving Average")
emaWidth = input.int(2, title="EMA Line Width", minval=1, maxval=5, group="Moving Average")
// === EMA 2 SETTINGS ===
showEma2 = input.bool(true, title="Show EMA 2", group="Moving Average") // Enabled by default
ema2Length = input.int(100, title="EMA 2 Length", minval=1, group="Moving Average")
ema2Source = input.source(close, title="EMA 2 Source", group="Moving Average")
ema2Timeframe = input.timeframe("", title="EMA 2 Timeframe (leave empty for current)", group="Moving Average")
ema2Color = input.color(color.new(color.blue, 0), title="EMA 2 Color", group="Moving Average")
ema2Width = input.int(2, title="EMA 2 Line Width", minval=1, maxval=5, group="Moving Average")
// === EMA 3 SETTINGS ===
showEma3 = input.bool(true, title="Show EMA 3", group="Moving Average") // Enabled by default
ema3Length = input.int(200, title="EMA 3 Length", minval=1, group="Moving Average")
ema3Source = input.source(close, title="EMA 3 Source", group="Moving Average")
ema3Timeframe = input.timeframe("", title="EMA 3 Timeframe (leave empty for current)", group="Moving Average")
ema3Color = input.color(color.new(color.purple, 0), title="EMA 3 Color", group="Moving Average")
ema3Width = input.int(2, title="EMA 3 Line Width", minval=1, maxval=5, group="Moving Average")
// Calculate EMA 1 with timeframe option
emaValue = request.security(syminfo.tickerid, emaTimeframe != "" ? emaTimeframe : timeframe.period, ta.ema(emaSource, emaLength))
plot(showEma ? emaValue : na, title="EMA", color=emaColor, linewidth=emaWidth)
// Calculate EMA 2 with timeframe option
emaValue2 = request.security(syminfo.tickerid, ema2Timeframe != "" ? ema2Timeframe : timeframe.period, ta.ema(ema2Source, ema2Length))
plot(showEma2 ? emaValue2 : na, title="EMA 2", color=ema2Color, linewidth=ema2Width)
// Calculate EMA 3 with timeframe option
emaValue3 = request.security(syminfo.tickerid, ema3Timeframe != "" ? ema3Timeframe : timeframe.period, ta.ema(ema3Source, ema3Length))
plot(showEma3 ? emaValue3 : na, title="EMA 3", color=ema3Color, linewidth=ema3Width)
Show full message · 287 lines Assistant2025-05-23 08:21 UTC Copy response
Thanks for sharing the second indicator code ("Liquidity Lines & Sweeps + FVG [Lucien]") in Pine Script v6.
Important notes before merging:
The first indicator is written in Pine Script v5 ; the second in v6 .
Pine versions are generally backward compatible. The safest approach is to convert both to the same version (preferably v5, since v6 is very new and not yet supported everywhere) or keep v6 but adapt the v5 code.
Both are overlay=true.
They both have input groups and visual elements, but different functionality.
Variables, functions, and input names do not collide, so merging is mostly about combining the initial declarations, inputs, and plot/line drawing, while ensuring no conflicts.
How to merge:
Strategy:
Change the v6 script to v5 (mostly syntax-compatible, but remove any v6-only features).
Combine inputs; rename conflicting input groups or variable names if needed.
Paste the first script's code first (Sessions), then the second's code (Liquidity/FVG) below.
Remove duplicate indicator(...) declarations; merge only one at the top.
Make sure to replace request.security calls properly and check alert conditions.
If you want me to, I can do the full merged script below based on v5.
Here's a merged example sketch in Pine Script v5 combining your two scripts:
Show full message · 332 lines recap, second indicator remain untouched. just add sessions
Assistant2025-05-23 08:22 UTC Copy response
Understood! You want to keep the entire second indicator as-is (including its indicator declaration, inputs, plots, etc.) and simply add the Sessions indicator on top of it in the same script .
The best way to do this:
Use the second indicator code as the base (since it's more complex and uses v6; but we'll have to adjust version).
Remove the //@version=6 line and replace it with //@version=5 (TradingView currently requires v5).
Paste the entire Sessions indicator code (except its indicator() line) at the top or bottom inside the script.
Make sure to rename inputs if any group/input names conflict.
Since the Sessions indicator uses a lot of var variables and many input() calls grouped differently from the second indicator, they generally won't conflict.
Both will plot on the same chart since both have overlay=true.
Here is a minimal example of the merge pattern:
pinescript Copy code
//@version=5
indicator("Liquidity Lines & Sweeps + FVG [Lucien] + Sessions [LuxAlgo]", overlay=true, max_lines_count=500, max_boxes_count=500, max_labels_count=500)
// === SESSIONS [LUXALGO] BEGIN ===
// Paste the entire Sessions indicator code here EXCEPT the `//@version=5` and `indicator()` line at the top.
// For example:
// ... all the Sessions code pasted here ...
// === SESSIONS [LUXALGO] END ===
// === LIQUIDITY & FVG [LUCIEN] BEGIN ===
// Now paste entire Liquidity Lines & Sweeps + FVG code starting AFTER its `//@version=6` & `indicator()` line:
// input : liquidityBool = input.bool(true, ...)
// ... all Liquidity/FVG code here ...
// === LIQUIDITY & FVG [LUCIEN] END ===
What to watch out for:
You must remove the Sessions indicator’s indicator() function line.
Rename the combined script’s indicator title to something that includes both.
Inputs will appear in separate groups as they had.
Both scripts use var style vars — this is ok in the same script unless same names exist (in your case, no direct name conflicts).
Confirm no errors or warnings for line/box/label maximum counts (max_lines_count etc.) — adjust if needed.
You can customize further if you want to share some data between indicators.
If you want, I can also produce a ready-to-use merged script copy-pasting the Sessions code inside your second indicator code — just say!
Assistant2025-05-23 08:25 UTC Copy response
Sure! Below is the full merged script in Pine Script v5 that keeps your second indicator completely intact and adds the Sessions [LuxAlgo] indicator code inside , so both run together in one combined script.
I did the following:
Changed //@version=6 of the second script to //@version=5.
Used combined single indicator() declaration (named to represent both).
Inserted the full Sessions indicator code after the indicator declaration but before the liquidity/FVG code.
Removed the separate indicator() declaration from Sessions.
Adjusted max_*_count input parameters to cover both.
Kept all inputs inside their original groups.
Show full message · 947 lines Not yet included in a published release.
sesd_range = input(true, 'Range', inline = 'sesd_overlays', group = 'Session D')
sesd_tl = input(false, 'Trendline', inline = 'sesd_overlays', group = 'Session D')
sesd_avg = input(false, 'Mean', inline = 'sesd_overlays', group = 'Session D')
sesd_vwap = input(false, 'VWAP', inline = 'sesd_overlays', group = 'Session D')
sesd_maxmin = input(false, 'Max/Min', inline = 'sesd_overlays', group = 'Session D')
//Timezones
tz_incr = input.int(0, 'UTC (+/-)', group = 'Timezone')
use_exchange = input(false, 'Use Exchange Timezone', group = 'Timezone')
//Ranges Options
bg_transp = input.float(90, 'Range Area Transparency', group = 'Ranges Settings')
show_outline = input(true, 'Range Outline', group = 'Ranges Settings')
show_txt = input(true, 'Range Label', group = 'Ranges Settings')
//Dashboard
show_dash = input(false, 'Show Dashboard', group = 'Dashboard')
advanced_dash = input(false, 'Advanced Dashboard', group = 'Dashboard')
dash_loc = input.string('Top Right', 'Dashboard Location', options = ['Top Right', 'Bottom Right', 'Bottom Left'], group = 'Dashboard')
text_size = input.string('Small', 'Dashboard Size', options = ['Tiny', 'Small', 'Normal'], group = 'Dashboard')
//Divider
show_ses_div = input(false, 'Show Sessions Divider', group = 'Dividers')
show_day_div = input(true, 'Show Daily Divider', group = 'Dividers')
//-----------------------------------------------------------------------------}
//Functions
//-----------------------------------------------------------------------------{
n = bar_index
//Get session average
get_avg(session)=>
var len = 1
var float csma = na
var float sma = na
code Copy code
if session > session[1]
len := 1
csma := close
if session and session == session[1]
len += 1
csma += close
sma := csma / len
sma
//Get trendline coordinates
get_linreg(session)=>
var len = 1
var float cwma = na
var float csma = na
var float csma2 = na
code Copy code
var float y1 = na
var float y2 = na
var float stdev = na
var float r2 = na
if session > session[1]
len := 1
cwma := close
csma := close
csma2 := close * close
if session and session == session[1]
len += 1
csma += close
csma2 += close * close
cwma += close * len
sma = csma / len
wma = cwma / (len * (len + 1) / 2)
cov = (wma - sma) * (len+1)/2
stdev := math.sqrt(csma2 / len - sma * sma)
r2 := cov / (stdev * (math.sqrt(len*len - 1) / (2 * math.sqrt(3))))
y1 := 4 * sma - 3 * wma
y2 := 3 * wma - 2 * sma
[y1 , y2, stdev, r2]
//Session Vwap
get_vwap(session) =>
var float num = na
var float den = na
code Copy code
if session > session[1]
num := close * volume
den := volume
else if session and session == session[1]
num += close * volume
den += volume
else
num := na
[num, den]
//Set line
set_line(session, y1, y2, session_css)=>
var line tl = na
code Copy code
if session > session[1]
tl := line.new(n, close, n, close, color = session_css)
if session and session == session[1]
line.set_y1(tl, y1)
line.set_xy2(tl, n, y2)
//Set session range
get_range(session, session_name, session_css)=>
var t = 0
var max = high
var min = low
var box bx = na
var label lbl = na
code Copy code
if session > session[1]
t := time
max := high
min := low
bx := box.new(n, max, n, min
, bgcolor = color.new(session_css, bg_transp)
, border_color = show_outline ? session_css : na
, border_style = line.style_dotted)
if show_txt
lbl := label.new(t, max, session_name
, xloc = xloc.bar_time
, textcolor = session_css
, style = label.style_label_down
, color = color.new(color.white, 100)
, size = size.tiny)
if session and session == session[1]
max := math.max(high, max)
min := math.min(low, min)
box.set_top(bx, max)
box.set_rightbottom(bx, n, min)
if show_txt
label.set_xy(lbl, int(math.avg(t, time)), max)
[session ? na : max, session ? na : min]
//-----------------------------------------------------------------------------}
//Sessions
//-----------------------------------------------------------------------------{
tf = timeframe.period
var tz = use_exchange ? syminfo.timezone :
str.format('UTC{0}{1}', tz_incr >= 0 ? '+' : '-', math.abs(tz_incr))
is_sesa = math.sign(nz(time(tf, sesa_ses, tz)))
is_sesb = math.sign(nz(time(tf, sesb_ses, tz)))
is_sesc = math.sign(nz(time(tf, sesc_ses, tz)))
is_sesd = math.sign(nz(time(tf, sesd_ses, tz)))
//-----------------------------------------------------------------------------}
//Dashboard
//-----------------------------------------------------------------------------{
var table_position = dash_loc == 'Bottom Left' ? position.bottom_left
: dash_loc == 'Top Right' ? position.top_right
: position.bottom_right
var table_size = text_size == 'Tiny' ? size.tiny
: text_size == 'Small' ? size.small
: size.normal
var tb = table.new(table_position, 5, 6
, bgcolor = #1e222d
, border_color = #373a46
, border_width = 1
, frame_color = #373a46
, frame_width = 1)
if barstate.isfirst and show_dash
table.cell(tb, 0, 0, 'LuxAlgo', text_color = color.white, text_size = table_size)
table.merge_cells(tb, 0, 0, 4, 0)
code Copy code
table.cell(tb, 0, 2, sesa_txt, text_color = sesa_css, text_size = table_size)
table.cell(tb, 0, 3, sesb_txt, text_color = sesb_css, text_size = table_size)
table.cell(tb, 0, 4, sesc_txt, text_color = sesc_css, text_size = table_size)
table.cell(tb, 0, 5, sesd_txt, text_color = sesd_css, text_size = table_size)
if advanced_dash
table.cell(tb, 0, 1, 'Session', text_color = color.white
, text_size = table_size)
table.cell(tb, 1, 1, 'Status', text_color = color.white
, text_size = table_size)
table.cell(tb, 2, 1, 'Trend', text_color = color.white
, text_size = table_size)
table.cell(tb, 3, 1, 'Volume', text_color = color.white
, text_size = table_size)
table.cell(tb, 4, 1, 'σ', text_color = color.white
, text_size = table_size)
if barstate.islast and show_dash
table.cell(tb, 1, 2, is_sesa ? 'Active' : 'Innactive'
, bgcolor = is_sesa ? #089981 : #f23645
, text_color = color.white
, text_size = table_size)
code Copy code
table.cell(tb, 1, 3, is_sesb ? 'Active' : 'Innactive'
, bgcolor = is_sesb ? #089981 : #f23645
, text_color = color.white
, text_size = table_size)
table.cell(tb, 1, 4, is_sesc ? 'Active' : 'Innactive'
, bgcolor = is_sesc ? #089981 : #f23645
, text_color = color.white
, text_size = table_size)
table.cell(tb, 1, 5, is_sesd ? 'Active' : 'Innactive'
, bgcolor = is_sesd ? #089981 : #f23645
, text_color = color.white
, text_size = table_size)
//-----------------------------------------------------------------------------}
//Overlays
//-----------------------------------------------------------------------------{
var float max_sesa = na
var float min_sesa = na
var float max_sesb = na
var float min_sesb = na
var float max_sesc = na
var float min_sesc = na
var float max_sesd = na
var float min_sesd = na
//Ranges
if show_sesa and sesa_range
[max, min] = get_range(is_sesa, sesa_txt, sesa_css)
max_sesa := max
min_sesa := min
if show_sesb and sesb_range
[max, min] = get_range(is_sesb, sesb_txt, sesb_css)
max_sesb := max
min_sesb := min
if show_sesc and sesc_range
[max, min] = get_range(is_sesc, sesc_txt, sesc_css)
max_sesc := max
min_sesc := min
if show_sesd and sesd_range
[max, min] = get_range(is_sesd, sesd_txt, sesd_css)
max_sesd := max
min_sesd := min
//Trendlines
if show_sesa and (sesa_tl or advanced_dash)
[y1, y2, stdev, r2] = get_linreg(is_sesa)
code Copy code
if advanced_dash
table.cell(tb, 2, 2, str.tostring(r2, '#.##')
, bgcolor = r2 > 0 ? #089981 : #f23645
, text_color = color.white
, text_size = table_size)
table.cell(tb, 4, 2, str.tostring(stdev, '#.####')
, text_color = color.white
, text_size = table_size)
if sesa_tl
set_line(is_sesa, y1, y2, sesa_css)
if show_sesb and (sesb_tl or advanced_dash)
[y1, y2, stdev, r2] = get_linreg(is_sesb)
code Copy code
if advanced_dash
table.cell(tb, 2, 3, str.tostring(r2, '#.##')
, bgcolor = r2 > 0 ? #089981 : #f23645
, text_color = color.white
, text_size = table_size)
table.cell(tb, 4, 3, str.tostring(stdev, '#.####')
, text_color = color.white
, text_size = table_size)
if sesb_tl
set_line(is_sesb, y1, y2, sesb_css)
if show_sesc and (sesc_tl or advanced_dash)
[y1, y2, stdev, r2] = get_linreg(is_sesc)
code Copy code
if advanced_dash
table.cell(tb, 2, 4, str.tostring(r2, '#.##')
, bgcolor = r2 > 0 ? #089981 : #f23645
, text_color = color.white
, text_size = table_size)
table.cell(tb, 4, 4, str.tostring(stdev, '#.####')
, text_color = color.white
, text_size = table_size)
if sesc_tl
set_line(is_sesc, y1, y2, sesc_css)
if show_sesd and (sesd_tl or advanced_dash)
[y1, y2, stdev, r2] = get_linreg(is_sesd)
code Copy code
if advanced_dash
table.cell(tb, 2, 5, str.tostring(r2, '#.##')
, bgcolor = r2 > 0 ? #089981 : #f23645
, text_color = color.white
, text_size = table_size)
table.cell(tb, 4, 5, str.tostring(stdev, '#.####')
, text_color = color.white
, text_size = table_size)
if sesd_tl
set_line(is_sesd, y1, y2, sesd_css)
//Mean
if show_sesa and sesa_avg
avg = get_avg(is_sesa)
set_line(is_sesa, avg, avg, sesa_css)
if show_sesb and sesb_avg
avg = get_avg(is_sesb)
set_line(is_sesb, avg, avg, sesb_css)
if show_sesc and sesc_avg
avg = get_avg(is_sesc)
set_line(is_sesc, avg, avg, sesc_css)
if show_sesd and sesd_avg
avg = get_avg(is_sesd)
set_line(is_sesd, avg, avg, sesd_css)
//VWAP
var float vwap_a = na
var float vwap_b = na
var float vwap_c = na
var float vwap_d = na
if show_sesa and (sesa_vwap or advanced_dash)
[num, den] = get_vwap(is_sesa)
code Copy code
if sesa_vwap
vwap_a := num / den
if advanced_dash
table.cell(tb, 3, 2, str.tostring(den, format.volume)
, text_color = color.white
, text_size = table_size)
if show_sesb and (sesb_vwap or advanced_dash)
[num, den] = get_vwap(is_sesb)
code Copy code
if sesb_vwap
vwap_b := num / den
if advanced_dash
table.cell(tb, 3, 3, str.tostring(den, format.volume)
, text_color = color.white
, text_size = table_size)
if show_sesc and (sesc_vwap or advanced_dash)
[num, den] = get_vwap(is_sesc)
code Copy code
if sesc_vwap
vwap_c := num / den
if advanced_dash
table.cell(tb, 3, 4, str.tostring(den, format.volume)
, text_color = color.white
, text_size = table_size)
if show_sesd and (sesd_vwap or advanced_dash)
[num, den] = get_vwap(is_sesd)
code Copy code
if sesd_vwap
vwap_d := num / den
if advanced_dash
table.cell(tb, 3, 5, str.tostring(den, format.volume)
, text_color = color.white
, text_size = table_size)
//-----------------------------------------------------------------------------}
//Plots
//-----------------------------------------------------------------------------{
//Plot max/min
plot(sesa_maxmin ? max_sesa : na, 'Session A Maximum', sesa_css, 1, plot.style_linebr)
plot(sesa_maxmin ? min_sesa : na, 'Session A Minimum', sesa_css, 1, plot.style_linebr)
plot(sesb_maxmin ? max_sesb : na, 'Session B Maximum', sesb_css, 1, plot.style_linebr)
plot(sesb_maxmin ? min_sesb : na, 'Session B Minimum', sesb_css, 1, plot.style_linebr)
plot(sesc_maxmin ? max_sesc : na, 'Session C Maximum', sesc_css, 1, plot.style_linebr)
plot(sesc_maxmin ? min_sesc : na, 'Session C Minimum', sesc_css, 1, plot.style_linebr)
plot(sesd_maxmin ? max_sesd : na, 'Session D Maximum', sesd_css, 1, plot.style_linebr)
plot(sesd_maxmin ? min_sesd : na, 'Session D Minimum', sesd_css, 1, plot.style_linebr)
//Plot vwaps
plot(vwap_a, 'Session A VWAP', sesa_css, 1, plot.style_linebr)
plot(vwap_b, 'Session B VWAP', sesb_css, 1, plot.style_linebr)
plot(vwap_c, 'Session C VWAP', sesc_css, 1, plot.style_linebr)
plot(vwap_d, 'Session D VWAP', sesd_css, 1, plot.style_linebr)
//Plot Divider A
plotshape(is_sesa and show_ses_div and show_sesa, "·"
, shape.square
, location.bottom
, na
, text = "."
, textcolor = sesa_css
, size = size.tiny
, display = display.all - display.status_line
, editable = false)
plotshape(is_sesa != is_sesa[1] and show_ses_div and show_sesa, "NYE"
, shape.labelup
, location.bottom
, na
, text = "❚"
, textcolor = sesa_css
, size = size.tiny
, display = display.all - display.status_line
, editable = false)
//Plot Divider B
plotshape(is_sesb and show_ses_div and show_sesb, "·"
, shape.labelup
, location.bottom
, na
, text = "."
, textcolor = sesb_css
, size = size.tiny
, display = display.all - display.status_line
, editable = false)
plotshape(is_sesb != is_sesb[1] and show_ses_div and show_sesb, "LDN"
, shape.labelup
, location.bottom
, na
, text = "❚"
, textcolor = sesb_css
, size = size.tiny
, display = display.all - display.status_line
, editable = false)
//Plot Divider C
plotshape(is_sesc and show_ses_div and show_sesc, "·"
, shape.square
, location.bottom
, na
, text = "."
, textcolor = sesc_css
, size = size.tiny
, display = display.all - display.status_line
, editable = false)
plotshape(is_sesc != is_sesc[1] and show_ses_div and show_sesc, "TYO"
, shape.labelup
, location.bottom
, na
, text = "❚"
, textcolor = sesc_css
, size = size.tiny
, display = display.all - display.status_line
, editable = false)
//Plot Divider D
plotshape(is_sesd and show_ses_div and show_sesd, "·"
, shape.labelup
, location.bottom
, na
, text = "."
, textcolor = sesd_css
, size = size.tiny
, display = display.all - display.status_line
, editable = false)
plotshape(is_sesd != is_sesd[1] and show_ses_div and show_sesd, "SYD"
, shape.labelup
, location.bottom
, na
, text = "❚"
, textcolor = sesd_css
, size = size.tiny
, display = display.all - display.status_line
, editable = false)
//-----------------------------------------------------------------------------}
//Plots daily dividers
//-----------------------------------------------------------------------------{
day = dayofweek
if day != day[1] and show_day_div
line.new(n, close + syminfo.mintick, n, close - syminfo.mintick
, color = color.gray
, extend = extend.both
, style = line.style_dashed)
plotshape(day != day[1] and day == 1 and show_day_div, "Sunday"
, shape.labeldown
, location.top
, na
, text = "Sunday"
, textcolor = color.gray
, size = size.tiny
, display = display.all - display.status_line
, editable = false)
plotshape(day != day[1] and day == 2 and show_day_div, "Monday"
, shape.labeldown
, location.top
, na
, text = "Monday"
, textcolor = color.gray
, size = size.tiny
, display = display.all - display.status_line
, editable = false)
plotshape(day != day[1] and day == 3 and show_day_div, "Tuesday"
, shape.labeldown
, location.top
, na
, text = "Tuesday"
, textcolor = color.gray
, size = size.tiny
, display = display.all - display.status_line
, editable = false)
plotshape(day != day[1] and day == 4 and show_day_div, "Wednesay"
, shape.labeldown
, location.top
, na
, text = "Wednesday"
, textcolor = color.gray
, size = size.tiny
, display = display.all - display.status_line
, editable = false)
plotshape(day != day[1] and day == 5 and show_day_div, "Thursday"
, shape.labeldown
, location.top
, na
, text = "Thursday"
, textcolor = color.gray
, size = size.tiny
, display = display.all - display.status_line
, editable = false)
plotshape(day != day[1] and day == 6 and show_day_div, "Friday"
, shape.labeldown
, location.top
, na
, text = "Friday"
, textcolor = color.gray
, size = size.tiny
, display = display.all - display.status_line
, editable = false)
plotshape(day != day[1] and day == 7 and show_day_div, "Saturday"
, shape.labeldown
, location.top
, na
, text = "Saturday"
, textcolor = color.gray
, size = size.tiny
, display = display.all - display.status_line
, editable = false)
//-----------------------------------------------------------------------------}
// --- True range for label positioning ---
tr = ta.tr(true)
// --- Bias Detection and Label ---
var label biasLabel = na
bullishBias = (emaValue > emaValue2) and (emaValue2 > emaValue3)
bearishBias = (emaValue < emaValue2) and (emaValue2 < emaValue3)
if not na(biasLabel)
label.delete(biasLabel)
if bullishBias
biasLabel := label.new(bar_index, low - tr5, "Only Buy", xloc=xloc.bar_index, yloc=yloc.price, style=label.style_label_up, color=color.new(color.teal, 0), textcolor=color.white, size=size.large)
else if bearishBias
biasLabel := label.new(bar_index, high + tr 5, "Only Sell", xloc=xloc.bar_index, yloc=yloc.price, style=label.style_label_down, color=color.new(color.red, 0), textcolor=color.white, size=size.large)
else
// No label if no clear bias, do nothing
na
// === FVG SETTINGS ===
isFvgToShow = input(true, title='Display FVG', group="Fair Value Gap")
bullishFvgColor = input.color(color.new(color.green, 50), 'Bullish FVG Color', group="Fair Value Gap")
bearishFvgColor = input.color(color.new(color.red, 50), 'Bearish FVG Color', group="Fair Value Gap")
mitigatedFvgColor = input.color(color.new(color.gray, 50), 'Mitigated FVG Color', group="Fair Value Gap")
fvgHistoryNbr = input.int(5, 'Number of FVG to show', minval=1, maxval=50, group="Fair Value Gap")
isMitigatedFvgToReduce = input(false, title='Reduce mitigated FVG', group="Fair Value Gap")
// === DATA STRUCTURES ===
// For Liquidity
type liquidity
float value
int barStart
int barEnd
line liquidityLine
bool broken
label sweep
var array bullishLiquidity = array.new()
var array bearishLiquidity = array.new()
// For FVG
var array fvgBoxes = array.new_box(0)
var array fvgTypes = array.new_bool(0)
var array fvgLabels = array.new_label(0)
var array isFvgMitigated = array.new_bool(0)
// === FVG FUNCTIONS ===
FVGDraw(_boxes, _fvgTypes, _isFvgMitigated, _fvgLabels) =>
for [index, value] in _boxes
// Processing bullish FVG
if array.get(_fvgTypes, index)
if low <= box.get_bottom(value)
array.remove(_boxes, index)
array.remove(_fvgTypes, index)
array.remove(_isFvgMitigated, index)
label.delete(array.get(_fvgLabels, index))
array.remove(_fvgLabels, index)
box.delete(value)
else
if low < box.get_top(value)
box.set_bgcolor(value, mitigatedFvgColor)
if not array.get(_isFvgMitigated, index)
alert("FVG has been mitigated", alert.freq_once_per_bar)
array.set(_isFvgMitigated, index, true)
if isMitigatedFvgToReduce
box.set_top(value, low)
box.set_right(value, bar_index)
label.set_x(array.get(_fvgLabels, index), (box.get_left(value) + box.get_right(value)) / 2 )
label.set_y(array.get(_fvgLabels, index), box.get_top(value) - (box.get_top(value) - box.get_bottom(value)) / 2)
// Processing bearish FVG
else
if high >= box.get_top(value)
array.remove(_boxes, index)
array.remove(_fvgTypes, index)
array.remove(_isFvgMitigated, index)
label.delete(array.get(_fvgLabels, index))
array.remove(_fvgLabels, index)
box.delete(value)
else
if high > box.get_bottom(value)
box.set_bgcolor(value, mitigatedFvgColor)
if not array.get(_isFvgMitigated, index)
alert("FVG has been mitigated", alert.freq_once_per_bar)
array.set(_isFvgMitigated, index, true)
if isMitigatedFvgToReduce
box.set_bottom(value, high)
box.set_right(value, bar_index)
label.set_x(array.get(_fvgLabels, index), (box.get_left(value) + box.get_right(value)) / 2 )
label.set_y(array.get(_fvgLabels, index), box.get_top(value) - (box.get_top(value) - box.get_bottom(value)) / 2)
// === LIQUIDITY DETECTION ===
phLiquidity = ta.pivothigh(high, liquidity_len, liquidity_len)
plLiquidity = ta.pivotlow(low, liquidity_len, liquidity_len)
if not na(phLiquidity) and liquidityBool
liquidity newLiquidity = liquidity.new()
newLiquidity.value := high[liquidity_len]
newLiquidity.barStart := time[liquidity_len]
newLiquidity.barEnd := time
newLiquidity.broken := false
newLiquidity.liquidityLine := line.new(x1 = newLiquidity.barStart, y1 = newLiquidity.value, x2 = newLiquidity.barEnd, y2 = newLiquidity.value, xloc = xloc.bar_time, color = downColor, width = 1)
array.push(bearishLiquidity, newLiquidity)
if array.size(bearishLiquidity) > 7
deletedLiquidity = array.shift(bearishLiquidity)
deletedLiquidity.liquidityLine.delete()
if not na(plLiquidity) and liquidityBool
liquidity newLiquidity = liquidity.new()
newLiquidity.value := low[liquidity_len]
newLiquidity.barStart := time[liquidity_len]
newLiquidity.barEnd := time
newLiquidity.broken := false
newLiquidity.liquidityLine := line.new(x1 = newLiquidity.barStart, y1 = newLiquidity.value, x2 = newLiquidity.barEnd, y2 = newLiquidity.value, xloc = xloc.bar_time, color = upColor, width = 1)
array.push(bullishLiquidity, newLiquidity)
if array.size(bullishLiquidity) > 7
deletedLiquidity = array.shift(bullishLiquidity)
deletedLiquidity.liquidityLine.delete()
// === FVG DETECTION ===
isBullishFVG = high[3] < low[1]
isBearishFVG = low[3] > high[1]
if isBullishFVG and isFvgToShow
box _box = box.new(left=bar_index - 2, top=low[1], right=bar_index - 1, bottom=high[3], border_style=line.style_solid, border_width=1, bgcolor=bullishFvgColor, border_color=color.new(color.green, 100))
label _label = label.new(math.ceil((_box.get_left() + _box.get_right()) / 2), _box.get_top() - (_box.get_top() - _box.get_bottom()) / 2, text = ".", style = label.style_none, textcolor = color.rgb(0, 0, 0))
array.push(fvgBoxes, _box)
array.push(fvgTypes, true)
array.push(isFvgMitigated, false)
array.push(fvgLabels, _label)
code Copy code
if array.size(fvgBoxes) > fvgHistoryNbr + 1
box.delete(array.get(fvgBoxes, 0))
label.delete(array.get(fvgLabels, 0))
array.remove(fvgLabels, 0)
array.remove(fvgBoxes, 0)
array.remove(fvgTypes, 0)
array.remove(isFvgMitigated, 0)
if isBearishFVG and isFvgToShow
box _box = box.new(left=bar_index - 2, top=low[3], right=bar_index - 1, bottom=high[1], border_style=line.style_solid, border_width=1, bgcolor=bearishFvgColor, border_color=color.new(color.red, 100))
label _label = label.new(math.ceil((_box.get_left() + _box.get_right()) / 2), _box.get_top() - (_box.get_top() - _box.get_bottom()) / 2, text = ".", style = label.style_none, textcolor = color.rgb(0, 0, 0))
array.push(fvgBoxes, _box)
array.push(fvgTypes, false)
array.push(isFvgMitigated, false)
array.push(fvgLabels, _label)
code Copy code
if array.size(fvgBoxes) > fvgHistoryNbr + 1
box.delete(array.get(fvgBoxes, 0))
label.delete(array.get(fvgLabels, 0))
array.remove(fvgLabels, 0)
array.remove(fvgBoxes, 0)
array.remove(fvgTypes, 0)
array.remove(isFvgMitigated, 0)
// === UPDATE VISUALS ===
// Update Liquidity Lines and Sweeps
var bool sweepAlert = false
if array.size(bearishLiquidity) > 0
liquidity testLiquidity = na
for i = array.size(bearishLiquidity) - 1 to 0 by 1
testLiquidity := array.get(bearishLiquidity, i)
if high > testLiquidity.value
testLiquidity.liquidityLine.set_x2(time)
testLiquidity.liquidityLine.set_style(line.style_dashed)
array.remove(bearishLiquidity, i)
if close < testLiquidity.value
testLiquidity.sweep := label.new(x = time, y = high, text = 'x', xloc = xloc.bar_time, style = label.style_label_down, size = size.normal, textcolor = color.new(color.purple, 0), color = color.new(color.white, 100))
sweepAlert := true
else
testLiquidity.liquidityLine.set_x2(time)
if array.size(bullishLiquidity) > 0
liquidity testLiquidity = na
for i = array.size(bullishLiquidity) - 1 to 0 by 1
testLiquidity := array.get(bullishLiquidity, i)
if low < testLiquidity.value
testLiquidity.liquidityLine.set_x2(time)
testLiquidity.liquidityLine.set_style(line.style_dashed)
array.remove(bullishLiquidity, i)
if close > testLiquidity.value
testLiquidity.sweep := label.new(x = time, y = low, text = 'x', xloc = xloc.bar_time, style = label.style_label_up, size = size.normal, textcolor = color.new(color.teal, 0), color = color.new(color.white, 100))
sweepAlert := true
else
testLiquidity.liquidityLine.set_x2(time)
// Update FVGs
FVGDraw(fvgBoxes, fvgTypes, isFvgMitigated, fvgLabels)
// === ALERTS ===
alertcondition(sweepAlert, title = "Liquidity Sweep", message = "A liquidity zone has been swept.")
sweepAlert := false
// === PREVIOUS DAY HIGH/LOW SETTINGS ===
showPrevDayRange = input.bool(true, 'Show Previous Day High/Low', group='Previous Day Range')
prevDayColorHigh = input.color(color.new(color.blue, 0), 'Previous Day High Color', group='Previous Day Range')
prevDayColorLow = input.color(color.new(color.orange, 0), 'Previous Day Low Color', group='Previous Day Range')
prevDayLineWidth = input.int(2, 'Previous Day Line Width', minval=1, maxval=5, group='Previous Day Range')
prevDayLineStyle = input.string('Dashed', 'Previous Day Line Style', options=['Dashed', 'Dotted'], group='Previous Day Range')
// Convert line style string to line.style constant
lineStyle = prevDayLineStyle == 'Dotted' ? line.style_dotted : line.style_dashed
// Get previous day timeframe string or use 'D'
dailyTF = "D" // fixed daily timeframe
// Request previous daily data (high/low) and previous day start timestamp (session start)
prevDayHigh = request.security(syminfo.tickerid, dailyTF, high[1], lookahead=barmerge.lookahead_on)
prevDayLow = request.security(syminfo.tickerid, dailyTF, low[1], lookahead=barmerge.lookahead_on)
prevDayTime = request.security(syminfo.tickerid, dailyTF, time[1], lookahead=barmerge.lookahead_on) // Timestamp of previous daily bar start
// Variables to hold lines just once (persistent)
var line prevHighLine = na
var line prevLowLine = na
// Calculate approximate timeframe minutes and future time offset
tf_minutes = timeframe.multiplier * (timeframe.isintraday ? 1 : 1440)
futureBarsCount = 500
futureDeltaMs = tf_minutes * 60000 * futureBarsCount
lineEndTime = time + futureDeltaMs
if showPrevDayRange
if na(prevHighLine)
prevHighLine := line.new(x1=prevDayTime, y1=prevDayHigh, x2=lineEndTime, y2=prevDayHigh, xloc=xloc.bar_time, color=prevDayColorHigh, width=prevDayLineWidth, style=lineStyle)
else
line.set_xy1(prevHighLine, prevDayTime, prevDayHigh)
line.set_xy2(prevHighLine, lineEndTime, prevDayHigh)
code Copy code
if na(prevLowLine)
prevLowLine := line.new(x1=prevDayTime, y1=prevDayLow, x2=lineEndTime, y2=prevDayLow, xloc=xloc.bar_time, color=prevDayColorLow, width=prevDayLineWidth, style=lineStyle)
else
line.set_xy1(prevLowLine, prevDayTime, prevDayLow)
line.set_xy2(prevLowLine, lineEndTime, prevDayLow)
else
if not na(prevHighLine)
line.delete(prevHighLine)
prevHighLine := na
if not na(prevLowLine)
line.delete(prevLowLine)
prevLowLine := na
//@version=5
indicator("Sessions + Liquidity Lines & FVG [Merged]", overlay=true, max_lines_count=500, max_boxes_count=500, max_labels_count=500)
// ----------- SESSIONS [LuxAlgo] CODE START -----------
// (Paste your entire Sessions indicator code here, copy-pasted exactly as you posted, minus the first 3 or so header lines and indicator() declaration)
// For brevity, let's say it's pasted here
// Remember to remove the `indicator(...)` line from the pasted session code.
// ----------- SESSIONS [LuxAlgo] CODE END -----------
// ----------- LIQUIDITY + FVG [Lucien] CODE START -----------
// === LIQUIDITY SETTINGS ===
liquidityBool = input.bool(true, 'Show Liquidity Sweeps', group = 'Liquidity Settings')
liquidity_len = input.int(30, 'Liquidity Length', minval = 5, group = 'Liquidity Settings')
upColor = input.color(color.new(color.teal, 15), title = 'Bullish Liquidity Color', group = 'Liquidity Settings')
downColor = input.color(color.new(color.red, 15), title = 'Bearish Liquidity Color', group = 'Liquidity Settings')
// === EMA SETTINGS ===
showEma = input.bool(true, title="Show EMA", group="Moving Average")
emaLength = input.int(50, title="EMA Length", minval=1, group="Moving Average")
emaSource = input.source(close, title="EMA Source", group="Moving Average")
emaTimeframe = input.timeframe("", title="EMA Timeframe (leave empty for current)", group="Moving Average")
emaColor = input.color(color.new(color.orange, 0), title="EMA Color", group="Moving Average")
emaWidth = input.int(2, title="EMA Line Width", minval=1, maxval=5, group="Moving Average")
// === EMA 2 SETTINGS ===
showEma2 = input.bool(true, title="Show EMA 2", group="Moving Average")
ema2Length = input.int(100, title="EMA 2 Length", minval=1, group="Moving Average")
ema2Source = input.source(close, title="EMA 2 Source", group="Moving Average")
ema2Timeframe = input.timeframe("", title="EMA 2 Timeframe (leave empty for current)", group="Moving Average")
ema2Color = input.color(color.new(color.blue, 0), title="EMA 2 Color", group="Moving Average")
ema2Width = input.int(2, title="EMA 2 Line Width", minval=1, maxval=5, group="Moving Average")
// === EMA 3 SETTINGS ===
showEma3 = input.bool(true, title="Show EMA 3", group="Moving Average")
ema3Length = input.int(200, title="EMA 3 Length", minval=1, group="Moving Average")
ema3Source = input.source(close, title="EMA 3 Source", group="Moving Average")
ema3Timeframe = input.timeframe("", title="EMA 3 Timeframe (leave empty for current)", group="Moving Average")
ema3Color = input.color(color.new(color.purple, 0), title="EMA 3 Color", group="Moving Average")
ema3Width = input.int(2, title="EMA 3 Line Width", minval=1, maxval=5, group="Moving Average")
// Calculate EMA 1 with timeframe option
emaValue = request.security(syminfo.tickerid, emaTimeframe != "" ? emaTimeframe : timeframe.period, ta.ema(emaSource, emaLength))
plot(showEma ? emaValue : na, title="EMA", color=emaColor, linewidth=emaWidth)
// Calculate EMA 2 with timeframe option
emaValue2 = request.security(syminfo.tickerid, ema2Timeframe != "" ? ema2Timeframe : timeframe.period, ta.ema(ema2Source, ema2Length))
plot(showEma2 ? emaValue2 : na, title="EMA 2", color=ema2Color, linewidth=ema2Width)
// Calculate EMA 3 with timeframe option
emaValue3 = request.security(syminfo.tickerid, ema3Timeframe != "" ? ema3Timeframe : timeframe.period, ta.ema(ema3Source, ema3Length))
plot(showEma3 ? emaValue3 : na, title="EMA 3", color=ema3Color, linewidth=ema3Width)
// --- True range for label positioning ---
tr = ta.tr(true)
// --- Bias Detection and Label ---
var label biasLabel = na
bullishBias = (emaValue > emaValue2) and (emaValue2 > emaValue3)
bearishBias = (emaValue < emaValue2) and (emaValue2 < emaValue3)
if not na(biasLabel)
label.delete(biasLabel)
if bullishBias
biasLabel := label.new(bar_index, low - tr*5, "Only Buy", xloc=xloc.bar_index, yloc=yloc.price, style=label.style_label_up, color=color.new(color.teal, 0), textcolor=color.white, size=size.large)
else if bearishBias
biasLabel := label.new(bar_index, high + tr*5, "Only Sell", xloc=xloc.bar_index, yloc=yloc.price, style=label.style_label_down, color=color.new(color.red, 0), textcolor=color.white, size=size.large)
// === FVG SETTINGS ===
isFvgToShow = input(true, title='Display FVG', group="Fair Value Gap")
bullishFvgColor = input.color(color.new(color.green, 50), 'Bullish FVG Color', group="Fair Value Gap")
bearishFvgColor = input.color(color.new(color.red, 50), 'Bearish FVG Color', group="Fair Value Gap")
mitigatedFvgColor = input.color(color.new(color.gray, 50), 'Mitigated FVG Color', group="Fair Value Gap")
fvgHistoryNbr = input.int(5, 'Number of FVG to show', minval=1, maxval=50, group="Fair Value Gap")
isMitigatedFvgToReduce = input(false, title='Reduce mitigated FVG', group="Fair Value Gap")
// === DATA STRUCTURES ===
// For Liquidity
type liquidity
float value
int barStart
int barEnd
line liquidityLine
bool broken
label sweep
var array<liquidity> bullishLiquidity = array.new<liquidity>()
var array<liquidity> bearishLiquidity = array.new<liquidity>()
// For FVG
var array<box> fvgBoxes = array.new_box(0)
var array<bool> fvgTypes = array.new_bool(0)
var array<label> fvgLabels = array.new_label(0)
var array<bool> isFvgMitigated = array.new_bool(0)
// === FVG FUNCTIONS ===
FVGDraw(_boxes, _fvgTypes, _isFvgMitigated, _fvgLabels) =>
for [index, value] in _boxes
// Processing bullish FVG
if array.get(_fvgTypes, index)
if low <= box.get_bottom(value)
array.remove(_boxes, index)
array.remove(_fvgTypes, index)
array.remove(_isFvgMitigated, index)
label.delete(array.get(_fvgLabels, index))
array.remove(_fvgLabels, index)
box.delete(value)
else
if low < box.get_top(value)
box.set_bgcolor(value, mitigatedFvgColor)
if not array.get(_isFvgMitigated, index)
alert("FVG has been mitigated", alert.freq_once_per_bar)
array.set(_isFvgMitigated, index, true)
if isMitigatedFvgToReduce
box.set_top(value, low)
box.set_right(value, bar_index)
label.set_x(array.get(_fvgLabels, index), (box.get_left(value) + box.get_right(value)) / 2 )
label.set_y(array.get(_fvgLabels, index), box.get_top(value) - (box.get_top(value) - box.get_bottom(value)) / 2)
// Processing bearish FVG
else
if high >= box.get_top(value)
array.remove(_boxes, index)
array.remove(_fvgTypes, index)
array.remove(_isFvgMitigated, index)
label.delete(array.get(_fvgLabels, index))
array.remove(_fvgLabels, index)
box.delete(value)
else
if high > box.get_bottom(value)
box.set_bgcolor(value, mitigatedFvgColor)
if not array.get(_isFvgMitigated, index)
alert("FVG has been mitigated", alert.freq_once_per_bar)
array.set(_isFvgMitigated, index, true)
if isMitigatedFvgToReduce
box.set_bottom(value, high)
box.set_right(value, bar_index)
label.set_x(array.get(_fvgLabels, index), (box.get_left(value) + box.get_right(value)) / 2 )
label.set_y(array.get(_fvgLabels, index), box.get_top(value) - (box.get_top(value) - box.get_bottom(value)) / 2)
// === LIQUIDITY DETECTION ===
phLiquidity = ta.pivothigh(high, liquidity_len, liquidity_len)
plLiquidity = ta.pivotlow(low, liquidity_len, liquidity_len)
if not na(phLiquidity) and liquidityBool
liquidity newLiquidity = liquidity.new()
newLiquidity.value := high[liquidity_len]
newLiquidity.barStart := time[liquidity_len]
newLiquidity.barEnd := time
newLiquidity.broken := false
newLiquidity.liquidityLine := line.new(x1 = newLiquidity.barStart, y1 = newLiquidity.value, x2 = newLiquidity.barEnd, y2 = newLiquidity.value, xloc = xloc.bar_time, color = downColor, width = 1)
array.push(bearishLiquidity, newLiquidity)
if array.size(bearishLiquidity) > 7
deletedLiquidity = array.shift(bearishLiquidity)
deletedLiquidity.liquidityLine.delete()
if not na(plLiquidity) and liquidityBool
liquidity newLiquidity = liquidity.new()
newLiquidity.value := low[liquidity_len]
newLiquidity.barStart := time[liquidity_len]
newLiquidity.barEnd := time
newLiquidity.broken := false
newLiquidity.liquidityLine := line.new(x1 = newLiquidity.barStart, y1 = newLiquidity.value, x2 = newLiquidity.barEnd, y2 = newLiquidity.value, xloc = xloc.bar_time, color = upColor, width = 1)
array.push(bullishLiquidity, newLiquidity)
if array.size(bullishLiquidity) > 7
deletedLiquidity = array.shift(bullishLiquidity)
deletedLiquidity.liquidityLine.delete()
// === FVG DETECTION ===
isBullishFVG = high[3] < low[1]
isBearishFVG = low[3] > high[1]
if isBullishFVG and isFvgToShow
box _box = box.new(left=bar_index - 2, top=low[1], right=bar_index - 1, bottom=high[3], border_style=line.style_solid, border_width=1, bgcolor=bullishFvgColor, border_color=color.new(color.green, 100))
label _label = label.new(math.ceil((_box.get_left() + _box.get_right()) / 2), _box.get_top() - (_box.get_top() - _box.get_bottom()) / 2, text = ".", style = label.style_none, textcolor = color.rgb(0, 0, 0))
array.push(fvgBoxes, _box)
array.push(fvgTypes, true)
array.push(isFvgMitigated, false)
array.push(fvgLabels, _label)
if array.size(fvgBoxes) > fvgHistoryNbr + 1
box.delete(array.get(fvgBoxes, 0))
label.delete(array.get(fvgLabels, 0))
array.remove(fvgLabels, 0)
array.remove(fvgBoxes, 0)
array.remove(fvgTypes, 0)
array.remove(isFvgMitigated, 0)
if isBearishFVG and isFvgToShow
box _box = box.new(left=bar_index - 2, top=low[3], right=bar_index - 1, bottom=high[1], border_style=line.style_solid, border_width=1, bgcolor=bearishFvgColor, border_color=color.new(color.red, 100))
label _label = label.new(math.ceil((_box.get_left() + _box.get_right()) / 2), _box.get_top() - (_box.get_top() - _box.get_bottom()) / 2, text = ".", style = label.style_none, textcolor = color.rgb(0, 0, 0))
array.push(fvgBoxes, _box)
array.push(fvgTypes, false)
array.push(isFvgMitigated, false)
array.push(fvgLabels, _label)
if array.size(fvgBoxes) > fvgHistoryNbr + 1
box.delete(array.get(fvgBoxes, 0))
label.delete(array.get(fvgLabels, 0))
array.remove(fvgLabels, 0)
array.remove(fvgBoxes, 0)
array.remove(fvgTypes, 0)
array.remove(isFvgMitigated, 0)
// === UPDATE VISUALS ===
// Update Liquidity Lines and Sweeps
var bool sweepAlert = false
if array.size(bearishLiquidity) > 0
liquidity testLiquidity = na
for i = array.size(bearishLiquidity) - 1 to 0 by 1
testLiquidity := array.get(bearishLiquidity, i)
if high > testLiquidity.value
testLiquidity.liquidityLine.set_x2(time)
testLiquidity.liquidityLine.set_style(line.style_dashed)
array.remove(bearishLiquidity, i)
if close < testLiquidity.value
testLiquidity.sweep := label.new(x = time, y = high, text = 'x', xloc = xloc.bar_time, style = label.style_label_down, size = size.normal, textcolor = color.new(color.purple, 0), color = color.new(color.white, 100))
sweepAlert := true
else
testLiquidity.liquidityLine.set_x2(time)
if array.size(bullishLiquidity) > 0
liquidity testLiquidity = na
for i = array.size(bullishLiquidity) - 1 to 0 by 1
testLiquidity := array.get(bullishLiquidity, i)
if low < testLiquidity.value
testLiquidity.liquidityLine.set_x2(time)
testLiquidity.liquidityLine.set_style(line.style_dashed)
array.remove(bullishLiquidity, i)
if close > testLiquidity.value
testLiquidity.sweep := label.new(x = time, y = low, text = 'x', xloc = xloc.bar_time, style = label.style_label_up, size = size.normal, textcolor = color.new(color.teal, 0), color = color.new(color.white, 100))
sweepAlert := true
else
testLiquidity.liquidityLine.set_x2(time)
// Update FVGs
FVGDraw(fvgBoxes, fvgTypes, isFvgMitigated, fvgLabels)
// === ALERTS ===
alertcondition(sweepAlert, title = "Liquidity Sweep", message = "A liquidity zone has been swept.")
sweepAlert := false
// === PREVIOUS DAY HIGH/LOW SETTINGS ===
showPrevDayRange = input.bool(true, 'Show Previous Day High/Low', group='Previous Day Range')
prevDayColorHigh = input.color(color.new(color.blue, 0), 'Previous Day High Color', group='Previous Day Range')
prevDayColorLow = input.color(color.new(color.orange, 0), 'Previous Day Low Color', group='Previous Day Range')
prevDayLineWidth = input.int(2, 'Previous Day Line Width', minval=1, maxval=5, group='Previous Day Range')
prevDayLineStyle = input.string('Dashed', 'Previous Day Line Style', options=['Dashed', 'Dotted'], group='Previous Day Range')
lineStyle = prevDayLineStyle == 'Dotted' ? line.style_dotted : line.style_dashed
dailyTF = "D"
prevDayHigh = request.security(syminfo.tickerid, dailyTF, high[1], lookahead=barmerge.lookahead_on)
prevDayLow = request.security(syminfo.tickerid, dailyTF, low[1], lookahead=barmerge.lookahead_on)
prevDayTime = request.security(syminfo.tickerid, dailyTF, time[1], lookahead=barmerge.lookahead_on)
var line prevHighLine = na
var line prevLowLine = na
tf_minutes = timeframe.multiplier * (timeframe.isintraday ? 1 : 1440)
futureBarsCount = 500
futureDeltaMs = tf_minutes * 60000 * futureBarsCount
lineEndTime = time + futureDeltaMs
if showPrevDayRange
if na(prevHighLine)
prevHighLine := line.new(x1=prevDayTime, y1=prevDayHigh, x2=lineEndTime, y2=prevDayHigh, xloc=xloc.bar_time, color=prevDayColorHigh, width=prevDayLineWidth, style=lineStyle)
else
line.set_xy1(prevHighLine, prevDayTime, prevDayHigh)
line.set_xy2(prevHighLine, lineEndTime, prevDayHigh)
if na(prevLowLine)
prevLowLine := line.new(x1=prevDayTime, y1=prevDayLow, x2=lineEndTime, y2=prevDayLow, xloc=xloc.bar_time, color=prevDayColorLow, width=prevDayLineWidth, style=lineStyle)
else
line.set_xy1(prevLowLine, prevDayTime, prevDayLow)
line.set_xy2(prevLowLine, lineEndTime, prevDayLow)
else
if not na(prevHighLine)
line.delete(prevHighLine)
prevHighLine := na
if not na(prevLowLine)
line.delete(prevLowLine)
prevLowLine := na
Notes:
You must paste the full first indicator code (minus the indicator() line) where commented .
Remove the //@version=6 line from the second indicator and change it to //@version=5 at top.
Adjust your max_*_count parameters accordingly if you get warnings/errors about resource limits.
The merged script will keep the UI inputs separate thanks to groups: "Session A/B/C/D", "Liquidity Settings", "Fair Value Gap", "Moving Average", etc.
Both indicators’ plots, boxes, lines, and labels will appear together.
You may want to check performance and disable features that make your chart slow.
If you'd like me to prepare and send you the fully merged script with the full first script included, please confirm, and I can do that for you!
//@version=5
indicator("Liquidity Lines & Sweeps + FVG [Lucien] + Sessions [LuxAlgo]", overlay=true, max_lines_count=1000, max_boxes_count=1000, max_labels_count=1000)
// ========== SESSIONS [LUXALGO] CODE START ==========
//------------------------------------------------------------------------------
//Settings
//-----------------------------------------------------------------------------{
//Session A
show_sesa = input(true, '', inline = 'sesa', group = 'Session A')
sesa_txt = input('New York', '', inline = 'sesa', group = 'Session A')
sesa_ses = input.session('1300-2200', '', inline = 'sesa', group = 'Session A')
sesa_css = input.color(#ff5d00, '', inline = 'sesa', group = 'Session A')
sesa_range = input(true, 'Range', inline = 'sesa_overlays', group = 'Session A')
sesa_tl = input(false, 'Trendline', inline = 'sesa_overlays', group = 'Session A')
sesa_avg = input(false, 'Mean', inline = 'sesa_overlays', group = 'Session A')
sesa_vwap = input(false, 'VWAP', inline = 'sesa_overlays', group = 'Session A')
sesa_maxmin = input(false, 'Max/Min', inline = 'sesa_overlays', group = 'Session A')
//Session B
show_sesb = input(true, '', inline = 'sesb', group = 'Session B')
sesb_txt = input('London', '', inline = 'sesb', group = 'Session B')
sesb_ses = input.session('0700-1600', '', inline = 'sesb', group = 'Session B')
sesb_css = input.color(#2157f3, '', inline = 'sesb', group = 'Session B')
sesb_range = input(true, 'Range', inline = 'sesb_overlays', group = 'Session B')
sesb_tl = input(false, 'Trendline', inline = 'sesb_overlays', group = 'Session B')
sesb_avg = input(false, 'Mean', inline = 'sesb_overlays', group = 'Session B')
sesb_vwap = input(false, 'VWAP', inline = 'sesb_overlays', group = 'Session B')
sesb_maxmin = input(false, 'Max/Min', inline = 'sesb_overlays', group = 'Session B')
//Session C
show_sesc = input(true, '', inline = 'sesc', group = 'Session C')
sesc_txt = input('Tokyo', '', inline = 'sesc', group = 'Session C')
sesc_ses = input.session('0000-0900', '', inline = 'sesc', group = 'Session C')
sesc_css = input.color(#e91e63, '', inline = 'sesc', group = 'Session C')
sesc_range = input(true, 'Range', inline = 'sesc_overlays', group = 'Session C')
sesc_tl = input(false, 'Trendline', inline = 'sesc_overlays', group = 'Session C')
sesc_avg = input(false, 'Mean', inline = 'sesc_overlays', group = 'Session C')
sesc_vwap = input(false, 'VWAP', inline = 'sesc_overlays', group = 'Session C')
sesc_maxmin = input(false, 'Max/Min', inline = 'sesc_overlays', group = 'Session C')
//Session D
show_sesd = input(true, '', inline = 'sesd', group = 'Session D')
sesd_txt = input('Sydney', '', inline = 'sesd', group = 'Session D')
sesd_ses = input.session('2100-0600', '', inline = 'sesd', group = 'Session D')
sesd_css = input.color(#ffeb3b, '', inline = 'sesd', group = 'Session D')
sesd_range = input(true, 'Range', inline = 'sesd_overlays', group = 'Session D')
sesd_tl = input(false, 'Trendline', inline = 'sesd_overlays', group = 'Session D')
sesd_avg = input(false, 'Mean', inline = 'sesd_overlays', group = 'Session D')
sesd_vwap = input(false, 'VWAP', inline = 'sesd_overlays', group = 'Session D')
sesd_maxmin = input(false, 'Max/Min', inline = 'sesd_overlays', group = 'Session D')
//Timezones
tz_incr = input.int(0, 'UTC (+/-)', group = 'Timezone')
use_exchange = input(false, 'Use Exchange Timezone', group = 'Timezone')
//Ranges Options
bg_transp = input.float(90, 'Range Area Transparency', group = 'Ranges Settings')
show_outline = input(true, 'Range Outline', group = 'Ranges Settings')
show_txt = input(true, 'Range Label', group = 'Ranges Settings')
//Dashboard
show_dash = input(false, 'Show Dashboard', group = 'Dashboard')
advanced_dash = input(false, 'Advanced Dashboard', group = 'Dashboard')
dash_loc = input.string('Top Right', 'Dashboard Location', options = ['Top Right', 'Bottom Right', 'Bottom Left'], group = 'Dashboard')
text_size = input.string('Small', 'Dashboard Size', options = ['Tiny', 'Small', 'Normal'], group = 'Dashboard')
//Divider
show_ses_div = input(false, 'Show Sessions Divider', group = 'Dividers')
show_day_div = input(true, 'Show Daily Divider', group = 'Dividers')
//-----------------------------------------------------------------------------}
//Functions
//-----------------------------------------------------------------------------{
n = bar_index
//Get session average
get_avg(session)=>
var len = 1
var float csma = na
var float sma = na
if session > session[1]
len := 1
csma := close
if session and session == session[1]
len += 1
csma += close
sma := csma / len
sma
//Get trendline coordinates
get_linreg(session)=>
var len = 1
var float cwma = na
var float csma = na
var float csma2 = na
var float y1 = na
var float y2 = na
var float stdev = na
var float r2 = na
if session > session[1]
len := 1
cwma := close
csma := close
csma2 := close * close
if session and session == session[1]
len += 1
csma += close
csma2 += close * close
cwma += close * len
sma = csma / len
wma = cwma / (len * (len + 1) / 2)
cov = (wma - sma) * (len+1)/2
stdev := math.sqrt(csma2 / len - sma * sma)
r2 := cov / (stdev * (math.sqrt(len*len - 1) / (2 * math.sqrt(3))))
y1 := 4 * sma - 3 * wma
y2 := 3 * wma - 2 * sma
[y1 , y2, stdev, r2]
//Session Vwap
get_vwap(session) =>
var float num = na
var float den = na
if session > session[1]
num := close * volume
den := volume
else if session and session == session[1]
num += close * volume
den += volume
else
num := na
[num, den]
//Set line
set_line(session, y1, y2, session_css)=>
var line tl = na
if session > session[1]
tl := line.new(n, close, n, close, color = session_css)
if session and session == session[1]
line.set_y1(tl, y1)
line.set_xy2(tl, n, y2)
//Set session range
get_range(session, session_name, session_css)=>
var t = 0
var max = high
var min = low
var box bx = na
var label lbl = na
if session > session[1]
t := time
max := high
min := low
bx := box.new(n, max, n, min
, bgcolor = color.new(session_css, bg_transp)
, border_color = show_outline ? session_css : na
, border_style = line.style_dotted)
if show_txt
lbl := label.new(t, max, session_name
, xloc = xloc.bar_time
, textcolor = session_css
, style = label.style_label_down
, color = color.new(color.white, 100)
, size = size.tiny)
if session and session == session[1]
max := math.max(high, max)
min := math.min(low, min)
box.set_top(bx, max)
box.set_rightbottom(bx, n, min)
if show_txt
label.set_xy(lbl, int(math.avg(t, time)), max)
[session ? na : max, session ? na : min]
//-----------------------------------------------------------------------------}
//Sessions
//-----------------------------------------------------------------------------{
tf = timeframe.period
var tz = use_exchange ? syminfo.timezone :
str.format('UTC{0}{1}', tz_incr >= 0 ? '+' : '-', math.abs(tz_incr))
is_sesa = math.sign(nz(time(tf, sesa_ses, tz)))
is_sesb = math.sign(nz(time(tf, sesb_ses, tz)))
is_sesc = math.sign(nz(time(tf, sesc_ses, tz)))
is_sesd = math.sign(nz(time(tf, sesd_ses, tz)))
//-----------------------------------------------------------------------------}
//Dashboard
//-----------------------------------------------------------------------------{
var table_position = dash_loc == 'Bottom Left' ? position.bottom_left
: dash_loc == 'Top Right' ? position.top_right
: position.bottom_right
var table_size = text_size == 'Tiny' ? size.tiny
: text_size == 'Small' ? size.small
: size.normal
var tb = table.new(table_position, 5, 6
, bgcolor = #1e222d
, border_color = #373a46
, border_width = 1
, frame_color = #373a46
, frame_width = 1)
if barstate.isfirst and show_dash
table.cell(tb, 0, 0, 'LuxAlgo', text_color = color.white, text_size = table_size)
table.merge_cells(tb, 0, 0, 4, 0)
table.cell(tb, 0, 2, sesa_txt, text_color = sesa_css, text_size = table_size)
table.cell(tb, 0, 3, sesb_txt, text_color = sesb_css, text_size = table_size)
table.cell(tb, 0, 4, sesc_txt, text_color = sesc_css, text_size = table_size)
table.cell(tb, 0, 5, sesd_txt, text_color = sesd_css, text_size = table_size)
if advanced_dash
table.cell(tb, 0, 1, 'Session', text_color = color.white
, text_size = table_size)
table.cell(tb, 1, 1, 'Status', text_color = color.white
, text_size = table_size)
table.cell(tb, 2, 1, 'Trend', text_color = color.white
, text_size = table_size)
table.cell(tb, 3, 1, 'Volume', text_color = color.white
, text_size = table_size)
table.cell(tb, 4, 1, 'σ', text_color = color.white
, text_size = table_size)
if barstate.islast and show_dash
table.cell(tb, 1, 2, is_sesa ? 'Active' : 'Innactive'
, bgcolor = is_sesa ? #089981 : #f23645
, text_color = color.white
, text_size = table_size)
table.cell(tb, 1, 3, is_sesb ? 'Active' : 'Innactive'
, bgcolor = is_sesb ? #089981 : #f23645
, text_color = color.white
, text_size = table_size)
table.cell(tb, 1, 4, is_sesc ? 'Active' : 'Innactive'
, bgcolor = is_sesc ? #089981 : #f23645
, text_color = color.white
, text_size = table_size)
table.cell(tb, 1, 5, is_sesd ? 'Active' : 'Innactive'
, bgcolor = is_sesd ? #089981 : #f23645
, text_color = color.white
, text_size = table_size)
//-----------------------------------------------------------------------------}
//Overlays
//-----------------------------------------------------------------------------{
var float max_sesa = na
var float min_sesa = na
var float max_sesb = na
var float min_sesb = na
var float max_sesc = na
var float min_sesc = na
var float max_sesd = na
var float min_sesd = na
//Ranges
if show_sesa and sesa_range
[max, min] = get_range(is_sesa, sesa_txt, sesa_css)
max_sesa := max
min_sesa := min
if show_sesb and sesb_range
[max, min] = get_range(is_sesb, sesb_txt, sesb_css)
max_sesb := max
min_sesb := min
if show_sesc and sesc_range
[max, min] = get_range(is_sesc, sesc_txt, sesc_css)
max_sesc := max
min_sesc := min
if show_sesd and sesd_range
[max, min] = get_range(is_sesd, sesd_txt, sesd_css)
max_sesd := max
min_sesd := min
//Trendlines
if show_sesa and (sesa_tl or advanced_dash)
[y1, y2, stdev, r2] = get_linreg(is_sesa)
if advanced_dash
table.cell(tb, 2, 2, str.tostring(r2, '#.##')
, bgcolor = r2 > 0 ? #089981 : #f23645
, text_color = color.white
, text_size = table_size)
table.cell(tb, 4, 2, str.tostring(stdev, '#.####')
, text_color = color.white
, text_size = table_size)
if sesa_tl
set_line(is_sesa, y1, y2, sesa_css)
if show_sesb and (sesb_tl or advanced_dash)
[y1, y2, stdev, r2] = get_linreg(is_sesb)
if advanced_dash
table.cell(tb, 2, 3, str.tostring(r2, '#.##')
, bgcolor = r2 > 0 ? #089981 : #f23645
, text_color = color.white
, text_size = table_size)
table.cell(tb, 4, 3, str.tostring(stdev, '#.####')
, text_color = color.white
, text_size = table_size)
if sesb_tl
set_line(is_sesb, y1, y2, sesb_css)
if show_sesc and (sesc_tl or advanced_dash)
[y1, y2, stdev, r2] = get_linreg(is_sesc)
if advanced_dash
table.cell(tb, 2, 4, str.tostring(r2, '#.##')
, bgcolor = r2 > 0 ? #089981 : #f23645
, text_color = color.white
, text_size = table_size)
table.cell(tb, 4, 4, str.tostring(stdev, '#.####')
, text_color = color.white
, text_size = table_size)
if sesc_tl
set_line(is_sesc, y1, y2, sesc_css)
if show_sesd and (sesd_tl or advanced_dash)
[y1, y2, stdev, r2] = get_linreg(is_sesd)
if advanced_dash
table.cell(tb, 2, 5, str.tostring(r2, '#.##')
, bgcolor = r2 > 0 ? #089981 : #f23645
, text_color = color.white
, text_size = table_size)
table.cell(tb, 4, 5, str.tostring(stdev, '#.####')
, text_color = color.white
, text_size = table_size)
if sesd_tl
set_line(is_sesd, y1, y2, sesd_css)
//Mean
if show_sesa and sesa_avg
avg = get_avg(is_sesa)
set_line(is_sesa, avg, avg, sesa_css)
if show_sesb and sesb_avg
avg = get_avg(is_sesb)
set_line(is_sesb, avg, avg, sesb_css)
if show_sesc and sesc_avg
avg = get_avg(is_sesc)
set_line(is_sesc, avg, avg, sesc_css)
if show_sesd and sesd_avg
avg = get_avg(is_sesd)
set_line(is_sesd, avg, avg, sesd_css)
//VWAP
var float vwap_a = na
var float vwap_b = na
var float vwap_c = na
var float vwap_d = na
if show_sesa and (sesa_vwap or advanced_dash)
[num, den] = get_vwap(is_sesa)
if sesa_vwap
vwap_a := num / den
if advanced_dash
table.cell(tb, 3, 2, str.tostring(den, format.volume)
, text_color = color.white
, text_size = table_size)
if show_sesb and (sesb_vwap or advanced_dash)
[num, den] = get_vwap(is_sesb)
if sesb_vwap
vwap_b := num / den
if advanced_dash
table.cell(tb, 3, 3, str.tostring(den, format.volume)
, text_color = color.white
, text_size = table_size)
if show_sesc and (sesc_vwap or advanced_dash)
[num, den] = get_vwap(is_sesc)
if sesc_vwap
vwap_c := num / den
if advanced_dash
table.cell(tb, 3, 4, str.tostring(den, format.volume)
, text_color = color.white
, text_size = table_size)
if show_sesd and (sesd_vwap or advanced_dash)
[num, den] = get_vwap(is_sesd)
if sesd_vwap
vwap_d := num / den
if advanced_dash
table.cell(tb, 3, 5, str.tostring(den, format.volume)
, text_color = color.white
, text_size = table_size)
//-----------------------------------------------------------------------------}
//Plots
//-----------------------------------------------------------------------------{
//Plot max/min
plot(sesa_maxmin ? max_sesa : na, 'Session A Maximum', sesa_css, 1, plot.style_linebr)
plot(sesa_maxmin ? min_sesa : na, 'Session A Minimum', sesa_css, 1, plot.style_linebr)
plot(sesb_maxmin ? max_sesb : na, 'Session B Maximum', sesb_css, 1, plot.style_linebr)
plot(sesb_maxmin ? min_sesb : na, 'Session B Minimum', sesb_css, 1, plot.style_linebr)
plot(sesc_maxmin ? max_sesc : na, 'Session C Maximum', sesc_css, 1, plot.style_linebr)
plot(sesc_maxmin ? min_sesc : na, 'Session C Minimum', sesc_css, 1, plot.style_linebr)
plot(sesd_maxmin ? max_sesd : na, 'Session D Maximum', sesd_css, 1, plot.style_linebr)
plot(sesd_maxmin ? min_sesd : na, 'Session D Minimum', sesd_css, 1, plot.style_linebr)
//Plot vwaps
plot(vwap_a, 'Session A VWAP', sesa_css, 1, plot.style_linebr)
plot(vwap_b, 'Session B VWAP', sesb_css, 1, plot.style_linebr)
plot(vwap_c, 'Session C VWAP', sesc_css, 1, plot.style_linebr)
plot(vwap_d, 'Session D VWAP', sesd_css, 1, plot.style_linebr)
//Plot Divider A
plotshape(is_sesa and show_ses_div and show_sesa, "·"
, shape.square
, location.bottom
, na
, text = "."
, textcolor = sesa_css
, size = size.tiny
, display = display.all - display.status_line
, editable = false)
plotshape(is_sesa != is_sesa[1] and show_ses_div and show_sesa, "NYE"
, shape.labelup
, location.bottom
, na
, text = "❚"
, textcolor = sesa_css
, size = size.tiny
, display = display.all - display.status_line
, editable = false)
//Plot Divider B
plotshape(is_sesb and show_ses_div and show_sesb, "·"
, shape.labelup
, location.bottom
, na
, text = "."
, textcolor = sesb_css
, size = size.tiny
, display = display.all - display.status_line
, editable = false)
plotshape(is_sesb != is_sesb[1] and show_ses_div and show_sesb, "LDN"
, shape.labelup
, location.bottom
, na
, text = "❚"
, textcolor = sesb_css
, size = size.tiny
, display = display.all - display.status_line
, editable = false)
//Plot Divider C
plotshape(is_sesc and show_ses_div and show_sesc, "·"
, shape.square
, location.bottom
, na
, text = "."
, textcolor = sesc_css
, size = size.tiny
, display = display.all - display.status_line
, editable = false)
plotshape(is_sesc != is_sesc[1] and show_ses_div and show_sesc, "TYO"
, shape.labelup
, location.bottom
, na
, text = "❚"
, textcolor = sesc_css
, size = size.tiny
, display = display.all - display.status_line
, editable = false)
//Plot Divider D
plotshape(is_sesd and show_ses_div and show_sesd, "·"
, shape.labelup
, location.bottom
, na
, text = "."
, textcolor = sesd_css
, size = size.tiny
, display = display.all - display.status_line
, editable = false)
plotshape(is_sesd != is_sesd[1] and show_ses_div and show_sesd, "SYD"
, shape.labelup
, location.bottom
, na
, text = "❚"
, textcolor = sesd_css
, size = size.tiny
, display = display.all - display.status_line
, editable = false)
//-----------------------------------------------------------------------------}
//Plots daily dividers
//-----------------------------------------------------------------------------{
day = dayofweek
if day != day[1] and show_day_div
line.new(n, close + syminfo.mintick, n, close - syminfo.mintick
, color = color.gray
, extend = extend.both
, style = line.style_dashed)
plotshape(day != day[1] and day == 1 and show_day_div, "Sunday"
, shape.labeldown
, location.top
, na
, text = "Sunday"
, textcolor = color.gray
, size = size.tiny
, display = display.all - display.status_line
, editable = false)
plotshape(day != day[1] and day == 2 and show_day_div, "Monday"
, shape.labeldown
, location.top
, na
, text = "Monday"
, textcolor = color.gray
, size = size.tiny
, display = display.all - display.status_line
, editable = false)
plotshape(day != day[1] and day == 3 and show_day_div, "Tuesday"
, shape.labeldown
, location.top
, na
, text = "Tuesday"
, textcolor = color.gray
, size = size.tiny
, display = display.all - display.status_line
, editable = false)
plotshape(day != day[1] and day == 4 and show_day_div, "Wednesay"
, shape.labeldown
, location.top
, na
, text = "Wednesday"
, textcolor = color.gray
, size = size.tiny
, display = display.all - display.status_line
, editable = false)
plotshape(day != day[1] and day == 5 and show_day_div, "Thursday"
, shape.labeldown
, location.top
, na
, text = "Thursday"
, textcolor = color.gray
, size = size.tiny
, display = display.all - display.status_line
, editable = false)
plotshape(day != day[1] and day == 6 and show_day_div, "Friday"
, shape.labeldown
, location.top
, na
, text = "Friday"
, textcolor = color.gray
, size = size.tiny
, display = display.all - display.status_line
, editable = false)
plotshape(day != day[1] and day == 7 and show_day_div, "Saturday"
, shape.labeldown
, location.top
, na
, text = "Saturday"
, textcolor = color.gray
, size = size.tiny
, display = display.all - display.status_line
, editable = false)
// ========== SESSIONS [LUXALGO] CODE END ==========
// ========== LIQUIDITY LINES & SWEEPS + FVG [LUCIEN] CODE BEGIN ==========
// === LIQUIDITY SETTINGS ===
liquidityBool = input.bool(true, 'Show Liquidity Sweeps', group = 'Liquidity Settings')
liquidity_len = input.int(30, 'Liquidity Length', minval = 5, group = 'Liquidity Settings')
upColor = input.color(color.new(color.teal, 15), title = 'Bullish Liquidity Color', group = 'Liquidity Settings')
downColor = input.color(color.new(color.red, 15), title = 'Bearish Liquidity Color', group = 'Liquidity Settings')
// === EMA SETTINGS ===
showEma = input.bool(true, title="Show EMA", group="Moving Average")
emaLength = input.int(50, title="EMA Length", minval=1, group="Moving Average")
emaSource = input.source(close, title="EMA Source", group="Moving Average")
emaTimeframe = input.timeframe("", title="EMA Timeframe (leave empty for current)", group="Moving Average")
emaColor = input.color(color.new(color.orange, 0), title="EMA Color", group="Moving Average")
emaWidth = input.int(2, title="EMA Line Width", minval=1, maxval=5, group="Moving Average")
// === EMA 2 SETTINGS ===
showEma2 = input.bool(true, title="Show EMA 2", group="Moving Average")
ema2Length = input.int(100, title="EMA 2 Length", minval=1, group="Moving Average")
ema2Source = input.source(close, title="EMA 2 Source", group="Moving Average")
ema2Timeframe = input.timeframe("", title="EMA 2 Timeframe (leave empty for current)", group="Moving Average")
ema2Color = input.color(color.new(color.blue, 0), title="EMA 2 Color", group="Moving Average")
ema2Width = input.int(2, title="EMA 2 Line Width", minval=1, maxval=5, group="Moving Average")
// === EMA 3 SETTINGS ===
showEma3 = input.bool(true, title="Show EMA 3", group="Moving Average")
ema3Length = input.int(200, title="EMA 3 Length", minval=1, group="Moving Average")
ema3Source = input.source(close, title="EMA 3 Source", group="Moving Average")
ema3Timeframe = input.timeframe("", title="EMA 3 Timeframe (leave empty for current)", group="Moving Average")
ema3Color = input.color(color.new(color.purple, 0), title="EMA 3 Color", group="Moving Average")
ema3Width = input.int(2, title="EMA 3 Line Width", minval=1, maxval=5, group="Moving Average")
// Calculate EMA 1 with timeframe option
emaValue = request.security(syminfo.tickerid, emaTimeframe != "" ? emaTimeframe : timeframe.period, ta.ema(emaSource, emaLength))
plot(showEma ? emaValue : na, title="EMA", color=emaColor, linewidth=emaWidth)
// Calculate EMA 2 with timeframe option
emaValue2 = request.security(syminfo.tickerid, ema2Timeframe != "" ? ema2Timeframe : timeframe.period, ta.ema(ema2Source, ema2Length))
plot(showEma2 ? emaValue2 : na, title="EMA 2", color=ema2Color, linewidth=ema2Width)
// Calculate EMA 3 with timeframe option
emaValue3 = request.security(syminfo.tickerid, ema3Timeframe != "" ? ema3Timeframe : timeframe.period, ta.ema(ema3Source, ema3Length))
plot(showEma3 ? emaValue3 : na, title="EMA 3", color=ema3Color, linewidth=ema3Width)
// --- True range for label positioning ---
tr = ta.tr(true)
// --- Bias Detection and Label ---
var label biasLabel = na
bullishBias = (emaValue > emaValue2) and (emaValue2 > emaValue3)
bearishBias = (emaValue < emaValue2) and (emaValue2 < emaValue3)
if not na(biasLabel)
label.delete(biasLabel)
if bullishBias
biasLabel := label.new(bar_index, low - tr*5, "Only Buy", xloc=xloc.bar_index, yloc=yloc.price, style=label.style_label_up, color=color.new(color.teal, 0), textcolor=color.white, size=size.large)
else if bearishBias
biasLabel := label.new(bar_index, high + tr*5, "Only Sell", xloc=xloc.bar_index, yloc=yloc.price, style=label.style_label_down, color=color.new(color.red, 0), textcolor=color.white, size=size.large)
// === FVG SETTINGS ===
isFvgToShow = input(true, title='Display FVG', group="Fair Value Gap")
bullishFvgColor = input.color(color.new(color.green, 50), 'Bullish FVG Color', group="Fair Value Gap")
bearishFvgColor = input.color(color.new(color.red, 50), 'Bearish FVG Color', group="Fair Value Gap")
mitigatedFvgColor = input.color(color.new(color.gray, 50), 'Mitigated FVG Color', group="Fair Value Gap")
fvgHistoryNbr = input.int(5, 'Number of FVG to show', minval=1, maxval=50, group="Fair Value Gap")
isMitigatedFvgToReduce = input(false, title='Reduce mitigated FVG', group="Fair Value Gap")
// === DATA STRUCTURES ===
// For Liquidity
type liquidity
float value
int barStart
int barEnd
line liquidityLine
bool broken
label sweep
var array<liquidity> bullishLiquidity = array.new<liquidity>()
var array<liquidity> bearishLiquidity = array.new<liquidity>()
// For FVG
var array<box> fvgBoxes = array.new_box(0)
var array<bool> fvgTypes = array.new_bool(0)
var array<label> fvgLabels = array.new_label(0)
var array<bool> isFvgMitigated = array.new_bool(0)
// === FVG FUNCTIONS ===
FVGDraw(_boxes, _fvgTypes, _isFvgMitigated, _fvgLabels) =>
for [index, value] in _boxes
// Processing bullish FVG
if array.get(_fvgTypes, index)
if low <= box.get_bottom(value)
array.remove(_boxes, index)
array.remove(_fvgTypes, index)
array.remove(_isFvgMitigated, index)
label.delete(array.get(_fvgLabels, index))
array.remove(_fvgLabels, index)
box.delete(value)
else
if low < box.get_top(value)
box.set_bgcolor(value, mitigatedFvgColor)
if not array.get(_isFvgMitigated, index)
alert("FVG has been mitigated", alert.freq_once_per_bar)
array.set(_isFvgMitigated, index, true)
if isMitigatedFvgToReduce
box.set_top(value, low)
box.set_right(value, bar_index)
label.set_x(array.get(_fvgLabels, index), (box.get_left(value) + box.get_right(value)) / 2 )
label.set_y(array.get(_fvgLabels, index), box.get_top(value) - (box.get_top(value) - box.get_bottom(value)) / 2)
// Processing bearish FVG
else
if high >= box.get_top(value)
array.remove(_boxes, index)
array.remove(_fvgTypes, index)
array.remove(_isFvgMitigated, index)
label.delete(array.get(_fvgLabels, index))
array.remove(_fvgLabels, index)
box.delete(value)
else
if high > box.get_bottom(value)
box.set_bgcolor(value, mitigatedFvgColor)
if not array.get(_isFvgMitigated, index)
alert("FVG has been mitigated", alert.freq_once_per_bar)
array.set(_isFvgMitigated, index, true)
if isMitigatedFvgToReduce
box.set_bottom(value, high)
box.set_right(value, bar_index)
label.set_x(array.get(_fvgLabels, index), (box.get_left(value) + box.get_right(value)) / 2 )
label.set_y(array.get(_fvgLabels, index), box.get_top(value) - (box.get_top(value) - box.get_bottom(value)) / 2)
// === LIQUIDITY DETECTION ===
phLiquidity = ta.pivothigh(high, liquidity_len, liquidity_len)
plLiquidity = ta.pivotlow(low, liquidity_len, liquidity_len)
if not na(phLiquidity) and liquidityBool
liquidity newLiquidity = liquidity.new()
newLiquidity.value := high[liquidity_len]
newLiquidity.barStart := time[liquidity_len]
newLiquidity.barEnd := time
newLiquidity.broken := false
newLiquidity.liquidityLine := line.new(x1 = newLiquidity.barStart, y1 = newLiquidity.value, x2 = newLiquidity.barEnd, y2 = newLiquidity.value, xloc = xloc.bar_time, color = downColor, width = 1)
array.push(bearishLiquidity, newLiquidity)
if array.size(bearishLiquidity) > 7
deletedLiquidity = array.shift(bearishLiquidity)
deletedLiquidity.liquidityLine.delete()
if not na(plLiquidity) and liquidityBool
liquidity newLiquidity = liquidity.new()
newLiquidity.value := low[liquidity_len]
newLiquidity.barStart := time[liquidity_len]
newLiquidity.barEnd := time
newLiquidity.broken := false
newLiquidity.liquidityLine := line.new(x1 = newLiquidity.barStart, y1 = newLiquidity.value, x2 = newLiquidity.barEnd, y2 = newLiquidity.value, xloc = xloc.bar_time, color = upColor, width = 1)
array.push(bullishLiquidity, newLiquidity)
if array.size(bullishLiquidity) > 7
deletedLiquidity = array.shift(bullishLiquidity)
deletedLiquidity.liquidityLine.delete()
// === FVG DETECTION ===
isBullishFVG = high[3] < low[1]
isBearishFVG = low[3] > high[1]
if isBullishFVG and isFvgToShow
box _box = box.new(left=bar_index - 2, top=low[1], right=bar_index - 1, bottom=high[3], border_style=line.style_solid, border_width=1, bgcolor=bullishFvgColor, border_color=color.new(color.green, 100))
label _label = label.new(math.ceil((_box.get_left() + _box.get_right()) / 2), _box.get_top() - (_box.get_top() - _box.get_bottom()) / 2, text = ".", style = label.style_none, textcolor = color.rgb(0, 0, 0))
array.push(fvgBoxes, _box)
array.push(fvgTypes, true)
array.push(isFvgMitigated, false)
array.push(fvgLabels, _label)
if array.size(fvgBoxes) > fvgHistoryNbr + 1
box.delete(array.get(fvgBoxes, 0))
label.delete(array.get(fvgLabels, 0))
array.remove(fvgLabels, 0)
array.remove(fvgBoxes, 0)
array.remove(fvgTypes, 0)
array.remove(isFvgMitigated, 0)
if isBearishFVG and isFvgToShow
box _box = box.new(left=bar_index - 2, top=low[3], right=bar_index - 1, bottom=high[1], border_style=line.style_solid, border_width=1, bgcolor=bearishFvgColor, border_color=color.new(color.red, 100))
label _label = label.new(math.ceil((_box.get_left() + _box.get_right()) / 2), _box.get_top() - (_box.get_top() - _box.get_bottom()) / 2, text = ".", style = label.style_none, textcolor = color.rgb(0, 0, 0))
array.push(fvgBoxes, _box)
array.push(fvgTypes, false)
array.push(isFvgMitigated, false)
array.push(fvgLabels, _label)
if array.size(fvgBoxes) > fvgHistoryNbr + 1
box.delete(array.get(fvgBoxes, 0))
label.delete(array.get(fvgLabels, 0))
array.remove(fvgLabels, 0)
array.remove(fvgBoxes, 0)
array.remove(fvgTypes, 0)
array.remove(isFvgMitigated, 0)
// === UPDATE VISUALS ===
// Update Liquidity Lines and Sweeps
var bool sweepAlert = false
if array.size(bearishLiquidity) > 0
liquidity testLiquidity = na
for i = array.size(bearishLiquidity) - 1 to 0 by 1
testLiquidity := array.get(bearishLiquidity, i)
if high > testLiquidity.value
testLiquidity.liquidityLine.set_x2(time)
testLiquidity.liquidityLine.set_style(line.style_dashed)
array.remove(bearishLiquidity, i)
if close < testLiquidity.value
testLiquidity.sweep := label.new(x = time, y = high, text = 'x', xloc = xloc.bar_time, style = label.style_label_down, size = size.normal, textcolor = color.new(color.purple, 0), color = color.new(color.white, 100))
sweepAlert := true
else
testLiquidity.liquidityLine.set_x2(time)
if array.size(bullishLiquidity) > 0
liquidity testLiquidity = na
for i = array.size(bullishLiquidity) - 1 to 0 by 1
testLiquidity := array.get(bullishLiquidity, i)
if low < testLiquidity.value
testLiquidity.liquidityLine.set_x2(time)
testLiquidity.liquidityLine.set_style(line.style_dashed)
array.remove(bullishLiquidity, i)
if close > testLiquidity.value
testLiquidity.sweep := label.new(x = time, y = low, text = 'x', xloc = xloc.bar_time, style = label.style_label_up, size = size.normal, textcolor = color.new(color.teal, 0), color = color.new(color.white, 100))
sweepAlert := true
else
testLiquidity.liquidityLine.set_x2(time)
// Update FVGs
FVGDraw(fvgBoxes, fvgTypes, isFvgMitigated, fvgLabels)
// === ALERTS ===
alertcondition(sweepAlert, title = "Liquidity Sweep", message = "A liquidity zone has been swept.")
sweepAlert := false
// === PREVIOUS DAY HIGH/LOW SETTINGS ===
showPrevDayRange = input.bool(true, 'Show Previous Day High/Low', group='Previous Day Range')
prevDayColorHigh = input.color(color.new(color.blue, 0), 'Previous Day High Color', group='Previous Day Range')
prevDayColorLow = input.color(color.new(color.orange, 0), 'Previous Day Low Color', group='Previous Day Range')
prevDayLineWidth = input.int(2, 'Previous Day Line Width', minval=1, maxval=5, group='Previous Day Range')
prevDayLineStyle = input.string('Dashed', 'Previous Day Line Style', options=['Dashed', 'Dotted'], group='Previous Day Range')
// Convert line style string to line.style constant
lineStyle = prevDayLineStyle == 'Dotted' ? line.style_dotted : line.style_dashed
// Get previous day timeframe string or use 'D'
dailyTF = "D" // fixed daily timeframe
// Request previous daily data (high/low) and previous day start timestamp (session start)
prevDayHigh = request.security(syminfo.tickerid, dailyTF, high[1], lookahead=barmerge.lookahead_on)
prevDayLow = request.security(syminfo.tickerid, dailyTF, low[1], lookahead=barmerge.lookahead_on)
prevDayTime = request.security(syminfo.tickerid, dailyTF, time[1], lookahead=barmerge.lookahead_on) // Timestamp of previous daily bar start
// Variables to hold lines just once (persistent)
var line prevHighLine = na
var line prevLowLine = na
// Calculate approximate timeframe minutes and future time offset
tf_minutes = timeframe.multiplier * (timeframe.isintraday ? 1 : 1440)
futureBarsCount = 500
futureDeltaMs = tf_minutes * 60000 * futureBarsCount
lineEndTime = time + futureDeltaMs
if showPrevDayRange
if na(prevHighLine)
prevHighLine := line.new(x1=prevDayTime, y1=prevDayHigh, x2=lineEndTime, y2=prevDayHigh, xloc=xloc.bar_time, color=prevDayColorHigh, width=prevDayLineWidth, style=lineStyle)
else
line.set_xy1(prevHighLine, prevDayTime, prevDayHigh)
line.set_xy2(prevHighLine, lineEndTime, prevDayHigh)
if na(prevLowLine)
prevLowLine := line.new(x1=prevDayTime, y1=prevDayLow, x2=lineEndTime, y2=prevDayLow, xloc=xloc.bar_time, color=prevDayColorLow, width=prevDayLineWidth, style=lineStyle)
else
line.set_xy1(prevLowLine, prevDayTime, prevDayLow)
line.set_xy2(prevLowLine, lineEndTime, prevDayLow)
else
if not na(prevHighLine)
line.delete(prevHighLine)
prevHighLine := na
if not na(prevLowLine)
line.delete(prevLowLine)
prevLowLine := na
// ========== LIQUIDITY LINES & SWEEPS + FVG [LUCIEN] CODE END ==========
How to use:
Copy entire code above and paste it into Pine Editor on TradingView.
Save and add to chart.
You will have both the Sessions indicator AND the Liquidity Lines + FVG + EMA + Previous Day Range functionalities all in one script.
Inputs are grouped separately for easy configuration.
Make sure your chart's resource limits allow enough lines and boxes — you can reduce max_lines_count etc. if necessary.
If you want me to do any custom tweaks or fix conflicts — just ask!