0% found this document useful (0 votes)
116 views22 pages

Saty, Double T - B, 123 Pattern, Profile

This indicator has technically advanced trend lines. Codes were created by artificial intelligence.

Uploaded by

moleno56
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)
116 views22 pages

Saty, Double T - B, 123 Pattern, Profile

This indicator has technically advanced trend lines. Codes were created by artificial intelligence.

Uploaded by

moleno56
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/ 22

// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.

0
at https://mozilla.org/MPL/2.0/
// © Riptide88

// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0
at https://mozilla.org/MPL/2.0/
// © NewLifeRipon

// Saty ATR Levels


// Copyright (C) 2022 Saty Mahajan
// Author is not responsible for your trading using this script.
// Data provided in this script is not financial advice.
//
// Features:
// - Day, Multiday, Swing, Position, Long-term, Keltner trading modes
// - Range against ATR for each period
// - Put and call trigger idea levels
// - Intermediate levels
// - Full-range levels
// - Extension levels
// - Trend label based on the 8-21-34 Pivot Ribbon
//
// Special thanks to Gabriel Viana.
// Based on my own ideas and ideas from Ripster, drippy2hard,
// Adam Sliver, and others.

//@version=5
indicator('Saty ATR Levels, Drawing max_bars_back', shorttitle='Saty ATR Levels',
overlay=true)
// max_bars_back(time, 5000)
var int pastBar = na
if barstate.islastconfirmedhistory
pastBar := bar_index - 2000
if barstate.islast
label.new(pastBar, 1, text = "Label text"),
// max_bars_back(time= 5000)

// Options
day_trading = 'Day'
multiday_trading = 'Multiday'
swing_trading = 'Swing'
position_trading = 'Position'
longterm_trading = 'Long-term'
trading_type = input.string(day_trading, 'Trading Type', options=[day_trading,
multiday_trading, swing_trading, position_trading, longterm_trading])
use_options_labels = input(true, 'Use Options Labels')
atr_length = input(14, 'ATR Length')
trigger_percentage = input(0.236, 'Trigger Percentage')
previous_close_level_color = input(color.white, 'Previous Close Level Color')
lower_trigger_level_color = input(color.yellow, 'Lower Trigger Level Color')
upper_trigger_level_color = input(color.aqua, 'Upper Trigger Level Color')
key_target_level_color = input(color.silver, 'Key Target Level Color')
atr_target_level_color = input(color.white, 'ATR Target Level Color')
intermediate_target_level_color = input(color.gray, 'Intermediate Target Level
Color')
show_all_fibonacci_levels = input(true, 'Show All Fibonacci Levels')
show_extensions = input(false, 'Show Extensions')
level_size = input(2, 'Level Size')
show_info = input(true, 'Show Info Label')
use_current_close = input(false, 'Use Current Close')
fast_ema = input(8, 'Fast EMA')
pivot_ema = input(21, 'Pivot EMA')
slow_ema = input(34, 'Slow EMA')

// Set the appropriate timeframe based on trading mode


timeframe_func() =>
timeframe = 'D'
if trading_type == day_trading
timeframe := 'D'
else if trading_type == multiday_trading
timeframe := 'W'
else if trading_type == swing_trading
timeframe := 'M'
else if trading_type == position_trading
timeframe := '3M'
else if trading_type == longterm_trading
timeframe := '12M'
else
timeframe := 'D'

// Trend
price = close
fast_ema_value = ta.ema(price, fast_ema)
pivot_ema_value = ta.ema(price, pivot_ema)
slow_ema_value = ta.ema(price, slow_ema)
bullish = price >= fast_ema_value and fast_ema_value >= pivot_ema_value and
pivot_ema_value >= slow_ema_value
bearish = price <= fast_ema_value and fast_ema_value <= pivot_ema_value and
pivot_ema_value <= slow_ema_value

// Data
period_index = use_current_close ? 0 : 1
ticker = ticker.new(syminfo.prefix, syminfo.ticker, session=session.extended)
previous_close = request.security(ticker, timeframe_func(), close[period_index],
gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on)
atr = request.security(ticker, timeframe_func(), ta.atr(atr_length)[period_index],
gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on)
period_high = request.security(ticker, timeframe_func(), high,
gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on)
period_low = request.security(ticker, timeframe_func(), low,
gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on)
range_1 = period_high - period_low
tr_percent_of_atr = range_1 / atr * 100
lower_trigger = previous_close - trigger_percentage * atr
upper_trigger = previous_close + trigger_percentage * atr
lower_0382 = previous_close - atr * 0.382
upper_0382 = previous_close + atr * 0.382
lower_0500 = previous_close - atr * 0.5
upper_0500 = previous_close + atr * 0.5
lower_0618 = previous_close - atr * 0.618
upper_0618 = previous_close + atr * 0.618
lower_0786 = previous_close - atr * 0.786
upper_0786 = previous_close + atr * 0.786
lower_1000 = previous_close - atr
upper_1000 = previous_close + atr
lower_1236 = lower_1000 - atr * 0.236
upper_1236 = upper_1000 + atr * 0.236
lower_1382 = lower_1000 - atr * 0.382
upper_1382 = upper_1000 + atr * 0.382
lower_1500 = lower_1000 - atr * 0.5
upper_1500 = upper_1000 + atr * 0.5
lower_1618 = lower_1000 - atr * 0.618
upper_1618 = upper_1000 + atr * 0.618
lower_1786 = lower_1000 - atr * 0.786
upper_1786 = upper_1000 + atr * 0.786
lower_2000 = lower_1000 - atr
upper_2000 = upper_1000 + atr
lower_2236 = lower_2000 - atr * 0.236
upper_2236 = upper_2000 + atr * 0.236
lower_2382 = lower_2000 - atr * 0.382
upper_2382 = upper_2000 + atr * 0.382
lower_2500 = lower_2000 - atr * 0.5
upper_2500 = upper_2000 + atr * 0.5
lower_2618 = lower_2000 - atr * 0.618
upper_2618 = upper_2000 + atr * 0.618
lower_2786 = lower_2000 - atr * 0.786
upper_2786 = upper_2000 + atr * 0.786
lower_3000 = lower_2000 - atr
upper_3000 = upper_2000 + atr

// Add Labels
tr_vs_atr_color = color.green
if tr_percent_of_atr <= 70
tr_vs_atr_color := color.green
else if tr_percent_of_atr >= 90
tr_vs_atr_color := color.red
else
tr_vs_atr_color := color.orange

trading_mode = 'Day'
if trading_type == day_trading
trading_mode := 'Day'
else if trading_type == multiday_trading
trading_mode := 'Multiday'
else if trading_type == swing_trading
trading_mode := 'Swing'
else if trading_type == position_trading
trading_mode := 'Position'
else if trading_type == longterm_trading
trading_mode := 'Long-term'
else
trading_mode := ''

long_label = ''
short_label = ''
if use_options_labels
long_label := 'Calls'
short_label := 'Puts'
else
long_label := 'Long'
short_label := 'Short'

trend_color = color.orange
if bullish
trend_color := color.green
else if bearish
trend_color := color.red
else
trend_color := color.orange

var tbl = table.new(position.top_right, 1, 4)


if barstate.islast and show_info
table.cell(tbl, 0, 0, 'Saty ATR Levels', bgcolor=trend_color)
table.cell(tbl, 0, 1, trading_mode + ' Range ($' + str.tostring(range_1,
'#.##') + ') is ' + str.tostring(tr_percent_of_atr, '#.#') + '% of ATR ($' +
str.tostring(atr, '#.##') + ')', bgcolor=tr_vs_atr_color)
table.cell(tbl, 0, 2, long_label + ' > $' + str.tostring(upper_trigger, '#.##')
+ ' | +1 ATR $' + str.tostring(upper_1000, '#.##'),
bgcolor=upper_trigger_level_color)
table.cell(tbl, 0, 3, short_label + ' < $' + str.tostring(lower_trigger,
'#.##') + ' | -1 ATR $' + str.tostring(lower_1000, '#.##'),
bgcolor=lower_trigger_level_color)

// Add levels
plot(show_extensions ? lower_3000 : na, color=color.new(atr_target_level_color,
40), linewidth=level_size, title='-300.0%', style=plot.style_stepline)
//plot(show_all_fibonacci_levels and show_extensions ? lower_2786 : na,
color=color.new(intermediate_target_level_color, 40), linewidth=level_size,
title='-278.6%', style=plot.style_stepline)
plot(show_extensions ? lower_2618 : na, color=color.new(key_target_level_color,
40), linewidth=level_size, title='-261.8%', style=plot.style_stepline)
//plot(show_all_fibonacci_levels and show_extensions ? lower_2500 : na,
color=color.new(intermediate_target_level_color, 40), linewidth=level_size,
title='-250.0%', style=plot.style_stepline)
//plot(show_all_fibonacci_levels and show_extensions ? lower_2382 : na,
color=color.new(intermediate_target_level_color, 40), linewidth=level_size,
title='-238.2%', style=plot.style_stepline)
plot(show_extensions ? lower_2236 : na, color=color.new(key_target_level_color,
40), linewidth=level_size, title='-223.6%', style=plot.style_stepline)
plot(show_extensions ? lower_2000 : na, color=color.new(atr_target_level_color,
40), linewidth=level_size, title='-200.0%', style=plot.style_stepline)
plot(show_all_fibonacci_levels and show_extensions ? lower_1786 : na,
color=color.new(intermediate_target_level_color, 40), linewidth=level_size,
title='-178.6%', style=plot.style_stepline)
plot(show_extensions ? lower_1618 : na, color=color.new(key_target_level_color,
40), linewidth=level_size, title='-161.8%', style=plot.style_stepline)
plot(show_all_fibonacci_levels and show_extensions ? lower_1500 : na,
color=color.new(intermediate_target_level_color, 40), linewidth=level_size,
title='-150.0%', style=plot.style_stepline)
plot(show_all_fibonacci_levels and show_extensions ? lower_1382 : na,
color=color.new(intermediate_target_level_color, 40), linewidth=level_size,
title='-138.2%', style=plot.style_stepline)
plot(show_extensions ? lower_1236 : na, color=color.new(key_target_level_color,
40), linewidth=level_size, title='-123.6%', style=plot.style_stepline)
plot(lower_1000, color=color.new(atr_target_level_color, 40), linewidth=level_size,
title='-100%', style=plot.style_stepline)
plot(show_all_fibonacci_levels ? lower_0786 : na,
color=color.new(intermediate_target_level_color, 40), linewidth=level_size,
title='-78.6%', style=plot.style_stepline)
plot(lower_0618, color=color.new(key_target_level_color, 40), linewidth=level_size,
title='-61.8%', style=plot.style_stepline)
plot(show_all_fibonacci_levels ? lower_0500 : na,
color=color.new(intermediate_target_level_color, 40), linewidth=level_size,
title='-50.0%', style=plot.style_stepline)
plot(show_all_fibonacci_levels ? lower_0382 : na,
color=color.new(intermediate_target_level_color, 40), linewidth=level_size,
title='-38.2%', style=plot.style_stepline)
plot(lower_trigger, color=color.new(lower_trigger_level_color, 40),
linewidth=level_size, title='Lower Trigger', style=plot.style_circles)
plot(previous_close, color=color.new(previous_close_level_color, 40),
linewidth=level_size, title='Previous Close', style=plot.style_circles)
plot(upper_trigger, color=color.new(upper_trigger_level_color, 40),
linewidth=level_size, title='Upper Trigger', style=plot.style_circles)
plot(show_all_fibonacci_levels ? upper_0382 : na,
color=color.new(intermediate_target_level_color, 40), linewidth=level_size,
title='38.2%', style=plot.style_stepline)
plot(show_all_fibonacci_levels ? upper_0500 : na,
color=color.new(intermediate_target_level_color, 40), linewidth=level_size,
title='50.0%', style=plot.style_stepline)
plot(upper_0618, color=color.new(key_target_level_color, 40), linewidth=level_size,
title='61.8%', style=plot.style_stepline)
plot(show_all_fibonacci_levels ? upper_0786 : na,
color=color.new(intermediate_target_level_color, 40), linewidth=level_size,
title='78.6%', style=plot.style_stepline)
plot(upper_1000, color=color.new(atr_target_level_color, 40), linewidth=level_size,
title='100%', style=plot.style_stepline)
plot(show_extensions ? upper_1236 : na, color=color.new(key_target_level_color,
40), linewidth=level_size, title='123.6%', style=plot.style_stepline)
plot(show_all_fibonacci_levels and show_extensions ? upper_1382 : na,
color=color.new(intermediate_target_level_color, 40), linewidth=level_size,
title='138.2%', style=plot.style_stepline)
plot(show_all_fibonacci_levels and show_extensions ? upper_1500 : na,
color=color.new(intermediate_target_level_color, 40), linewidth=level_size,
title='150.0%', style=plot.style_stepline)
plot(show_extensions ? upper_1618 : na, color=color.new(key_target_level_color,
40), linewidth=level_size, title='161.8%', style=plot.style_stepline)
plot(show_all_fibonacci_levels and show_extensions ? upper_1786 : na,
color=color.new(intermediate_target_level_color, 40), linewidth=level_size,
title='178.6%', style=plot.style_stepline)
plot(show_extensions ? upper_2000 : na, color=color.new(atr_target_level_color,
40), linewidth=level_size, title='200.0%', style=plot.style_stepline)
plot(show_extensions ? upper_2236 : na, color=color.new(key_target_level_color,
40), linewidth=level_size, title='223.6%', style=plot.style_stepline)
//plot(show_all_fibonacci_levels and show_extensions ? upper_2382 : na,
color=color.new(intermediate_target_level_color, 40), linewidth=level_size,
title='238.2%', style=plot.style_stepline)
//plot(show_all_fibonacci_levels and show_extensions ? upper_2500 : na,
color=color.new(intermediate_target_level_color, 40), linewidth=level_size,
title='250.0%', style=plot.style_stepline)
plot(show_extensions ? upper_2618 : na, color=color.new(key_target_level_color,
40), linewidth=level_size, title='261.8%', style=plot.style_stepline)
//plot(show_all_fibonacci_levels and show_extensions ? upper_2786 : na,
color=color.new(intermediate_target_level_color, 40), linewidth=level_size,
title='278.6%', style=plot.style_stepline)
plot(show_extensions ? upper_3000 : na, color=color.new(atr_target_level_color,
40), linewidth=level_size, title='300%', style=plot.style_stepline)

// 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/
// © Zeiierman

//@version=5

// ~~ ToolTips {
t1 = "Pivot period"
t2 = "Show pattern break, set the size, and coloring"
t3 = "Show the 1-2-3 Pattern"
t4 = "Enable the HH/HL/LL/LH labels"
// ~~}
// ~~ Inputs {
prd = input.int(10,title="Period",tooltip=t1)

showBreak = input.bool(true,"Show Break", inline="break")


showPattern = input.bool(true,"Show Pattern",tooltip=t3)
showPvts = input.bool(false,"Show Pivots",tooltip=t4)

visuell =
input.string("Diamond","",options=["Diamond","XCross","Cross","Flag","Square"],inli
ne="break")
colBull = input.color(#34fa03,"",inline="break")
colBear = input.color(#fc0303,"",inline="break")
size =
input.string(size.tiny,"",options=[size.tiny,size.small,size.normal,size.large,size
.huge],inline="break",tooltip=t2)

shape = switch visuell


"Diamond" => label.style_diamond
"XCross" => label.style_xcross
"Cross" => label.style_cross
"Flag" => label.style_flag
"Square" => label.style_square
// ~~ }
// ~~ Arrays {
var pvts = array.new<float>(3,0.0)
var idx = array.new<int>(3,0)
// ~~ }
// ~~ Pivots {
pvtHi = ta.pivothigh(high,prd,prd)
pvtLo = ta.pivotlow(low,prd,prd)
var pos = 0

if not na(pvtHi) and pos<=0


if showPvts
label.new(bar_index-
prd,high[prd],text=pvtHi>array.get(pvts,1)?"HH":"LH",style=label.style_label_down,c
olor=color(na),textcolor=chart.fg_color)
array.pop(pvts)
array.pop(idx)
array.unshift(pvts,high[prd])
array.unshift(idx,bar_index-prd)
pos := 1
if not na(pvtLo) and pos>=0
if showPvts
label.new(bar_index-
prd,low[prd],text=pvtLo>array.get(pvts,1)?"HL":"LL",style=label.style_label_up,colo
r=color(na),textcolor=chart.fg_color)
array.pop(pvts)
array.pop(idx)
array.unshift(pvts,low[prd])
array.unshift(idx,bar_index-prd)
pos := -1
// ~~ }
// ~~ Identify 1-2-3 Pattern & Alerts {
var pattern = true
if ta.crossover(high,array.get(pvts,1)) and pattern
if array.get(pvts,0)>array.get(pvts,2) and array.get(pvts,0)<array.get(pvts,1)
if showBreak
label.new(bar_index,high,style=shape,color=colBull,size=size)

line.new(array.get(idx,1),array.get(pvts,1),bar_index,array.get(pvts,1),color=chart
.fg_color,style=line.style_dashed)
if showPattern

label.new(array.get(idx,2),array.get(pvts,2),text="1",color=color(na),textcolor=cha
rt.fg_color,style=label.style_label_up)

label.new(array.get(idx,1),array.get(pvts,1),text="2",color=color(na),textcolor=cha
rt.fg_color,style=label.style_label_down)

label.new(array.get(idx,0),array.get(pvts,0),text="3",color=color(na),textcolor=cha
rt.fg_color,style=label.style_label_up)

line.new(array.get(idx,2),array.get(pvts,2),array.get(idx,1),array.get(pvts,1),colo
r=color.rgb(78, 254, 3, 2))

line.new(array.get(idx,1),array.get(pvts,1),array.get(idx,0),array.get(pvts,0),colo
r=color.rgb(78, 255, 3, 2))
alert("Bullish 1-2-3 Pattern Identified on:
"+syminfo.ticker,alert.freq_once_per_bar_close)
pattern := false
if ta.crossunder(low,array.get(pvts,1)) and pattern
if array.get(pvts,0)<array.get(pvts,2) and array.get(pvts,0)>array.get(pvts,1)
if showBreak
label.new(bar_index,low,style=shape,color=colBear,size=size)

line.new(array.get(idx,1),array.get(pvts,1),bar_index,array.get(pvts,1),color=chart
.fg_color,style=line.style_dashed)
if showPattern

label.new(array.get(idx,2),array.get(pvts,2),text="1",color=color(na),textcolor=cha
rt.fg_color,style=label.style_label_down)

label.new(array.get(idx,1),array.get(pvts,1),text="2",color=color(na),textcolor=cha
rt.fg_color,style=label.style_label_up)

label.new(array.get(idx,0),array.get(pvts,0),text="3",color=color(na),textcolor=cha
rt.fg_color,style=label.style_label_down)

line.new(array.get(idx,2),array.get(pvts,2),array.get(idx,1),array.get(pvts,1),
color=#fa0303fa)

line.new(array.get(idx,1),array.get(pvts,1),array.get(idx,0),array.get(pvts,0),colo
r=#fa0303fa)
alert("Bearish 1-2-3 Pattern Identified on:
"+syminfo.ticker,alert.freq_once_per_bar_close)
pattern := false
// ~~ }
// ~~ Debugger only check break once {
if ta.change(array.get(pvts,1))
pattern := true
// ~~ }
// This source code is subject to the terms of the Mozilla Public License 2.0 at
https://mozilla.org/MPL/2.0/
// © HSAF

//@version=5

//==========================
//Inputs
//==========================
sessionType = input.string('Daily', 'Session Type', options=['Tokyo','London','New
York','Daily','Weekly', 'Monthly'])

showProf = input.bool(true, 'Show Volume Profile', group='Display')


showPoc = input.bool(true, 'Show POC', group='Display')
showVA = input.bool(true, 'Show Value Area', group='Display')
showCur = input.bool(true, 'Show Live Zone', group='Display')
resolution = input.int(30, 'Resolution', minval=5, tooltip='The higher the value,
the more refined of a profile, but less profiles shown on chart', group='Volume
Profile Settings')
smoothVol = input.bool(false, 'Smooth Volume Data', tooltip='Useful for assets that
have very large spikes in volume over large bars, helps create better profiles',
group='Volume Profile Settings')
dataTf = ''

bullCol = input.color(color.rgb(76, 175, 79, 50), 'Up Volume', group='Appearance')


bearCol = input.color(color.rgb(255, 82, 82, 50), 'Down Volume',
group='Appearance')
pocCol = input.color(color.red, 'POC', inline='p', group='Appearance')
pocWid = input.int(1, 'Thickness', inline='p', group='Appearance')
vahCol = input.color(color.aqua, 'VAH', inline='h', group='Appearance')
vahWid = input.int(1, 'Thickness', inline='h', group='Appearance')
valCol = input.color(color.aqua, 'VAL', inline='l', group='Appearance')
valWid = input.int(1, 'Thickness', inline='l', group='Appearance')
boxWid = input.int(1, 'Session Box Thickness', group='Appearance')

//==========================
//Constants / Variable Declaration
//==========================
var int zoneStart = 0
int lookback = bar_index - zoneStart
var activeZone = false

// Defining arrays that store the information


var vpGreen = array.new_float(resolution, 0) // Sum of volume on long bars
var vpRed = array.new_float(resolution, 0) // Same thing but with red bars
var zoneBounds = array.new_float(resolution, 0) // array that stores the highest
value that can be in a zone

//Values to store current intra bar data


var float[] ltfOpen = array.new_float(0)
var float[] ltfClose = array.new_float(0)
var float[] ltfHigh = array.new_float(0)
var float[] ltfLow = array.new_float(0)
var float[] ltfVolume = array.new_float(0)

vol() =>
smoothVol ? ta.ema(volume, 5) : volume
//Getting intrabar intial data
[dO, dC, dH, dL, dV] = request.security_lower_tf(syminfo.tickerid, dataTf, [open,
close, high, low, vol()])

//==========================
//Functions
//==========================
resetProfile(enable) =>
if enable
array.fill(vpGreen, 0)
array.fill(vpRed, 0)
array.clear(ltfOpen)
array.clear(ltfHigh)
array.clear(ltfLow)
array.clear(ltfClose)
array.clear(ltfVolume)

profHigh = ta.highest(high, lookback+1)[1]


profLow = ta.lowest(low, lookback+1)[1]

tr = ta.atr(1)

get_vol(y11, y12, y21, y22, height, vol) =>


nz(math.max(math.min(math.max(y11, y12), math.max(y21, y22)) -
math.max(math.min(y11, y12), math.min(y21, y22)), 0) * vol / height)

profileAdd(o, h, l, c, v, g, w) =>
//Array to store how much to distribute in each zone, on scale of 1 for full
gap size to 0
zoneDist = array.new_float(resolution, 0)
distSum = 0.0
// Going over each zone
for i = 0 to array.size(vpGreen) - 1
// Checking to see if cur bar is in zone
zoneTop = array.get(zoneBounds, i)
zoneBot = zoneTop - g

body_top = math.max(c, o)
body_bot = math.min(c, o)
itsgreen = c >= o

topwick = h - body_top
bottomwick = body_bot - l
body = body_top - body_bot

bodyvol = body * v / (2 * topwick + 2 * bottomwick + body)


topwickvol = 2 * topwick * v / (2 * topwick + 2 * bottomwick + body)
bottomwickvol = 2 * bottomwick * v / (2 * topwick + 2 * bottomwick + body)

array.set(vpGreen, i, array.get(vpGreen, i) + (itsgreen ? get_vol(zoneBot,


zoneTop, body_bot, body_top, body, bodyvol) : 0) + get_vol(zoneBot, zoneTop,
body_top, h, topwick, topwickvol) / 2 + get_vol(zoneBot, zoneTop, body_bot, l,
bottomwick, bottomwickvol) / 2)
array.set(vpRed, i, array.get(vpRed, i) + (itsgreen ? 0 : get_vol(zoneBot,
zoneTop, body_bot, body_top, body, bodyvol)) + get_vol(zoneBot, zoneTop, body_top,
h, topwick, topwickvol) / 2 + get_vol(zoneBot, zoneTop, body_bot, l, bottomwick,
bottomwickvol) / 2)

calcSession(update) =>
array.fill(vpGreen, 0)
array.fill(vpRed, 0)
if bar_index > lookback and update
gap = (profHigh - profLow) / resolution

// Defining profile bounds


for i = 0 to resolution - 1
array.set(zoneBounds, i, profHigh - gap * i)

// Putting each bar inside zone into the volume profile array
if array.size(ltfOpen) > 0
for j = 0 to array.size(ltfOpen) - 1
profileAdd(array.get(ltfOpen, j), array.get(ltfHigh, j),
array.get(ltfLow, j), array.get(ltfClose, j), array.get(ltfVolume, j), gap, 1)

pocLevel() =>
float maxVol = 0
int levelInd = 0
for i = 0 to array.size(vpRed) - 1
if array.get(vpRed, i) + array.get(vpGreen, i) > maxVol
maxVol := array.get(vpRed, i) + array.get(vpGreen, i)
levelInd := i

float outLevel = na
if levelInd != array.size(vpRed) - 1
outLevel := array.get(zoneBounds, levelInd) - (array.get(zoneBounds,
levelInd) - array.get(zoneBounds, levelInd+1)) / 2
outLevel

valueLevels(poc) =>
float gap = (profHigh - profLow) / resolution
float volSum = array.sum(vpRed) + array.sum(vpGreen)
float volCnt = 0

float vah = profHigh


float val = profLow

//Finding poc index


int pocInd = 0
for i = 0 to array.size(zoneBounds)-2
if array.get(zoneBounds, i) >= poc and array.get(zoneBounds, i + 1) < poc
pocInd := i

volCnt += (array.get(vpRed, pocInd) + array.get(vpGreen, pocInd))


for i = 1 to array.size(vpRed)
if pocInd + i >= 0 and pocInd + i < array.size(vpRed)
volCnt += (array.get(vpRed, pocInd + i) + array.get(vpGreen, pocInd +
i))
if volCnt >= volSum * 0.7
break
else
val := array.get(zoneBounds, pocInd + i) - gap
if pocInd - i >= 0 and pocInd - i < array.size(vpRed)
volCnt += (array.get(vpRed, pocInd - i) + array.get(vpGreen, pocInd -
i))
if volCnt >= volSum * 0.7
break
else
vah := array.get(zoneBounds, pocInd - i)
[val, vah]

drawNewZone(update) =>
if bar_index > lookback and update and array.sum(vpGreen) + array.sum(vpRed) >
0
gap = (profHigh - profLow) / resolution
float leftMax = bar_index[lookback]
float rightMax = bar_index[int(lookback / 1.4)]
float rightMaxVol = array.max(vpGreen)+array.max(vpRed)
float buffer = gap / 10
if showProf
for i = 0 to array.size(vpRed) - 1
greenEnd = int(leftMax + (rightMax - leftMax) * (array.get(vpGreen,
i) / rightMaxVol))
redEnd = int(greenEnd + (rightMax - leftMax) * (array.get(vpRed, i)
/ rightMaxVol))
box.new(int(leftMax), array.get(zoneBounds, i) - buffer, greenEnd,
array.get(zoneBounds, i) - gap + buffer, bgcolor=bullCol, border_width=0)
box.new(greenEnd, array.get(zoneBounds, i) - buffer, redEnd,
array.get(zoneBounds, i) - gap + buffer, bgcolor=bearCol, border_width=0)
box.new(int(leftMax), profHigh, bar_index-1, profLow, chart.fg_color,
boxWid, line.style_dashed, bgcolor=color.rgb(0,0,0,100))
poc = pocLevel()
[val, vah] = valueLevels(poc)
if showPoc
line.new(int(leftMax), poc, bar_index-1, poc, color=pocCol,
width=pocWid)
if showVA
line.new(int(leftMax), vah, bar_index-1, vah, color=vahCol,
width=vahWid)
line.new(int(leftMax), val, bar_index-1, val, color=valCol,
width=valWid)

//if update
// resetProfile(true)

drawCurZone(update) =>
var line pocLine = na
var line vahLine = na
var line valLine = na
var box outBox = na

var redBoxes = array.new_box(array.size(vpRed), na)


var greenBoxes = array.new_box(array.size(vpRed), na)

if bar_index > lookback and update and array.sum(vpGreen) + array.sum(vpRed) >


0
//Clearing the previous boxes and array
if not na(pocLine)
line.delete(pocLine)
if not na(vahLine)
line.delete(vahLine)
if not na(valLine)
line.delete(valLine)
if not na(outBox)
box.delete(outBox)
for i = 0 to array.size(redBoxes) - 1
if not na(array.get(redBoxes, i))
box.delete(array.get(redBoxes, i))
box.delete(array.get(greenBoxes, i))

gap = (profHigh - profLow) / resolution


float leftMax = bar_index[lookback]
float rightMax = bar_index[int(lookback / 1.4)]
float rightMaxVol = array.max(vpGreen)+array.max(vpRed)
float buffer = gap / 10
if showProf
for i = 0 to array.size(vpRed) - 1
greenEnd = int(leftMax + (rightMax - leftMax) * (array.get(vpGreen,
i) / rightMaxVol))
redEnd = int(greenEnd + (rightMax - leftMax) * (array.get(vpRed, i)
/ rightMaxVol))
array.set(greenBoxes, i, box.new(int(leftMax),
array.get(zoneBounds, i) - buffer, greenEnd, array.get(zoneBounds, i) - gap +
buffer, bgcolor=bullCol, border_width=0))
array.set(redBoxes, i, box.new(greenEnd, array.get(zoneBounds, i) -
buffer, redEnd, array.get(zoneBounds, i) - gap + buffer, bgcolor=bearCol,
border_width=0))
outBox := box.new(int(leftMax), profHigh, bar_index-1, profLow,
chart.fg_color, boxWid, line.style_dashed, bgcolor=color.rgb(0,0,0,100))

poc = pocLevel()
[val, vah] = valueLevels(poc)
if showPoc
line.new(int(leftMax), poc, bar_index-1, poc, color=pocCol,
width=pocWid)
if showVA
line.new(int(leftMax), vah, bar_index-1, vah, color=vahCol,
width=vahWid)
line.new(int(leftMax), val, bar_index-1, val, color=valCol,
width=valWid)

combArray(arr1, arr2) =>


out = array.copy(arr1)
if array.size(arr2) > 0
for i = 0 to array.size(arr2) - 1
array.push(out, array.get(arr2, i))
out

updateIntra(o, h, l, c, v) =>
if array.size(o) > 0
for i = 0 to array.size(o) - 1
array.push(ltfOpen, array.get(o, i))
array.push(ltfHigh,array.get(h, i))
array.push(ltfLow,array.get(l, i))
array.push(ltfClose,array.get(c, i))
array.push(ltfVolume,array.get(v, i))

//==========================
//Calculations
//==========================
//Detecting different start dates
newDaily = dayofweek != dayofweek[1]
newWeekly = (dayofweek != dayofweek[1] + 1) and (dayofweek != dayofweek[1])
newMonthly = (dayofmonth != dayofmonth[1] + 1) and (dayofmonth != dayofmonth[1])

utcHour = hour(time(timeframe.period, '0000-2400', 'GMT'), 'GMT')

newTokyo = utcHour != utcHour[1] + 1 and utcHour != utcHour[1]


endTokyo = utcHour >= 9 and utcHour[1] < 9

newLondon = utcHour >= 7 and utcHour[1] < 7


endLondon = utcHour >= 16 and utcHour[1] < 16

newNewYork = utcHour >= 13 and utcHour[1] < 13


endNewYork = utcHour >= 22 and utcHour[1] < 22

newSession = switch sessionType


'Tokyo' => newTokyo
'London' => newLondon
'New York' => newNewYork
'Daily' => newDaily
'Weekly' => newWeekly
'Monthly' => newMonthly

zoneEnd = switch sessionType


'Tokyo' => endTokyo
'London' => endLondon
'New York' => endNewYork
'Daily' => newDaily
'Weekly' => newWeekly
'Monthly' => newMonthly

//Re calculating and drawing zones


calcSession(zoneEnd or (barstate.islast and showCur))
drawNewZone(zoneEnd)
drawCurZone(barstate.islast and not zoneEnd and showCur and activeZone)

//Reseting profie at start of new zone


resetProfile(newSession)

//Updating data arrays


updateIntra(dO, dH, dL, dC, dV)

//Reseting zone start value


if zoneEnd
activeZone := false

if newSession
zoneStart := bar_index
activeZone := true

// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0
at https://mozilla.org/MPL/2.0/
// © NewLifeRipon

// This source code is subject to the terms of the Mozilla Public License 2.0 at
https://mozilla.org/MPL/2.0/
// © Nephew_Sam_

//@version=5
// --------------- INPUTS ---------------
var GRP1 = "•••••••••• INTRADAY TIMEFRAMES ••••••••••"
// 1
ltimeframe1Show = input.bool(true, title='', inline='1', group=GRP1)
ltimeframe1 = input.timeframe('15', title='', inline='1', group=GRP1)
lleftBars1 = input.int(defval=7, title='Left', minval=2, maxval=20, group=GRP1,
inline='1')
lrightBars1 = input.int(defval=7, title='Right', minval=2, maxval=20, group=GRP1,
inline='1', tooltip="Highest/lowest point in x right and left bars.")

// 2
ltimeframe2Show = input.bool(true, title='', inline='2', group=GRP1)
ltimeframe2 = input.timeframe('30', title='', inline='2', group=GRP1)
lleftBars2 = input.int(defval=7, title='Left', minval=2, maxval=20, group=GRP1,
inline='2')
lrightBars2 = input.int(defval=7, title='Right', minval=2, maxval=20, group=GRP1,
inline='2', tooltip="Highest/lowest point in x right and left bars.")

// 3
ltimeframe3Show = input.bool(true, title='', inline='3', group=GRP1)
ltimeframe3 = input.timeframe('60', title='', inline='3', group=GRP1)
lleftBars3 = input.int(defval=7, title='Left', minval=2, maxval=20, group=GRP1,
inline='3')
lrightBars3 = input.int(defval=6, title='Right', minval=2, maxval=20, group=GRP1,
inline='3', tooltip="Highest/lowest point in x right and left bars.")

// 4
ltimeframe4Show = input.bool(true, title='', inline='4', group=GRP1)
ltimeframe4 = input.timeframe('120', title='', inline='4', group=GRP1)
lleftBars4 = input.int(defval=7, title='Left', minval=2, maxval=20, group=GRP1,
inline='4')
lrightBars4 = input.int(defval=6, title='Right', minval=2, maxval=20, group=GRP1,
inline='4', tooltip="Highest/lowest point in x right and left bars.")

// 5
ltimeframe5Show = input.bool(true, title='', inline='5', group=GRP1)
ltimeframe5 = input.timeframe('240', title='', inline='5', group=GRP1)
lleftBars5 = input.int(defval=6, title='Left', minval=2, maxval=20, group=GRP1,
inline='5')
lrightBars5 = input.int(defval=6, title='Right', minval=2, maxval=20, group=GRP1,
inline='5', tooltip="Highest/lowest point in x right and left bars.")

// 6
ltimeframe6Show = input.bool(true, title='', inline='6', group=GRP1)
ltimeframe6 = input.timeframe('D', title='', inline='6', group=GRP1)
lleftBars6 = input.int(defval=5, title='Left', minval=2, maxval=20, group=GRP1,
inline='6')
lrightBars6 = input.int(defval=5, title='Right', minval=2, maxval=20, group=GRP1,
inline='6', tooltip="Highest/lowest point in x right and left bars.")

var GRP2 = "•••••••••• HIGHER TIMEFRAMES (> 4HR) ••••••••••"


// 1
htimeframe1Show = input.bool(true, title='', inline='1', group=GRP2)
htimeframe1 = input.timeframe('480', title='', inline='1', group=GRP2)
hleftBars1 = input.int(defval=7, title='Left', minval=2, maxval=20, group=GRP2,
inline='1')
hrightBars1 = input.int(defval=7, title='Right', minval=2, maxval=20, group=GRP2,
inline='1', tooltip="Highest/lowest point in x right and left bars.")

// 2
htimeframe2Show = input.bool(true, title='', inline='2', group=GRP2)
htimeframe2 = input.timeframe('D', title='', inline='2', group=GRP2)
hleftBars2 = input.int(defval=7, title='Left', minval=2, maxval=20, group=GRP2,
inline='2')
hrightBars2 = input.int(defval=7, title='Right', minval=2, maxval=20, group=GRP2,
inline='2', tooltip="Highest/lowest point in x right and left bars.")

// 3
htimeframe3Show = input.bool(true, title='', inline='3', group=GRP2)
htimeframe3 = input.timeframe('3D', title='', inline='3', group=GRP2)
hleftBars3 = input.int(defval=7, title='Left', minval=2, maxval=20, group=GRP2,
inline='3')
hrightBars3 = input.int(defval=6, title='Right', minval=2, maxval=20, group=GRP2,
inline='3', tooltip="Highest/lowest point in x right and left bars.")

// 4
htimeframe4Show = input.bool(true, title='', inline='4', group=GRP2)
htimeframe4 = input.timeframe('W', title='', inline='4', group=GRP2)
hleftBars4 = input.int(defval=7, title='Left', minval=2, maxval=20, group=GRP2,
inline='4')
hrightBars4 = input.int(defval=6, title='Right', minval=2, maxval=20, group=GRP2,
inline='4', tooltip="Highest/lowest point in x right and left bars.")

// 5
htimeframe5Show = input.bool(true, title='', inline='5', group=GRP2)
htimeframe5 = input.timeframe('M', title='', inline='5', group=GRP2)
hleftBars5 = input.int(defval=6, title='Left', minval=2, maxval=20, group=GRP2,
inline='5')
hrightBars5 = input.int(defval=6, title='Right', minval=2, maxval=20, group=GRP2,
inline='5', tooltip="Highest/lowest point in x right and left bars.")

// 6
htimeframe6Show = input.bool(false, title='', inline='6', group=GRP2)
htimeframe6 = input.timeframe('2M', title='', inline='6', group=GRP2)
hleftBars6 = input.int(defval=5, title='Left', minval=2, maxval=20, group=GRP2,
inline='6')
hrightBars6 = input.int(defval=5, title='Right', minval=2, maxval=20, group=GRP2,
inline='6', tooltip="Highest/lowest point in x right and left bars.")

var GRP3 = "•••••••••• Other Settings ••••••••••"


hideLTF = input.bool(true, "Hide lines lower than enabled timeframes?", group =
GRP3)
// --------------- INPUTS ---------------

// --------------- COLORS AND LENGTH ---------------


topColor1 = color.new(color.red, 40)
bottomColor1 = color.rgb(0, 230, 23, 40)
lineLength1 = 6

topColor2 = color.new(color.red, 30)


bottomColor2 = color.rgb(0, 230, 23, 40)
lineLength2 = 10

topColor3 = color.new(color.red, 20)


bottomColor3 = color.rgb(0, 230, 23, 20)
lineLength3 = 10

topColor4 = color.new(color.red, 15)


bottomColor4 = color.rgb(0, 230, 23, 15)
lineLength4 = 10

topColor5 = color.new(color.red, 10)


bottomColor5 = color.rgb(0, 230, 23, 10)
lineLength5 = 15

topColor6 = color.new(color.red, 5)
bottomColor6 = color.rgb(0, 230, 23, 5)
lineLength6 = 15
// --------------- COLORS AND LENGTH ---------------

// --------------- FUNCTIONS ---------------


getPivotData(lb, rb) =>
ph = ta.pivothigh(lb, rb)
phtimestart = ph ? time[rb-1] : na

pl = ta.pivotlow(lb, rb)
pltimestart = pl ? time[rb-1] : na

[ph, phtimestart, pl, pltimestart]

getLineStyle(_style) =>
_linestyle = _style == "Solid" ? line.style_solid : _style == "Dashed" ?
line.style_dashed : line.style_dotted
_linestyle

resolutionInMinutes(tf = "") =>


chartTf = timeframe.multiplier * (timeframe.isseconds ? 1. / 60 :
timeframe.isminutes ? 1. : timeframe.isdaily ? 60. * 24 : timeframe.isweekly ? 60.
* 24 * 7 : timeframe.ismonthly ? 60. * 24 * 30.4375 : na)
float result = tf == "" ? chartTf : request.security(syminfo.tickerid, tf,
chartTf)

f_timeFrom(length, _units) =>


int _timeFrom = na
_unit = str.replace_all(_units, 's', '')
_timeFrom := int(time + resolutionInMinutes() * 60 * 1000 * length)
_timeFrom

notLowerTimeframe(tf) =>
_cond = hideLTF ? resolutionInMinutes() < resolutionInMinutes(tf) : true
_cond

// ▓ ▒ ░ ░

generateText(_n = 5, _large = false) =>


_symbol = "░"
_text = ""
for i = _n to 0
_text := _text + " "
for i = _n to 0
_text := _text + _symbol
if _large
_text := _text + "\n" + _text

_text
// --------------- FUNCTIONS ---------------

isLtf = resolutionInMinutes() < resolutionInMinutes("240")

// --------------- Calculate Pivots ---------------


[phchart, phtimestartchart, plchart, pltimestartchart] =
request.security(syminfo.tickerid, "5", getPivotData(6, 6), lookahead =
barmerge.lookahead_on)

[lph1, lphtimestart1, lpl1, lpltimestart1] = request.security(syminfo.tickerid,


ltimeframe1, getPivotData(lleftBars1, lrightBars1), lookahead =
barmerge.lookahead_on)
[lph2, lphtimestart2, lpl2, lpltimestart2] = request.security(syminfo.tickerid,
ltimeframe2, getPivotData(lleftBars2, lrightBars2), lookahead =
barmerge.lookahead_on)
[lph3, lphtimestart3, lpl3, lpltimestart3] = request.security(syminfo.tickerid,
ltimeframe3, getPivotData(lleftBars3, lrightBars3), lookahead =
barmerge.lookahead_on)
[lph4, lphtimestart4, lpl4, lpltimestart4] = request.security(syminfo.tickerid,
ltimeframe4, getPivotData(lleftBars4, lrightBars4), lookahead =
barmerge.lookahead_on)
[lph5, lphtimestart5, lpl5, lpltimestart5] = request.security(syminfo.tickerid,
ltimeframe5, getPivotData(lleftBars5, lrightBars5), lookahead =
barmerge.lookahead_on)
[lph6, lphtimestart6, lpl6, lpltimestart6] = request.security(syminfo.tickerid,
ltimeframe6, getPivotData(lleftBars6, lrightBars6), lookahead =
barmerge.lookahead_on)

[hph1, hphtimestart1, hpl1, hpltimestart1] = request.security(syminfo.tickerid,


htimeframe1, getPivotData(hleftBars1, hrightBars1), lookahead =
barmerge.lookahead_on)
[hph2, hphtimestart2, hpl2, hpltimestart2] = request.security(syminfo.tickerid,
htimeframe2, getPivotData(hleftBars2, hrightBars2), lookahead =
barmerge.lookahead_on)
[hph3, hphtimestart3, hpl3, hpltimestart3] = request.security(syminfo.tickerid,
htimeframe3, getPivotData(hleftBars3, hrightBars3), lookahead =
barmerge.lookahead_on)
[hph4, hphtimestart4, hpl4, hpltimestart4] = request.security(syminfo.tickerid,
htimeframe4, getPivotData(hleftBars4, hrightBars4), lookahead =
barmerge.lookahead_on)
[hph5, hphtimestart5, hpl5, hpltimestart5] = request.security(syminfo.tickerid,
htimeframe5, getPivotData(hleftBars5, hrightBars5), lookahead =
barmerge.lookahead_on)
[hph6, hphtimestart6, hpl6, hpltimestart6] = request.security(syminfo.tickerid,
htimeframe6, getPivotData(hleftBars6, hrightBars6), lookahead =
barmerge.lookahead_on)

ph1 = isLtf ? lph1 : hph1


phtimestart1 = isLtf ? lphtimestart1 : hphtimestart1
pl1 = isLtf ? lpl1 : hpl1
pltimestart1 = isLtf ? lpltimestart1 : hpltimestart1

ph2 = isLtf ? lph2 : hph2


phtimestart2 = isLtf ? lphtimestart2 : hphtimestart2
pl2 = isLtf ? lpl2 : hpl2
pltimestart2 = isLtf ? lpltimestart2 : hpltimestart2
ph3 = isLtf ? lph3 : hph3
phtimestart3 = isLtf ? lphtimestart3 : hphtimestart3
pl3 = isLtf ? lpl3 : hpl3
pltimestart3 = isLtf ? lpltimestart3 : hpltimestart3

ph4 = isLtf ? lph4 : hph4


phtimestart4 = isLtf ? lphtimestart4 : hphtimestart4
pl4 = isLtf ? lpl4 : hpl4
pltimestart4 = isLtf ? lpltimestart4 : hpltimestart4

ph5 = isLtf ? lph5 : hph5


phtimestart5 = isLtf ? lphtimestart5 : hphtimestart5
pl5 = isLtf ? lpl5 : hpl5
pltimestart5 = isLtf ? lpltimestart5 : hpltimestart5

ph6 = isLtf ? lph6 : hph6


phtimestart6 = isLtf ? lphtimestart6 : hphtimestart6
pl6 = isLtf ? lpl6 : hpl6
pltimestart6 = isLtf ? lpltimestart6 : hpltimestart6

pivothighchart = na(phchart[1]) and phchart ? phchart : na


pivotlowchart = na(plchart[1]) and plchart ? plchart : na

pivothigh1 = na(ph1[1]) and ph1 ? ph1 : na


pivotlow1 = na(pl1[1]) and pl1 ? pl1 : na

pivothigh2 = na(ph2[1]) and ph2 ? ph2 : na


pivotlow2 = na(pl2[1]) and pl2 ? pl2 : na

pivothigh3 = na(ph3[1]) and ph3 ? ph3 : na


pivotlow3 = na(pl3[1]) and pl3 ? pl3 : na

pivothigh4 = na(ph4[1]) and ph4 ? ph4 : na


pivotlow4 = na(pl4[1]) and pl4 ? pl4 : na

pivothigh5 = na(ph5[1]) and ph5 ? ph5 : na


pivotlow5 = na(pl5[1]) and pl5 ? pl5 : na

pivothigh6 = na(ph6[1]) and ph6 ? ph6 : na


pivotlow6 = na(pl6[1]) and pl6 ? pl6 : na
// --------------- Calculate Pivots ---------------

// --------------- Add to array ---------------


var float[] pivothighs1 = array.new_float(0)
var float[] pivotlows1 = array.new_float(0)

var float[] pivothighs2 = array.new_float(0)


var float[] pivotlows2 = array.new_float(0)

var float[] pivothighs3 = array.new_float(0)


var float[] pivotlows3 = array.new_float(0)

var float[] pivothighs4 = array.new_float(0)


var float[] pivotlows4 = array.new_float(0)

var float[] pivothighs5 = array.new_float(0)


var float[] pivotlows5 = array.new_float(0)
var float[] pivothighs6 = array.new_float(0)
var float[] pivotlows6 = array.new_float(0)
// --------------- Add to array ---------------

// --------------- Plot pivot points ---------------


// if barstate.islast
// label.new(bar_index, high, str.tostring(resolutionInMinutes()) +"\n"+
str.tostring(resolutionInMinutes("3")))

// ONLY LOW TIMEFRAME > 3


showTimeframe1 = isLtf ? ltimeframe1Show : htimeframe1Show
validTimeframe1 = isLtf ? notLowerTimeframe(ltimeframe1) :
notLowerTimeframe(htimeframe1)

if showTimeframe1 and pivothighchart and resolutionInMinutes() <=


resolutionInMinutes("3")
label.new(phtimestartchart, phchart, xloc=xloc.bar_time, text=generateText(12),
style=label.style_none, textcolor=topColor1)
if showTimeframe1 and pivotlowchart and resolutionInMinutes() <=
resolutionInMinutes("3")
label.new(pltimestartchart, plchart, xloc=xloc.bar_time, text=generateText(12),
style=label.style_none, textcolor=bottomColor1)

// Timeframe 1
if 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)
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)

// Timeframe 3
showTimeframe3 = isLtf ? ltimeframe3Show : htimeframe3Show
validTimeframe3 = isLtf ? notLowerTimeframe(ltimeframe3) :
notLowerTimeframe(htimeframe3)
if showTimeframe3 and pivothigh3 and validTimeframe3
label.new(phtimestart3, ph3, xloc=xloc.bar_time,
text=generateText(lineLength3), style=label.style_none, textcolor=topColor3)
if showTimeframe3 and pivotlow3 and validTimeframe3
label.new(pltimestart3, pl3, xloc=xloc.bar_time,
text=generateText(lineLength3), style=label.style_none, textcolor=bottomColor3)

// Timeframe 4
showTimeframe4 = isLtf ? ltimeframe4Show : htimeframe4Show
validTimeframe4 = isLtf ? notLowerTimeframe(ltimeframe4) :
notLowerTimeframe(htimeframe4)
if showTimeframe4 and pivothigh4 and validTimeframe4
label.new(phtimestart4, ph4, xloc=xloc.bar_time,
text=generateText(lineLength4), style=label.style_none, textcolor=topColor4)
if showTimeframe4 and pivotlow4 and validTimeframe4
label.new(pltimestart4, pl4, xloc=xloc.bar_time,
text=generateText(lineLength4), style=label.style_none, textcolor=bottomColor4)

// Timeframe 5
showTimeframe5 = isLtf ? ltimeframe5Show : htimeframe5Show
validTimeframe5 = isLtf ? notLowerTimeframe(ltimeframe5) :
notLowerTimeframe(htimeframe5)
if showTimeframe5 and pivothigh5 and validTimeframe5
label.new(phtimestart5, ph5, xloc=xloc.bar_time, text=generateText(lineLength5,
true), style=label.style_none, textcolor=topColor5)
if showTimeframe5 and pivotlow5 and validTimeframe5
label.new(pltimestart5, pl5, xloc=xloc.bar_time, text=generateText(lineLength5,
true), style=label.style_none, textcolor=bottomColor5)

// Timeframe 6
showTimeframe6 = isLtf ? ltimeframe6Show : htimeframe6Show
validTimeframe6 = isLtf ? notLowerTimeframe(ltimeframe6) :
notLowerTimeframe(htimeframe6)
if showTimeframe6 and pivothigh6 and validTimeframe6
label.new(phtimestart6, ph6, xloc=xloc.bar_time, text=generateText(lineLength6,
true), style=label.style_none, textcolor=topColor6)
if showTimeframe6 and pivotlow6 and validTimeframe6
label.new(pltimestart6, pl6, xloc=xloc.bar_time, text=generateText(lineLength6,
true), style=label.style_none, textcolor=bottomColor6)
// --------------- Plot pivot points ---------------

// --------------- Equal highs ---------------

// WATERMARK
if barstate.islast
_table = table.new("bottom_left", 1, 1)
table.cell(_table, 0, 0, text="@Nephew_Sam_", text_size=size.small,
text_color=color.new(color.gray, 50))

// This source code is subject to the terms of the Mozilla Public License 2.0 at
https://mozilla.org/MPL/2.0/
// © protradingart

//@version=5

pivotLeg = input.int(10, "Pivot Length")

var top = array.new_float(na)


var bottom = array.new_float(na)

var topIndex = array.new_int(na)


var bottomIndex = array.new_int(na)

ph = ta.pivothigh(pivotLeg, pivotLeg)
pl = ta.pivotlow(pivotLeg, pivotLeg)

////////////// Top ///////////////////


if not na(ph)
array.push(top, ph)
array.push(topIndex, bar_index-pivotLeg)

if array.size(top) > 3
array.shift(top)
array.shift(topIndex)

////////////// Bottom ///////////////////


if not na(pl)
array.push(bottom, pl)
array.push(bottomIndex, bar_index-pivotLeg)

if array.size(bottom) > 3
array.shift(bottom)
array.shift(bottomIndex)

inRange = array.size(top) >= 3 and array.size(bottom) >= 3


////////////////////////// Top
Calculation //////////////////////////////////////////////////////
topPrice = 0.0
isTop = false

if inRange
topStart = array.get(topIndex, array.size(topIndex)-1)
topPrice := array.get(top, array.size(top)-1)

if topPrice < array.get(top, array.size(top)-2) and array.get(topIndex,


array.size(topIndex)-2) > array.get(bottomIndex, array.size(bottomIndex)-3)
topPrice := array.get(top, array.size(top)-2)
topStart := array.get(topIndex, array.size(topIndex)-2)

max_index = array.indexof(top, array.max(top))


if topPrice < array.max(top) and array.get(topIndex, max_index) >
array.get(bottomIndex, array.size(bottomIndex)-3)
topPrice := array.max(top)
topStart := array.get(topIndex, max_index)

isTop := high >= topPrice and high[1] < topPrice and low < topPrice and
array.get(bottom, array.size(top)-1) > array.get(bottom, array.size(top)-2)

var topEnd = 0

if isTop
topEnd := bar_index
topLine = line.new(x1=topStart, y1=topPrice, x2=topEnd, y2=topPrice,
color=color.lime, width=1)
topA = label.new(x=topStart, y=topPrice, text="Top 1", color=color.lime,
style=label.style_label_down, textcolor=color.black, size=size.small)
topB = label.new(x=topEnd, y=topPrice, text="Top 2", color=color.lime,
style=label.style_label_down, textcolor=color.black, size=size.small)
alert("Double Top In: "+str.tostring(syminfo.ticker),
alert.freq_once_per_bar_close)

////////////////////////// Bottom
Calculation //////////////////////////////////////////////////////
bottomPrice = 0.0
isBottom = false

if inRange
bottomStart = array.get(bottomIndex, array.size(bottomIndex)-1)
bottomPrice := array.get(bottom, array.size(bottom)-1)

if bottomPrice > array.get(bottom, array.size(bottom)-2) and


array.get(bottomIndex, array.size(bottomIndex)-2) > array.get(topIndex,
array.size(topIndex)-3)
bottomPrice := array.get(bottom, array.size(bottom)-2)
bottomStart := array.get(bottomIndex, array.size(bottomIndex)-2)

min_index = array.indexof(bottom, array.min(bottom))


if bottomPrice > array.min(bottom) and array.get(bottomIndex, min_index) >
array.get(topIndex, array.size(topIndex)-3)
bottomPrice := array.min(bottom)
bottomStart := array.get(bottomIndex, min_index)

isBottom := low <= bottomPrice and low[1] > bottomPrice and high > bottomPrice
and array.get(top, array.size(top)-1) < array.get(top, array.size(top)-2)

var bottomEnd = 0

if isBottom
bottomEnd := bar_index
bottomLine = line.new(x1=bottomStart, y1=bottomPrice, x2=bottomEnd,
y2=bottomPrice, color=color.red, width=1)
bottomA = label.new(x=bottomStart, y=bottomPrice, text="Bottom 1",
color=color.red, style=label.style_label_up, textcolor=color.black, size=size.tiny)
bottomB = label.new(x=bottomEnd, y=bottomPrice, text="Bottom 2",
color=color.red, style=label.style_label_up, textcolor=color.black, size=size.tiny)
alert("Double Bottom In: "+str.tostring(syminfo.ticker),
alert.freq_once_per_bar_close)

You might also like