0% found this document useful (0 votes)
23 views47 pages

A

This document contains a Pine Script™ code for a trading indicator named 'FluidTrades - SMC' designed for use on trading platforms. It includes various user inputs for customization, calculations for bullish and bearish signals, and visual elements such as swing lines and alerts. The script is governed by the Mozilla Public License 2.0 and is intended for technical analysis in trading.

Uploaded by

h.ermenkov
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)
23 views47 pages

A

This document contains a Pine Script™ code for a trading indicator named 'FluidTrades - SMC' designed for use on trading platforms. It includes various user inputs for customization, calculations for bullish and bearish signals, and visual elements such as swing lines and alerts. The script is governed by the Mozilla Public License 2.0 and is intended for technical analysis in trading.

Uploaded by

h.ermenkov
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/ 47

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

0
at https://mozilla.org/MPL/2.0/
// © Deewithme
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0
at https://mozilla.org/MPL/2.0/
// © Deewithme
// This source code is subject to the terms of the Mozilla Public License 2.0 at
https://mozilla.org/MPL/2.0/
// © Pmgjill
//@version=5
indicator("FluidTrades - SMC", overlay = true, max_labels_count = 500,
max_boxes_count = 500, max_lines_count = 500, max_bars_back = 1000)

//TELEGRAM ==> https://t.me/eyops


//INPUTS
cooldownPeriod = input.int(10,title="Cooldown Period", minval=0, group =
"Settings")

lbLeft = 20
lbRight = 20

showSwing = input.bool(true,title="Show Swings?", inline="s_1", group = 'Swing


Detaction')
swingClr = input.color(color.rgb(3, 205, 251), title='', inline="s_1", group =
'Swing Detaction')

bullWidth = input.int(1, title='Line Width:', group='Bullish Sweep')


bullStyle = input.string('Dashed', title='Line Style:', options=['Solid', 'Dotted',
'Dashed'], group='Bullish Sweep')
bullColor = input.color(color.rgb(255, 255, 255), title='Bullish Color:',
group='Bullish Sweep')

bearWidth = input.int(1, title='Line Width:', group='Bearish Sweep')


bearStyle = input.string('Dashed', title='Line Style:', options=['Solid', 'Dotted',
'Dashed'], group='Bearish Sweep')
bearColor = input.color(color.rgb(255, 255, 255), title='Bearish Color:',
group='Bearish Sweep')

//FUNCTIONS
lineStyle(s) =>
if s == 'Solid'
line.style_solid
else if s == 'Dotted'
line.style_dotted
else
line.style_dashed

//VARS
var int bullSignalIndex = 0
var int bearSignalIndex = 0

var line bullLine = na


var line bearLine = na

var line highLine = na


var line lowLine = na

var label swingHighLbl = na


var label swingLowLbl = na
var label swingHighLblTxt = na
var label swingLowLblTxt = na

var float swingLowVal = na


var float swingHighVal = na

//CALCULATIONS
pLow = ta.pivotlow(low, lbLeft, lbRight)
pHigh = ta.pivothigh(high, lbLeft, lbRight)

pLowVal = ta.valuewhen(not na(pLow), low[lbRight], 0)


pHighVal = ta.valuewhen(not na(pHigh), high[lbRight], 0)

prevLowIndex = ta.valuewhen(not na(pLow), bar_index[lbRight], 0)


prevHighIndex = ta.valuewhen(not na(pHigh), bar_index[lbRight], 0)

lp = ta.lowest(low, lbLeft)
hp = ta.highest(high, lbLeft)

highestClose = ta.highest(close, lbLeft)


lowestClose = ta.lowest(close, lbLeft)

bullishSFP = low < pLowVal and close > pLowVal and open > pLowVal and low == lp and
lowestClose >= pLowVal
bearishSFP = high > pHighVal and close < pHighVal and open < pHighVal and high ==
hp and highestClose <= pHighVal

bullCond = bullishSFP[3] and (close > pLowVal) and (close[1] > pLowVal[1]) and
(close[2] > pLowVal[2]) and bar_index >= bullSignalIndex + cooldownPeriod
bearCond = bearishSFP[3] and (close < pHighVal) and (close[1] < pHighVal[1]) and
(close[2] < pHighVal[2]) and bar_index >= bearSignalIndex + cooldownPeriod

//Check Swing H/L Stopper


var int swingLowCounter = 0
var int swingHighCounter = 0
var bool isSwingLowCheck = false
var bool isSwingHighCheck = false
var bool stopPrintingLow = false
var bool stopPrintingHigh = false

if high < swingLowVal and isSwingLowCheck


swingLowCounter := swingLowCounter+1

if low > swingHighVal and isSwingHighCheck


swingHighCounter := swingHighCounter+1

if ta.crossunder(close, swingLowVal) and isSwingLowCheck == false


isSwingLowCheck := true
swingLowCounter := 1
if ta.crossover(close, swingHighVal) and isSwingHighCheck == false
isSwingHighCheck := true
swingHighCounter := 1

if swingLowCounter == 5 and isSwingLowCheck


stopPrintingLow := true
isSwingLowCheck := false
line.set_x2(lowLine,bar_index[4])

if swingHighCounter == 5 and isSwingHighCheck


stopPrintingHigh := true
isSwingHighCheck := false
line.set_x2(highLine,bar_index[4])

//Draw sweep lines


if bullCond
bullSignalIndex := bar_index
bullLine := line.new(prevLowIndex, pLowVal, bar_index-3, pLowVal,
color=bullColor, width=bullWidth, style=lineStyle(bullStyle))

if bearCond
bearSignalIndex := bar_index
bearLine := line.new(prevHighIndex, pHighVal, bar_index-3, pHighVal,
color=bearColor, width=bearWidth, style=lineStyle(bearStyle))

var swingHighArr = array.new_label(0)


var swingHighTextArr = array.new_label(0)

var swingLowArr = array.new_label(0)


var swingLowTextArr = array.new_label(0)

if array.size(swingHighArr) >= 3
label.delete(array.shift(swingHighArr))
label.delete(array.shift(swingHighTextArr))

if array.size(swingLowArr) >= 3
label.delete(array.shift(swingLowArr))
label.delete(array.shift(swingLowTextArr))

//Draw range lines


if showSwing
if stopPrintingHigh == false
line.set_x2(highLine,bar_index+5)
if stopPrintingLow == false
line.set_x2(lowLine,bar_index+5)

if showSwing and not na(pHigh) and bearishSFP[lbRight] == false


stopPrintingHigh := false
swingHighVal := high[lbRight]
line.delete(highLine)
highLine := line.new(bar_index[lbRight], high[lbRight], bar_index+10,
high[lbRight], color = swingClr, width = 2)

swingHighLbl := label.new(bar_index[lbRight], high[lbRight], text="",


yloc=yloc.abovebar, color = swingClr, textcolor = swingClr, style =
label.style_triangledown, size = size.auto)
swingHighLblTxt := label.new(bar_index[lbRight], high[lbRight], text="Swing\
nH", yloc=yloc.abovebar, color = swingClr, textcolor = swingClr, style =
label.style_none, size = size.small)
array.push(swingHighArr, swingHighLbl)
array.push(swingHighTextArr, swingHighLblTxt)

if showSwing and not na(pLow) and bullishSFP[lbRight] == false


stopPrintingLow := false
swingLowVal := low[lbRight]
line.delete(lowLine)
lowLine := line.new(bar_index[lbRight], low[lbRight], bar_index+10,
low[lbRight], color = swingClr, width = 2)

swingLowLbl := label.new(bar_index[lbRight], low[lbRight], text="",


yloc=yloc.belowbar, color = swingClr, textcolor = swingClr, style =
label.style_triangleup, size = size.auto)
swingLowLblTxt := label.new(bar_index[lbRight], low[lbRight], text="Swing\nL",
yloc=yloc.belowbar, color = swingClr, textcolor = swingClr, style =
label.style_none, size = size.small)
array.push(swingLowArr, swingLowLbl)
array.push(swingLowTextArr, swingLowLblTxt)

//PLOTS
plotshape(bullCond, text='LIQUZ', color=bullColor, textcolor=bullColor,
location=location.belowbar, offset = -3)
plotshape(bearCond, text='LIQUZ', color=bearColor, textcolor=bearColor,
location=location.abovebar, offset = -3)

//ALERTS
alertcondition(bullishSFP, title='Bullish Sweep', message='{{ticker}} Bullish
Sweep, Price:{{close}}')
alertcondition(bearishSFP, title='Bearish Sweep', message='{{ticker}} Bearish
Sweep, Price:{{close}}')

//------------------ AI Signals | https://www.getaisignals.com ---------------//


// Get user input
sensitivity = input.string("Low", "Sensitivity", ["Low", "Medium", "High"])
suppRes = input.bool(false, "Support & Resistance")
breaks = input.bool(false, "Breaks")
signals = input.bool(true, "Buy/Sell Signals?")
emaEnergy = input.bool(true, "EMA Energy")
channelBal = input.bool(true, "Channel Balance")

// Functions
supertrend(_src, factor, atrLen) =>
atr = ta.atr(atrLen)
upperBand = _src + factor * atr
lowerBand = _src - factor * atr
prevLowerBand = nz(lowerBand[1])
prevUpperBand = nz(upperBand[1])
lowerBand := lowerBand > prevLowerBand or close[1] < prevLowerBand ?
lowerBand : prevLowerBand
upperBand := upperBand < prevUpperBand or close[1] > prevUpperBand ?
upperBand : prevUpperBand
int direction = na
float superTrend = na
prevSuperTrend = superTrend[1]
if na(atr[1])
direction := 1
else if prevSuperTrend == prevUpperBand
direction := close > upperBand ? -1 : 1
else
direction := close < lowerBand ? 1 : -1
superTrend := direction == -1 ? lowerBand : upperBand
[superTrend, direction]
lr_slope(_src, _len) =>
x = 0.0, y = 0.0, x2 = 0.0, xy = 0.0
for i = 0 to _len - 1
val = _src[i]
per = i + 1
x += per
y += val
x2 += per * per
xy += val * per
_slp = (_len * xy - x * y) / (_len * x2 - x * x)
_avg = y / _len
_int = _avg - _slp * x / _len + _slp
[_slp, _avg, _int]
lr_dev(_src, _len, _slp, _avg, _int) =>
upDev = 0.0, dnDev = 0.0
val = _int
for j = 0 to _len - 1
price = high[j] - val
if price > upDev
upDev := price
price := val - low[j]
if price > dnDev
dnDev := price
price := _src[j]
val += _slp
[upDev, dnDev]
// Get Components
ocAvg = math.avg(open, close)
sma1 = ta.sma(close, 5)
sma2 = ta.sma(close, 6)
sma3 = ta.sma(close, 7)
sma4 = ta.sma(close, 8)
sma5 = ta.sma(close, 9)
sma6 = ta.sma(close, 10)
sma7 = ta.sma(close, 11)
sma8 = ta.sma(close, 12)
sma9 = ta.sma(close, 13)

psar = ta.sar(0.02, 0.02, 0.2)


[middleKC1, upperKC1, lowerKC1] = ta.kc(close, 80, 10.5)
[middleKC2, upperKC2, lowerKC2] = ta.kc(close, 80, 9.5)
[middleKC3, upperKC3, lowerKC3] = ta.kc(close, 80, 8)
[middleKC4, upperKC4, lowerKC4] = ta.kc(close, 80, 3)
[supertrend, direction] = supertrend(close, sensitivity == "Low" ? 6.8 :
sensitivity == "Medium" ? 2.5 : 3, 11)
barsL = 10
barsR = 10
pivotHigh = fixnan(ta.pivothigh(barsL, barsR)[1])
pivotLow = fixnan(ta.pivotlow(barsL, barsR)[1])
source = close, period1 = 150
[s, a, i] = lr_slope(source, period1)
[upDev, dnDev] = lr_dev(source, period1, s, a, i)
// Colors
green1 = #6df902ce, green2 = #5bcd04e4
red1 = #f9040485, red2 = #DD0000
emaEnergyColor(ma) => emaEnergy ? (close >= ma ? green1 : red1) : na
// Plots
k1 = plot(ta.ema(upperKC1, 50), "", na, editable=false)
k2 = plot(ta.ema(upperKC2, 50), "", na, editable=false)
k3 = plot(ta.ema(upperKC3, 50), "", na, editable=false)
k4 = plot(ta.ema(upperKC4, 50), "", na, editable=false)
k5 = plot(ta.ema(lowerKC4, 50), "", na, editable=false)
k6 = plot(ta.ema(lowerKC3, 50), "", na, editable=false)
k7 = plot(ta.ema(lowerKC2, 50), "", na, editable=false)
k8 = plot(ta.ema(lowerKC1, 50), "", na, editable=false)
fill(k1, k2, channelBal ? color.new(red2, 40) : na, editable=false)
fill(k2, k3, channelBal ? color.new(red2, 65) : na, editable=false)
fill(k3, k4, channelBal ? color.new(red2, 90) : na, editable=false)
fill(k5, k6, channelBal ? color.new(green2, 90) : na, editable=false)
fill(k6, k7, channelBal ? color.new(green2, 65) : na, editable=false)
fill(k7, k8, channelBal ? color.new(green2, 40) : na, editable=false)
plot(sma1, "", emaEnergyColor(sma1), editable=false)
plot(sma2, "", emaEnergyColor(sma2), editable=false)

y1 = low - (ta.atr(30) * 2), y1B = low - ta.atr(30)


y2 = high + (ta.atr(30) * 2), y2B = high + ta.atr(30)
bull = ta.crossover(close, supertrend) and close >= sma9
bear = ta.crossunder(close, supertrend) and close <= sma9
buy = bull ? label.new(bar_index, y1, "Buy🚀", xloc.bar_index, yloc.price, #2BE300,
label.style_label_up, #000000) : na
sell = bear ? label.new(bar_index, y2, "Sell 🐻", xloc.bar_index, yloc.price, red2,
label.style_label_down, color.white) : na

plot(pivotHigh, "Resistance", not suppRes or ta.change(pivotHigh) ? na : red2, 2,


offset=-(barsR + 1), editable=false)
plot(pivotLow, "Support", not suppRes or ta.change(pivotLow) ? na : green2, 2,
offset=-(barsR + 1), editable=false)
upB = breaks and ta.crossover(close, pivotHigh) ? label.new(bar_index, y1B, "B",
xloc.bar_index, yloc.price, green1, label.style_label_up, color.white,
size.small) : na
dnB = breaks and ta.crossunder(close, pivotLow) ? label.new(bar_index, y2B, "B",
xloc.bar_index, yloc.price, red1, label.style_label_down, color.white,
size.small) : na
x1 = bar_index - period1 + 1, _y1 = i + s * (period1 - 1), x2 = bar_index, _y2 = i

//@version=5
//ndicator("Simplealgo.io v5 "
//, overlay = true
/// max_labels_count = 500
//, max_lines_count = 500
// max_boxes_count = 500// max_bars_back = 500)

//
===================================================================================
====
// MODULO DE SEÑALES PARA MEGA POWER
//
===================================================================================
====

changeCond = bull or bear //NECESARIO PARA EL MODULO DE TPS


//
===================================================================================
====

// Módulo - Entrada - SL - TPS mejora enviada por: CRIPTOMAN SPAIN @CRIPTOTR4DER


//-----------------------------------------
//*********************************************************
//* Módulo *
//* Entrada - SL - TPSEND *
//*********************************************************
// Cálculos
groupEnTpSl = "Módulo - Signals"
plot(na)
//
===================================================================================
====
//ESTO ES EL CALCULO COMO SE HACIA EN EL PRIMER SCRIPT QUE ME ENVIASTE
//
===================================================================================
====
levels_tip = "Habilita etiquetas compra/venta /SL"
atrLen_tip = "Atr para el Calculo de Stoploss y TakeProfit"
atrRisk_tip = "Multiplicador de Riesgo ATR: Recomendado 1.5 o 1.9"
levels1 = input(title='Mostrar Etiquetas de Entrada/SL/TP', defval=true,
group=groupEnTpSl, tooltip=levels_tip)
atrLen = input.int(10, "ATR Length SL ", group=groupEnTpSl, tooltip=atrLen_tip)
atrRisk = input.float(1, "ATR Risk SL", group=groupEnTpSl,tooltip=atrRisk_tip )
trigger = bull ? 1 : 0
atrBand = ta.atr(atrLen) * atrRisk
atrStop = trigger == 1 ? low - atrBand : high + atrBand
//
===================================================================================
====
lastTrade(src) => ta.valuewhen(changeCond, src, 0 )
//
===================================================================================
====
//
===================================================================================
====
//ENTRADAS
entry = levels1 ? label.new(time, close, "ENTRY" + str.tostring(lastTrade(close),
"#.######"), xloc.bar_time, yloc.price, #501da800, label.style_label_left,
color.rgb(4, 158, 214), size.normal) : na
label.set_y(entry, lastTrade(close))
label.delete(entry[1])
stop_y = lastTrade(atrStop)

tp1_y = (lastTrade(close)-lastTrade(atrStop))*1 + lastTrade(close)


tp1 = levels1 ? label.new(time, close, " 1 - " + str.tostring(tp1_y, "#.#####"),
xloc.bar_time, yloc.price, #51ff0000, label.style_label_left, #01ff16,
size.normal) : na
label.set_y(tp1, tp1_y)
label.delete(tp1[1])
tp2_y = (lastTrade(close)-lastTrade(atrStop))*2 + lastTrade(close)
tp2 = levels1 ? label.new(time, close, " 2 - " + str.tostring(tp2_y, "#.#####"),
xloc.bar_time, yloc.price, #51ff0000, label.style_label_left, #01ff16, size.normal)
: na
label.set_y(tp2, tp2_y)
label.delete(tp2[1])
tp3_y = (lastTrade(close)-lastTrade(atrStop))*3 + lastTrade(close)
tp3 = levels1 ? label.new(time, close, " 3 - " + str.tostring(tp3_y, "#.#####"),
xloc.bar_time, yloc.price, #51ff0000, label.style_label_left, #01ff16, size.normal)
: na
label.set_y(tp3, tp3_y)
label.delete(tp3[1])

// 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("Trendlines with Breaks [LuxAlgo]", "LuxAlgo - Trendlines with Breaks",
overlay = true)
//------------------------------------------------------------------------------
//Settings
//-----------------------------------------------------------------------------{
length = input.int(14, 'Swing Detection Lookback')
mult = input.float(1., 'Slope', minval = 0, step = .1)
calcMethod = input.string('Atr', 'Slope Calculation Method', options =
['Atr','Stdev','Linreg'])
backpaint = input(true, tooltip = 'Backpainting offset displayed elements in the
past. Disable backpainting to see real time information returned by the
indicator.')

//Style
upCss = input.color(color.teal, 'Up Trendline Color', group = 'Style')
dnCss = input.color(color.red, 'Down Trendline Color', group = 'Style')
showExt = input(true, 'Show Extended Lines')

//-----------------------------------------------------------------------------}
//Calculations
//-----------------------------------------------------------------------------{
var upper = 0.
var lower = 0.
var slope_ph = 0.
var slope_pl = 0.

var offset = backpaint ? length : 0

n = bar_index
src = close

phh = ta.pivothigh(length, length)


pll = ta.pivotlow(length, length)

//Slope Calculation Method


slope = switch calcMethod
'Atr' => ta.atr(length) / length * mult
'Stdev' => ta.stdev(src,length) / length * mult
'Linreg' => math.abs(ta.sma(src * n, length) - ta.sma(src, length) * ta.sma(n,
length)) / ta.variance(n, length) / 2 * mult

//Get slopes and calculate trendlines


slope_ph := phh ? slope : slope_ph
slope_pl := pll ? slope : slope_pl

upper := phh ? phh : upper - slope_ph


lower := pll ? pll : lower + slope_pl

var upos = 0
var dnos = 0
upos := phh ? 0 : close > upper - slope_ph * length ? 1 : upos
dnos := pll ? 0 : close < lower + slope_pl * length ? 1 : dnos

//-----------------------------------------------------------------------------}
//Extended Lines
//-----------------------------------------------------------------------------{
var uptl = line.new(na,na,na,na, color = upCss, style = line.style_dashed, extend
= extend.right)
var dntl = line.new(na,na,na,na, color = dnCss, style = line.style_dashed, extend
= extend.right)

if phh and showExt


uptl.set_xy1(n-offset, backpaint ? phh : upper - slope_ph * length)
uptl.set_xy2(n-offset+1, backpaint ? phh - slope : upper - slope_ph *
(length+1))

if pll and showExt


dntl.set_xy1(n-offset, backpaint ? pll : lower + slope_pl * length)
dntl.set_xy2(n-offset+1, backpaint ? pll + slope : lower + slope_pl *
(length+1))

//-----------------------------------------------------------------------------}
//Plots
//-----------------------------------------------------------------------------{
plot(backpaint ? upper : upper - slope_ph * length, 'Upper', color = phh ? na :
upCss, offset = -offset)
plot(backpaint ? lower : lower + slope_pl * length, 'Lower', color = pll ? na :
dnCss, offset = -offset)

//Breakouts
plotshape(upos > upos[1] ? low : na, "Upper Break"
, shape.labelup
, location.absolute
, upCss
, text = "B"
, textcolor = color.white
, size = size.tiny)

plotshape(dnos > dnos[1] ? high : na, "Lower Break"


, shape.labeldown
, location.absolute
, dnCss
, text = "B"
, textcolor = color.white
, size = size.tiny)

//-----------------------------------------------------------------------------}
//Alerts
//-----------------------------------------------------------------------------{

//SETTINGS
//

// On & Off functionality


enableSR = input.bool(false, title = 'Support/Resistance', group = 'On & Off
functionality',inline = 'overlayLine1')
enableDS = input.bool(false, title = 'Demand/Supply', group = 'On & Off
functionality',inline = 'overlayLine1')

box_ob = input.bool(false, title = 'Toggle Order Block', group = 'On & Off
functionality',inline = 'overlayLine2')
box_hide_gray = input.bool(true, title = 'Hide gray boxes', group = 'On & Off
functionality',inline = 'overlayLine2')

showIndicator = input.bool(true, title = 'EMA', group = 'On & Off


functionality',inline = 'overlayLine3')
showVWAP = input.bool(false, title = 'VWAP', group = 'On & Off
functionality',inline = 'overlayLine3')
showORB = input.bool(false, title = 'ORB', group = 'On & Off functionality',inline
= 'overlayLine3')
rsicol = input.bool(false, title = 'Show RSI colors?', group = 'On & Off
functionality',inline = 'overlayLine3')

volumeProfile = input.bool(false, title = 'Volume Profile', group = 'On & Off


functionality',inline = 'overlayLine4')
volumeHistogram = input.bool(false, title = 'Volume Histogram', group = 'On & Off
functionality',inline = 'overlayLine4')

trendTable = input.bool(true, title = 'Show Trend Table', group = 'On & Off
functionality',inline = 'overlayLine5')
trendCalc = input.string(defval = "EMA", title = "Trend Mode",
options=["Supertrend", "EMA"], group = 'On & Off functionality',inline =
'overlayLine5')
showDXY = input.bool(false, title = 'Show DXY', group = 'On & Off
functionality',inline = 'overlayLine5')

show_price_action_labels = input.bool(false, title = 'Show Price Action Labels',


group = 'On & Off functionality',inline = 'overlayLine6')
show_zigzag = input.bool(false, title = 'Show Zig Zag', group = 'On & Off
functionality', inline = 'overlayLine6')

showTL = input.bool(false, title = 'TrendLine', group = 'On & Off functionality',


inline = 'overlayLine7')
periodlen = input.string('Adaptive', 'Trendline Term', ['Long Term', 'Short
Term','Adaptive'], group = 'On & Off functionality', inline = 'overlayLine7')
showSR = input.bool(false, title = 'S&R', group = 'On & Off functionality', inline
= 'overlayLine7')
timef = input.timeframe("", "", group = 'On & Off functionality', inline =
'overlayLine7')
// INDICATOR SETTINGS
swing_length = input.int(10, title = 'Swing High/Low Length', group = 'Settings',
minval = 1, maxval = 50)
history_of_demand_to_keep = input.int(20, title = 'History To Keep', minval = 5,
maxval = 50)
box_width = input.float(10, title = 'Supply/Demand Box Width', group = 'Settings',
minval = 1, maxval = 10, step = 0.5)

// INDICATOR VISUAL SETTINGS


// show_zigzag = input.bool(false, title = 'Show Zig Zag', group = 'Visual
Settings', inline = '1')
// show_price_action_labels = input.bool(false, title = 'Show Price Action Labels',
group = 'Visual Settings', inline = '2')

supply_color = input.color(color.new(#EDEDED,70), title = 'Supply', group = 'Visual


Settings', inline = '3')
supply_outline_color = input.color(color.new(color.white,75), title = 'Outline',
group = 'Visual Settings', inline = '3')

demand_color = input.color(color.new(#00FFFF,70), title = 'Demand', group = 'Visual


Settings', inline = '4')
demand_outline_color = input.color(color.new(color.white,75), title = 'Outline',
group = 'Visual Settings', inline = '4')

bos_label_color = input.color(color.white, title = 'BOS Label', group = 'Visual


Settings', inline = '5')
poi_label_color = input.color(color.white, title = 'POI Label', group = 'Visual
Settings', inline = '7')

swing_type_color = input.color(color.lime, title = 'Price Action Label', group =


'Visual Settings', inline = '8')
zigzag_color = input.color(color.new(#000000,0), title = 'Zig Zag', group = 'Visual
Settings', inline = '9')

//
//END SETTINGS
//

//
//FUNCTIONS
//

// FUNCTION TO ADD NEW AND REMOVE LAST IN ARRAY


f_array_add_pop(array, new_value_to_add) =>
array.unshift(array, new_value_to_add)
array.pop(array)

// FUNCTION SWING H & L LABELS


f_sh_sl_labels(array, swing_type) =>

var string label_text = na


if swing_type == 1
if array.get(array, 0) >= array.get(array, 1)
label_text := 'HH'
else
label_text := 'LH'
label.new(bar_index - swing_length, array.get(array,0), text = label_text,
style=label.style_label_down, textcolor = swing_type_color, color =
color.new(swing_type_color, 100), size = size.tiny)

else if swing_type == -1
if array.get(array, 0) >= array.get(array, 1)
label_text := 'HL'
else
label_text := 'LL'
label.new(bar_index - swing_length, array.get(array,0), text = label_text,
style=label.style_label_up, textcolor = swing_type_color, color =
color.new(swing_type_color, 100), size = size.tiny)

// FUNCTION MAKE SURE SUPPLY ISNT OVERLAPPING


f_check_overlapping(new_poi, box_array, atr) =>

atr_threshold = atr * 2
okay_to_draw = true

for i = 0 to array.size(box_array) - 1
top = box.get_top(array.get(box_array, i))
bottom = box.get_bottom(array.get(box_array, i))
poi = (top + bottom) / 2

upper_boundary = poi + atr_threshold


lower_boundary = poi - atr_threshold

if new_poi >= lower_boundary and new_poi <= upper_boundary


okay_to_draw := false
break
else
okay_to_draw := true
okay_to_draw

// FUNCTION TO DRAW SUPPLY OR DEMAND ZONE


f_supply_demand(value_array, bn_array, box_array, label_array, box_type, atr) =>

atr_buffer = atr * (box_width / 10)


box_left = array.get(bn_array, 0)
box_right = bar_index

var float box_top = 0.00


var float box_bottom = 0.00
var float poi = 0.00

if box_type == 1
box_top := array.get(value_array, 0)
box_bottom := box_top - atr_buffer
poi := (box_top + box_bottom) / 2
else if box_type == -1
box_bottom := array.get(value_array, 0)
box_top := box_bottom + atr_buffer
poi := (box_top + box_bottom) / 2

okay_to_draw = f_check_overlapping(poi, box_array, atr)


// okay_to_draw = true

//delete oldest box, and then create a new box and add it to the array
if box_type == 1 and okay_to_draw and enableDS
box.delete( array.get(box_array, array.size(box_array) - 1) )
f_array_add_pop(box_array, box.new( left = box_left, top = box_top, right =
box_right, bottom = box_bottom, border_color = supply_outline_color,
bgcolor = supply_color, extend = extend.right, text = 'SUPPLY',
text_halign = text.align_center, text_valign = text.align_center, text_color =
poi_label_color, text_size = size.small, xloc = xloc.bar_index))

box.delete( array.get(label_array, array.size(label_array) - 1) )


f_array_add_pop(label_array, box.new( left = box_left, top = poi, right =
box_right, bottom = poi, border_color = color.new(poi_label_color,90),
bgcolor = color.new(poi_label_color,90), extend = extend.right, text =
'POI', text_halign = text.align_left, text_valign = text.align_center, text_color =
poi_label_color, text_size = size.small, xloc = xloc.bar_index))

else if box_type == -1 and okay_to_draw and enableDS


box.delete( array.get(box_array, array.size(box_array) - 1) )
f_array_add_pop(box_array, box.new( left = box_left, top = box_top, right =
box_right, bottom = box_bottom, border_color = demand_outline_color,
bgcolor = demand_color, extend = extend.right, text = 'DEMAND',
text_halign = text.align_center, text_valign = text.align_center, text_color =
poi_label_color, text_size = size.small, xloc = xloc.bar_index))

box.delete( array.get(label_array, array.size(label_array) - 1) )


f_array_add_pop(label_array, box.new( left = box_left, top = poi, right =
box_right, bottom = poi, border_color = color.new(poi_label_color,90),
bgcolor = color.new(poi_label_color,90), extend = extend.right, text
= 'POI', text_halign = text.align_left, text_valign = text.align_center, text_color
= poi_label_color, text_size = size.small, xloc = xloc.bar_index))

// FUNCTION TO CHANGE SUPPLY/DEMAND TO A BOS IF BROKEN


f_sd_to_bos(box_array, bos_array, label_array, zone_type) =>

if zone_type == 1
for i = 0 to array.size(box_array) - 1
level_to_break = box.get_top(array.get(box_array,i))
// if ta.crossover(close, level_to_break)
if close >= level_to_break
copied_box = box.copy(array.get(box_array,i))
f_array_add_pop(bos_array, copied_box)
mid = (box.get_top(array.get(box_array,i)) +
box.get_bottom(array.get(box_array,i))) / 2
box.set_top(array.get(bos_array,0), mid)
box.set_bottom(array.get(bos_array,0), mid)
box.set_extend( array.get(bos_array,0), extend.none)
box.set_right( array.get(bos_array,0), bar_index)
box.set_text( array.get(bos_array,0), 'BOS' )
box.set_text_color( array.get(bos_array,0), bos_label_color)
box.set_text_size( array.get(bos_array,0), size.small)
box.set_text_halign( array.get(bos_array,0), text.align_center)
box.set_text_valign( array.get(bos_array,0), text.align_center)
box.delete(array.get(box_array, i))
box.delete(array.get(label_array, i))

if zone_type == -1
for i = 0 to array.size(box_array) - 1
level_to_break = box.get_bottom(array.get(box_array,i))
// if ta.crossunder(close, level_to_break)
if close <= level_to_break
copied_box = box.copy(array.get(box_array,i))
f_array_add_pop(bos_array, copied_box)
mid = (box.get_top(array.get(box_array,i)) +
box.get_bottom(array.get(box_array,i))) / 2
box.set_top(array.get(bos_array,0), mid)
box.set_bottom(array.get(bos_array,0), mid)
box.set_extend( array.get(bos_array,0), extend.none)
box.set_right( array.get(bos_array,0), bar_index)
box.set_text( array.get(bos_array,0), 'BOS' )
box.set_text_color( array.get(bos_array,0), bos_label_color)
box.set_text_size( array.get(bos_array,0), size.small)
box.set_text_halign( array.get(bos_array,0), text.align_center)
box.set_text_valign( array.get(bos_array,0), text.align_center)
box.delete(array.get(box_array, i))
box.delete(array.get(label_array, i))

// FUNCTION MANAGE CURRENT BOXES BY CHANGING ENDPOINT


f_extend_box_endpoint(box_array) =>

for i = 0 to array.size(box_array) - 1
box.set_right(array.get(box_array, i), bar_index + 100)

//
//END FUNCTIONS
//

//
//CALCULATIONS
//

// CALCULATE ATR
atr = ta.atr(50)

// CALCULATE SWING HIGHS & SWING LOWS


swing_high = ta.pivothigh(high, swing_length, swing_length)
swing_low = ta.pivotlow(low, swing_length, swing_length)

// ARRAYS FOR SWING H/L & BN


var swing_high_values = array.new_float(5,0.00)
var swing_low_values = array.new_float(5,0.00)

var swing_high_bns = array.new_int(5,0)


var swing_low_bns = array.new_int(5,0)

// ARRAYS FOR SUPPLY / DEMAND


var current_supply_box = array.new_box(history_of_demand_to_keep, na)
var current_demand_box = array.new_box(history_of_demand_to_keep, na)

// ARRAYS FOR SUPPLY / DEMAND POI LABELS


var current_supply_poi = array.new_box(history_of_demand_to_keep, na)
var current_demand_poi = array.new_box(history_of_demand_to_keep, na)

// ARRAYS FOR BOS


var supply_bos = array.new_box(5, na)
var demand_bos = array.new_box(5, na)
//
//END CALCULATIONS
//

// NEW SWING HIGH


if not na(swing_high)

//MANAGE SWING HIGH VALUES


f_array_add_pop(swing_high_values, swing_high)
f_array_add_pop(swing_high_bns, bar_index[swing_length])
if show_price_action_labels
f_sh_sl_labels(swing_high_values, 1)

f_supply_demand(swing_high_values, swing_high_bns, current_supply_box,


current_supply_poi, 1, atr)

// NEW SWING LOW


else if not na(swing_low)

//MANAGE SWING LOW VALUES


f_array_add_pop(swing_low_values, swing_low)
f_array_add_pop(swing_low_bns, bar_index[swing_length])
if show_price_action_labels
f_sh_sl_labels(swing_low_values, -1)

f_supply_demand(swing_low_values, swing_low_bns, current_demand_box,


current_demand_poi, -1, atr)

f_sd_to_bos(current_supply_box, supply_bos, current_supply_poi, 1)


f_sd_to_bos(current_demand_box, demand_bos, current_demand_poi, -1)

f_extend_box_endpoint(current_supply_box)
f_extend_box_endpoint(current_demand_box)

//ZIG ZAG
h = ta.highest(high, swing_length * 2 + 1)
l = ta.lowest(low, swing_length * 2 + 1)
f_isMin(len) =>
l == low[len]
f_isMax(len) =>
h == high[len]

var dirUp = false


var lastLow = high * 100
var lastHigh = 0.0
var timeLow = bar_index
var timeHigh = bar_index
var line li = na

f_drawLine() =>
_li_color = show_zigzag ? zigzag_color : color.new(#ffffff,100)
line.new(timeHigh - swing_length, lastHigh, timeLow - swing_length, lastLow,
xloc.bar_index, color=_li_color, width=2)

if dirUp
if f_isMin(swing_length) and low[swing_length] < lastLow
lastLow := low[swing_length]
timeLow := bar_index
line.delete(li)
li := f_drawLine()
li

if f_isMax(swing_length) and high[swing_length] > lastLow


lastHigh := high[swing_length]
timeHigh := bar_index
dirUp := false
li := f_drawLine()
li

if not dirUp
if f_isMax(swing_length) and high[swing_length] > lastHigh
lastHigh := high[swing_length]
timeHigh := bar_index
line.delete(li)
li := f_drawLine()
li
if f_isMin(swing_length) and low[swing_length] < lastHigh
lastLow := low[swing_length]
timeLow := bar_index
dirUp := true
li := f_drawLine()
if f_isMax(swing_length) and high[swing_length] > lastLow
lastHigh := high[swing_length]
timeHigh := bar_index
dirUp := false
li := f_drawLine()
li
// if barstate.islast
// label.new(x = bar_index + 10, y = close[1], text =
str.tostring( array.size(current_supply_poi) ))
// label.new(x = bar_index + 20, y = close[1], text =
str.tostring( box.get_bottom( array.get(current_supply_box, 0))))
// label.new(x = bar_index + 30, y = close[1], text =
str.tostring( box.get_bottom( array.get(current_supply_box, 1))))
// label.new(x = bar_index + 40, y = close[1], text =
str.tostring( box.get_bottom( array.get(current_supply_box, 2))))
// label.new(x = bar_index + 50, y = close[1], text =
str.tostring( box.get_bottom( array.get(current_supply_box, 3))))
// label.new(x = bar_index + 60, y = close[1], text =
str.tostring( box.get_bottom( array.get(current_supply_box, 4))))

// VWAP
// showVWAP = input(true, "on/off VWAP")
// Input options
averageData = input.source(close, title="Average Data Source")
// Calculate the volume-weighted average price and its 'noise' bands
vwapData = ta.vwap(averageData)
// Plot the average and its band
plot(showVWAP ? vwapData : na, color=color.red, title="VWAP",style =
plot.style_circles)
// EMA

//Open Range Breakout


// showORB = input(true, "on/off Open Range Breakout")
inputMax = input(15, title='ORB total time (minutes)')
sess = input.session('0915-0930', title='Session Time')
t = time(timeframe.period, sess + ':1234567')
hide = timeframe.isintraday and timeframe.multiplier <= inputMax

is_newbar_(res) =>
ta.change(time(res)) != 0
in_session = not na(t)
is_first = in_session and not in_session[1]

orb_high = float(na)
orb_low = float(na)

if is_first
orb_high := high
orb_low := low
orb_low
else
orb_high := orb_high[1]
orb_low := orb_low[1]
orb_low
if high > orb_high and in_session
orb_high := high
orb_high
if low < orb_low and in_session
orb_low := low
orb_low

plot(showORB ? orb_high : na, style=plot.style_line, color=orb_high[1] !=


orb_high ? na : color.green, title='ORB High', linewidth=2)
plot(showORB ? orb_low : na, style=plot.style_line, color=orb_low[1] != orb_low ?
na : color.red, title='ORB Low', linewidth=2)

//Volume Profile

//.....................................................//

f_drawLabelX(_x, _y, _text, _xloc, _yloc, _color, _style, _textcolor, _size,


_textalign, _tooltip) =>
var id = label.new(_x, _y, _text, _xloc, _yloc, _color, _style, _textcolor,
_size, _textalign, _tooltip)
label.set_xy(id, _x, _y)
label.set_text(id, _text)
label.set_tooltip(id, _tooltip)
label.set_textcolor(id, _textcolor)

// Functions
-----------------------------------------------------------------------------------
//
//
-----------------------------------------------------------------------------------
----------- //

//
-----------------------------------------------------------------------------------
----------- //
// Volume Profile (Price by Volume) / Volume Histogram
------------------------------------------ //

group_volume_profile = 'Volume Profile / Price by Volume'


tooltip_volume_profile = 'Volume Profile (also known as Price by Volume) is an
charting study that displays trading activity over a specified time period at
specific price levels'

// volumeProfile = input.bool(true, 'Volume Profile', group =


group_volume_profile, tooltip = tooltip_volume_profile)
lookbackLength = input.int(150, 'Lookback Length', minval = 10, maxval = 5000,
step = 10 , group = group_volume_profile)
profileLevels = input.int(100, 'Number of Rows' , minval = 10, maxval = 150 ,
step = 1 , group = group_volume_profile)
profileDisplay = input.string('Up/Down', 'Volume', options = ['Up/Down',
'Total'], group = group_volume_profile)
upVolumeColor = color.new(#1592e6, 30)
downVolumeColor = color.new(#fbc123, 30)
totalVolumeColor = color.new(#801922, 30)
backgroundColor = color.new(#2962ff, 95)
pointOfControl = input.bool(true, 'Show Point of Control', inline='PoC', group =
group_volume_profile)
pocColor = color.new(#ff0000, 0)
bullBearStr = input.bool(true, 'Show Bull/Bear Volume Strength',
inline='BB' , group = group_volume_profile)
bbStrUpColor = color.new(#26a69a, 30)
bbStrDownColor = color.new(#ef5350, 30)
priceLevels = input.bool(false, 'Show Price Levels'
, group = group_volume_profile)
profilePlacement = input.string('Right', 'Placment', options = ['Right', 'Left']
, group = group_volume_profile)
profileWidth = input.int(30, 'Profile Width', minval = 21, maxval = 150
, group = group_volume_profile)
horizontalOffset = input.int(10, 'Horizontal Offset', minval = 0 , maxval = 50
, group = group_volume_profile)

group_volume = 'Volume Histogram'


tooltip_volume = 'The Volume indicator is used to measure how much of a given
financial asset has traded in a specific period of time'
// volumeHistogram = input.bool(true, 'Volume Histogram'
, group = group_volume, tooltip = tooltip_volume)
volumePlacement = input.string('Top', 'Placment', options = ['Top', 'Bottom'],
inline='VOL' , group = group_volume)
volumeHistHight = 11 - input.int(8, 'Hight' , minval = 1, maxval = 10 ,
inline='VOL' , group = group_volume)
volumeMA = input.bool(true, 'Volume MA, Length' ,
inline='vol2', group = group_volume)
volumeMALength = input.int(21, '', minval = 1 ,
inline='vol2', group = group_volume)
volumeUpColor = color.new(#26a69a, 30)
volumeDownColor = color.new(#ef5350, 30)
volumeMAColor = color.new(#2962ff, 0)
volumeStorageT = array.new_float(profileLevels + 1, 0.)
volumeStorageB = array.new_float(profileLevels + 1, 0.)
var a_profile = array.new_box()
var a_histogram = array.new_line()
priceHighest = ta.highest(high, lookbackLength)
priceLowest = ta.lowest (low , lookbackLength)
priceStep = (priceHighest - priceLowest) / profileLevels
priceChangeRate = (priceHighest - priceLowest) / priceHighest
barPriceLow = low
barPriceHigh = high
bullCandle = close > open
nzVolume = nz(volume)
volumeHighest = ta.highest(nzVolume, lookbackLength)
volumeMARate = nzVolume/ta.sma(nzVolume, volumeMALength)

if barstate.islast and nzVolume and volumeProfile


if array.size(a_profile) > 0
for i = 1 to array.size(a_profile)
box.delete(array.shift(a_profile))

if array.size(a_histogram) > 0
for i = 1 to array.size(a_histogram)
line.delete(array.shift(a_histogram))

if priceLevels
f_drawLabelX(bar_index + (profilePlacement == 'Right' ? profileWidth +
horizontalOffset : 0), priceHighest, str.tostring(priceHighest, format.mintick),
xloc.bar_index, yloc.price, color.new(upVolumeColor , 89), profilePlacement ==
'Left' and volumePlacement == 'Top' ? label.style_label_left :
label.style_label_down, upVolumeColor , size.normal, text.align_left, 'Profile
High - during last ' + str.tostring(lookbackLength) + ' bars\n %' +
str.tostring((priceHighest - priceLowest) / priceLowest * 100, '#.##') + ' higher
than the Profile Low')
f_drawLabelX(bar_index + (profilePlacement == 'Right' ? profileWidth +
horizontalOffset : 0), priceLowest , str.tostring(priceLowest , format.mintick),
xloc.bar_index, yloc.price, color.new(downVolumeColor, 89), profilePlacement ==
'Left' and volumePlacement == 'Bottom' ? label.style_label_left :
label.style_label_up , downVolumeColor, size.normal, text.align_left, 'Profile Low
- during last ' + str.tostring(lookbackLength) + ' bars\n %' +
str.tostring((priceHighest - priceLowest) / priceHighest * 100, '#.##') + ' lower
than the Profile High')

for barIndex = 0 to lookbackLength - 1


level = 0
for priceLevel = priceLowest to priceHighest by priceStep
if barPriceHigh[barIndex] >= priceLevel and barPriceLow[barIndex] <
priceLevel + priceStep
array.set(volumeStorageT, level, array.get(volumeStorageT, level) +
nzVolume[barIndex] * ((barPriceHigh[barIndex] - barPriceLow[barIndex]) == 0 ? 1 :
priceStep / (barPriceHigh[barIndex] - barPriceLow[barIndex])) )

if bullCandle[barIndex] and (profileDisplay == 'Up/Down' or


bullBearStr)
array.set(volumeStorageB, level, array.get(volumeStorageB,
level) + nzVolume[barIndex] * ((barPriceHigh[barIndex] - barPriceLow[barIndex]) ==
0 ? 1 : priceStep / (barPriceHigh[barIndex] - barPriceLow[barIndex])) )
level += 1

if volumeHistogram and array.size(a_histogram) < 500


array.push(a_histogram, line.new(bar_index[barIndex], volumePlacement
== 'Top' ? priceHighest * (1 + priceChangeRate * .05) : priceLowest * (1 -
priceChangeRate * .05) , bar_index[barIndex], (volumePlacement == 'Top' ?
priceHighest * (1 + priceChangeRate * .05) : priceLowest * (1 - priceChangeRate
* .05)) * (1 + ( volumePlacement == 'Top' ? 1 : -1) * nzVolume[barIndex] /
volumeHighest * priceChangeRate / volumeHistHight), xloc.bar_index, extend.none,
bullCandle[barIndex] ? volumeUpColor : volumeDownColor, line.style_solid, 2))

if volumeMA
array.push(a_histogram, line.new(bar_index[barIndex],
(volumePlacement == 'Top' ? priceHighest * (1 + priceChangeRate * .05) :
priceLowest * (1 - priceChangeRate * .05)) * (1 + (volumePlacement == 'Top' ? 1 :
-1) * nzVolume[barIndex] / volumeHighest * priceChangeRate / volumeHistHight /
volumeMARate[barIndex]), bar_index[barIndex + 1], (volumePlacement == 'Top' ?
priceHighest * (1 + priceChangeRate * .05) : priceLowest * (1 - priceChangeRate
* .05)) * (1 + (volumePlacement == 'Top' ? 1 : -1) * nzVolume[barIndex + 1] /
volumeHighest * priceChangeRate / volumeHistHight / volumeMARate[barIndex + 1]),
xloc.bar_index, extend.none, volumeMAColor, line.style_solid, 2))

array.push(a_profile, box.new(bar_index - lookbackLength + 1, priceLowest,


bar_index + (profilePlacement == 'Right' ? profileWidth + horizontalOffset : 0),
priceHighest, backgroundColor, 1, line.style_dotted, bgcolor = backgroundColor ))

if pointOfControl
array.push(a_profile, box.new(bar_index - lookbackLength + 1, priceLowest +
(array.indexof(volumeStorageT, array.max(volumeStorageT)) + .40) * priceStep,
bar_index + (profilePlacement == 'Right' ? profileWidth : 0), priceLowest +
(array.indexof(volumeStorageT, array.max(volumeStorageT)) + .60) * priceStep,
pocColor, bgcolor = pocColor ))

if priceLevels
f_drawLabelX(bar_index + (profilePlacement == 'Right' ?
horizontalOffset + 5 : 7), priceLowest + (array.indexof(volumeStorageT,
array.max(volumeStorageT)) + .5) * priceStep, str.tostring(priceLowest +
(array.indexof(volumeStorageT, array.max(volumeStorageT)) + .5) * priceStep,
format.mintick), xloc.bar_index, yloc.price, color.new(pocColor, 89),
(profilePlacement == 'Right' ? label.style_label_up : label.style_label_left),
color.new(pocColor, 0), size.normal, text.align_left, 'Point Of Control Price')

for level = 0 to profileLevels - 1


levelColor = profileDisplay == 'Up/Down' ? downVolumeColor :
totalVolumeColor
startBoxIndex = profilePlacement == 'Right' ? bar_index + profileWidth +
horizontalOffset - int(array.get(volumeStorageT, level) / array.max(volumeStorageT)
* (profileWidth - 9)) : bar_index - lookbackLength + 1
endBoxIndex = profilePlacement == 'Right' ? bar_index + profileWidth +
horizontalOffset: startBoxIndex + int( array.get(volumeStorageT, level) /
array.max(volumeStorageT) * (profileWidth - 9))
array.push(a_profile, box.new(startBoxIndex, priceLowest + (level + 0.1) *
priceStep, endBoxIndex, priceLowest + (level + 0.9) * priceStep, levelColor,
bgcolor = levelColor ))

if profileDisplay == 'Up/Down'
startBoxIndex := profilePlacement == 'Right' ? bar_index + profileWidth
+ horizontalOffset - int(array.get(volumeStorageB, level) /
array.max(volumeStorageB) * (profileWidth - 9) / 2) : bar_index - lookbackLength +
1
endBoxIndex := profilePlacement == 'Right' ? bar_index + profileWidth
+ horizontalOffset: startBoxIndex + int( array.get(volumeStorageB, level) /
array.max(volumeStorageB) * (profileWidth - 9) / 2)
array.push(a_profile, box.new(startBoxIndex, priceLowest + (level +
0.1) * priceStep, endBoxIndex, priceLowest + (level + 0.9) * priceStep,
upVolumeColor, bgcolor = upVolumeColor ))

if bullBearStr
bullBearPower = 2 * array.get(volumeStorageB, level) -
array.get(volumeStorageT, level)
startBoxIndex := profilePlacement == 'Right' ? bar_index + profileWidth
+ 1 + horizontalOffset + (bullBearPower > 0 ? 1 : -1) * int(bullBearPower /
array.max(volumeStorageT) * (profileWidth - 9) * 1.75) : bar_index - lookbackLength
endBoxIndex := profilePlacement == 'Right' ? bar_index + profileWidth
+ 1 + horizontalOffset: startBoxIndex + (bullBearPower > 0 ? -1 : 1) *
int(bullBearPower / array.max(volumeStorageT) * (profileWidth - 9) * 1.75 )
array.push(a_profile, box.new(startBoxIndex, priceLowest + (level +
0.1) * priceStep, endBoxIndex, priceLowest + (level + 0.9) * priceStep,
bullBearPower > 0 ? bbStrUpColor : bbStrDownColor, bgcolor = bullBearPower > 0 ?
bbStrUpColor : bbStrDownColor ))

// 8888888888 8888888b. 8888888888 8888888888 d8888 888 .d8888b.


.d88888b. As you
// 888 888 Y88b 888 888 d88888 888 d88P Y88b
d88P" "Y88b Can see
// 888 888 888 888 888 d88P888 888 888 888
888 888 Are all
// 8888888 888 d88P 8888888 8888888 d88P 888 888 888
888 888 .d8888b Basic free
// 888 8888888P" 888 888 d88P 888 888 888 88888
888 888 88K tradingview
// 888 888 T88b 888 888 d88P 888 888 888 888
888 888 "Y8888b. indicators
// 888 888 T88b 888 888 d8888888888 888 Y88b d88P
Y88b. .d88P X88 repackaged
// 888 888 T88b 8888888888 8888888888 d88P 888 88888888 "Y8888P88
"Y88888P" 88888P' into one
//
// FAQ
//
// Why?
// I want you to see what you are willing to pay hundereds of dollars a month

// Has the code been leaked/hacked?


// No, this code has been created only using common sense and public information
from the internet

// What's the accuracy I can expect from this version of the indicator?
// I'd say it's about 95% the same as the one you would pay

// The indicator needs to be updated?


// Write me a private message on TradingView (Nick42_for_win)

// Can I suggest an indicator to get a FREE ALGOs version?


// Write me a private message on TradingView (Nick42_for_win)

// Do you get any monetary return from this project?


// Nope, 0$
// Enjoy ;)

//------------------- EzAlgo SR | https://www.ezalgo.co ----------------------//


// Get user input
// enableSR = input(true, "SR On/Off", group="SR")
colorSup = input(#00DBFF, "Support Color", group="SR")
colorRes = input(#E91E63, "Resistance Color", group="SR")
strengthSR = input.int(2, "S/R Strength", 1, group="SR")
lineStyle = input.string("Dotted", "Line Style", ["Solid", "Dotted", "Dashed"],
group="SR")
lineWidth = input.int(2, "S/R Line Width", 1, group="SR")
useZones = input(true, "Zones On/Off", group="SR")
useHLZones = input(true, "High Low Zones On/Off", group="SR")
zoneWidth = input.int(2, "Zone Width %", 0, tooltip="it's calculated using % of
the distance between highest/lowest in last 300 bars", group="SR")
expandSR = input(true, "Expand SR")
// Functions
percWidth(len, perc) => (ta.highest(len) - ta.lowest(len)) * perc / 100
// Get components
rb = 10
prd = 284
ChannelW = 10
label_loc = 55
style_ = lineStyle == "Solid" ? line.style_solid : lineStyle == "Dotted" ?
line.style_dotted : line.style_dashed
ph = ta.pivothigh(rb, rb)
pl = ta.pivotlow (rb, rb)
sr_levels = array.new_float(21, na)
prdhighest = ta.highest(prd)
prdlowest = ta.lowest(prd)
cwidth = percWidth(prd, ChannelW)
zonePerc = percWidth(300, zoneWidth)
aas = array.new_bool(41, true)
u1 = 0.0, u1 := nz(u1[1])
d1 = 0.0, d1 := nz(d1[1])
highestph = 0.0, highestph := highestph[1]
lowestpl = 0.0, lowestpl := lowestpl[1]
var sr_levs = array.new_float(21, na)
label hlabel = na, label.delete(hlabel[1])
label llabel = na, label.delete(llabel[1])
var sr_lines = array.new_line(21, na)
var sr_linesH = array.new_line(21, na)
var sr_linesL = array.new_line(21, na)
var sr_linesF = array.new_linefill(21, na)
var sr_labels = array.new_label(21, na)
if ph or pl
for x = 0 to array.size(sr_levels) - 1
array.set(sr_levels, x, na)
highestph := prdlowest
lowestpl := prdhighest
countpp = 0
for x = 0 to prd
if na(close[x])
break
if not na(ph[x]) or not na(pl[x])
highestph := math.max(highestph, nz(ph[x], prdlowest), nz(pl[x],
prdlowest))
lowestpl := math.min(lowestpl, nz(ph[x], prdhighest), nz(pl[x],
prdhighest))
countpp += 1
if countpp > 40
break
if array.get(aas, countpp)
upl = (ph[x] ? high[x + rb] : low[x + rb]) + cwidth
dnl = (ph[x] ? high[x + rb] : low[x + rb]) - cwidth
u1 := countpp == 1 ? upl : u1
d1 := countpp == 1 ? dnl : d1
tmp = array.new_bool(41, true)
cnt = 0
tpoint = 0
for xx = 0 to prd
if na(close[xx])
break
if not na(ph[xx]) or not na(pl[xx])
chg = false
cnt += 1
if cnt > 40
break
if array.get(aas, cnt)
if not na(ph[xx])
if high[xx + rb] <= upl and high[xx + rb] >= dnl
tpoint += 1
chg := true
if not na(pl[xx])
if low[xx + rb] <= upl and low[xx + rb] >= dnl
tpoint += 1
chg := true
if chg and cnt < 41
array.set(tmp, cnt, false)
if tpoint >= strengthSR
for g = 0 to 40 by 1
if not array.get(tmp, g)
array.set(aas, g, false)
if ph[x] and countpp < 21
array.set(sr_levels, countpp, high[x + rb])
if pl[x] and countpp < 21
array.set(sr_levels, countpp, low[x + rb])
// Plot
var line highest_ = na, line.delete(highest_)
var line lowest_ = na, line.delete(lowest_)
var line highest_fill1 = na, line.delete(highest_fill1)
var line highest_fill2 = na, line.delete(highest_fill2)
var line lowest_fill1 = na, line.delete(lowest_fill1)
var line lowest_fill2 = na, line.delete(lowest_fill2)
hi_col = close >= highestph ? colorSup : colorRes
lo_col = close >= lowestpl ? colorSup : colorRes
if enableSR
highest_ := line.new(bar_index - 311, highestph, bar_index, highestph,
xloc.bar_index, expandSR ? extend.both : extend.right, hi_col, style_, lineWidth)
lowest_ := line.new(bar_index - 311, lowestpl , bar_index, lowestpl ,
xloc.bar_index, expandSR ? extend.both : extend.right, lo_col, style_, lineWidth)
if useHLZones
highest_fill1 := line.new(bar_index - 311, highestph + zonePerc, bar_index,
highestph + zonePerc, xloc.bar_index, expandSR ? extend.both : extend.right, na)
highest_fill2 := line.new(bar_index - 311, highestph - zonePerc, bar_index,
highestph - zonePerc, xloc.bar_index, expandSR ? extend.both : extend.right, na)
lowest_fill1 := line.new(bar_index - 311, lowestpl + zonePerc , bar_index,
lowestpl + zonePerc , xloc.bar_index, expandSR ? extend.both : extend.right, na)
lowest_fill2 := line.new(bar_index - 311, lowestpl - zonePerc , bar_index,
lowestpl - zonePerc , xloc.bar_index, expandSR ? extend.both : extend.right, na)
linefill.new(highest_fill1, highest_fill2, color.new(hi_col, 80))
linefill.new(lowest_fill1 , lowest_fill2 , color.new(lo_col, 80))
if ph or pl
for x = 0 to array.size(sr_lines) - 1
array.set(sr_levs, x, array.get(sr_levels, x))
for x = 0 to array.size(sr_lines) - 1
line.delete(array.get(sr_lines, x))
line.delete(array.get(sr_linesH, x))
line.delete(array.get(sr_linesL, x))
linefill.delete(array.get(sr_linesF, x))
if array.get(sr_levs, x) and enableSR
line_col = close >= array.get(sr_levs, x) ? colorSup : colorRes
array.set(sr_lines, x, line.new(bar_index - 355, array.get(sr_levs, x),
bar_index, array.get(sr_levs, x), xloc.bar_index, expandSR ? extend.both :
extend.right, line_col, style_, lineWidth))
if useZones
array.set(sr_linesH, x, line.new(bar_index - 355, array.get(sr_levs, x)
+ zonePerc, bar_index, array.get(sr_levs, x) + zonePerc, xloc.bar_index, expandSR ?
extend.both : extend.right, na))
array.set(sr_linesL, x, line.new(bar_index - 355, array.get(sr_levs, x)
- zonePerc, bar_index, array.get(sr_levs, x) - zonePerc, xloc.bar_index, expandSR ?
extend.both : extend.right, na))
array.set(sr_linesF, x, linefill.new(array.get(sr_linesH, x),
array.get(sr_linesL, x), color.new(line_col, 80)))
for x = 0 to array.size(sr_labels) - 1
label.delete(array.get(sr_labels, x))
if array.get(sr_levs, x) and enableSR
lab_loc = close >= array.get(sr_levs, x) ? label.style_label_up :
label.style_label_down
lab_col = close >= array.get(sr_levs, x) ? colorSup : colorRes
array.set(sr_labels, x, label.new(bar_index + label_loc, array.get(sr_levs,
x), str.tostring(math.round_to_mintick(array.get(sr_levs, x))), color=lab_col ,
textcolor=#000000, style=lab_loc))
hlabel := enableSR ? label.new(bar_index + label_loc +
math.round(math.sign(label_loc)) * 20, highestph, "High Level : " +
str.tostring(highestph), color=hi_col, textcolor=#000000,
style=label.style_label_down) : na
llabel := enableSR ? label.new(bar_index + label_loc +
math.round(math.sign(label_loc)) * 20, lowestpl , "Low Level : " +
str.tostring(lowestpl) , color=lo_col, textcolor=#000000,
style=label.style_label_up ) : na

//ORDER BLOCK
// box_ob = input.bool(true, "Toggle Order Block", group="ORDER BLOCK")
// box_hide_gray = input.bool(true, "Hide gray boxes", group="ORDER BLOCK")
bos_type = input.string("Close and Open", "MSB trigger", ["High and Low",
"Close and Open"], group="ORDER BLOCK")
box_sv = input.bool(true, "Plot Order Block boxes", group="ORDER BLOCK")
box_test_delay = input.int(3, "Delay to count test of Order Block box", 1,
group="ORDER BLOCK")
box_fill_delay = input.int(3, "Delay to count fill of Order Block box", 1,
group="ORDER BLOCK")
box_test_sv = input.bool(true, "Dim tested Order Block boxes", group="ORDER
BLOCK")
box_stop_sv = input.bool(true, "Stop plotting filled Order Block boxes",
group="ORDER BLOCK")

// Get components

var float[] pvh1_price = array.new_float(1000, na)


var int[] pvh1_time = array.new_int (1000, na)
var float[] pvl1_price = array.new_float(1000, na)
var int[] pvl1_time = array.new_int (1000, na)
var float[] pvh2_price = array.new_float(1000, na)
var int[] pvh2_time = array.new_int (1000, na)
var float[] pvl2_price = array.new_float(1000, na)
var int[] pvl2_time = array.new_int (1000, na)
var float htcmrll_price = na
var int htcmrll_time = na
var float ltcmrhh_price = na
var int ltcmrhh_time = na
var box[] long_boxes = array.new_box()
var box[] short_boxes = array.new_box()
var float temp_pv_0 = na
var float temp_pv_1 = na
var float temp_pv_2 = na
bool pvh = high < high[1] and high[1] > high[6]
bool pvl = low > low [1] and low [1] < low [6]
int pv1_time = bar_index[1]
float pv1_high = high[1]
float pv1_low = low [1]
float trigger_high = bos_type == "High and Low" ? high : math.max(open,
close)
float trigger_low = bos_type == "High and Low" ? low : math.min(open,
close)

// Colors
green = #00DD00, green50 = color.new(green, 50), green20 = color.new(green,
80)
red = #DD0000, red50 = color.new(red, 50), red20 = color.new(red, 80)
silver = #B2B5BE, silver50 = color.new(silver, 50), silver20 = color.new(silver,
80)
// Plots

if box_ob and barstate.isconfirmed


if pvh
array.pop(pvh1_price)
array.pop(pvh1_time)
array.unshift(pvh1_price, pv1_high)
array.unshift(pvh1_time, pv1_time)
if array.size(pvh1_price) > 6
temp_pv_0 := array.get(pvh1_price, 0)
temp_pv_1 := array.get(pvh1_price, 1)
temp_pv_2 := array.get(pvh1_price, 6)
if temp_pv_0 > temp_pv_1
for i = 0 to array.size(pvl1_time) - 1 by 1
temp_ltcmrhh_time = array.get(pvl1_time, i)
if temp_ltcmrhh_time < array.get(pvh1_time, 0)
ltcmrhh_price := array.get(pvl1_price, i)
ltcmrhh_time := temp_ltcmrhh_time
break
if temp_pv_0 < temp_pv_1 and temp_pv_1 > temp_pv_2
array.pop(pvh2_price)
array.pop(pvh2_time)
array.unshift(pvh2_price, temp_pv_1)
array.unshift(pvh2_time, array.get(pvh1_time, 1))
if pvl
array.pop(pvl1_price)
array.pop(pvl1_time)
array.unshift(pvl1_price, pv1_low)
array.unshift(pvl1_time, pv1_time)
if array.size(pvl1_price) > 6
temp_pv_0 := array.get(pvl1_price, 0)
temp_pv_1 := array.get(pvl1_price, 1)
temp_pv_2 := array.get(pvl1_price, 6)
if temp_pv_0 < temp_pv_1
for i = 0 to array.size(pvh1_time) - 1 by 1
temp_htcmrll_time = array.get(pvh1_time, i)
if temp_htcmrll_time < array.get(pvl1_time, 0)
htcmrll_price := array.get(pvh1_price, i)
htcmrll_time := temp_htcmrll_time
break
if temp_pv_0 > temp_pv_1 and temp_pv_1 < temp_pv_2
array.pop(pvl2_price)
array.pop(pvl2_time)
array.unshift(pvl2_price, temp_pv_1)
array.unshift(pvl2_time, array.get(pvl1_time, 1))
if trigger_high > htcmrll_price
if box_sv
loBox = box.new(left=array.get(pvl1_time, 0),
top=math.min(high[bar_index - array.get(pvl1_time, 0)], high[bar_index -
array.get(pvl1_time, 0) + 1]), right=bar_index, bottom=array.get(pvl1_price, 0),
bgcolor=color.rgb(0, 255, 0, 80), border_color=color.rgb(0, 255, 0, 80),
extend=extend.right)
if array.size(long_boxes) >= 25
box.delete(array.shift(long_boxes))
array.push(long_boxes, loBox)
htcmrll_price := na
htcmrll_price
if trigger_low < ltcmrhh_price
if box_sv
hiBox = box.new(left=array.get(pvh1_time, 0), top=array.get(pvh1_price,
0), right=bar_index, bottom=math.max(low[bar_index - array.get(pvh1_time, 0)],
low[bar_index - array.get(pvh1_time, 0) + 1]), bgcolor=color.rgb(255, 0, 0, 80),
border_color=color.rgb(255, 0, 0, 80), extend=extend.right)
if array.size(short_boxes) >= 25
box.delete(array.shift(short_boxes))
array.push(short_boxes, hiBox)
ltcmrhh_price := na
ltcmrhh_price
if array.size(short_boxes) > 0
for i = array.size(short_boxes) - 1 to 0 by 1
tbox = array.get(short_boxes, i)
top = box.get_top(tbox)
bottom = box.get_bottom(tbox)
if trigger_high > bottom and box.get_left(tbox) + box_test_delay <
bar_index and box_test_sv
if box_hide_gray
box.set_bgcolor(tbox, #00000000)
box.set_border_color(tbox, #00000000)
else
box.set_bgcolor(tbox, color.rgb(192, 192, 192, 80))
box.set_border_color(tbox, color.rgb(192, 192, 192, 80))
if trigger_high > top and box.get_left(tbox) + box_fill_delay <
bar_index
if box_stop_sv
box.set_right(tbox, bar_index)
box.set_extend(tbox, extend.none)
array.remove(short_boxes, i)
if array.size(long_boxes) > 0
for i = array.size(long_boxes) - 1 to 0 by 1
lbox = array.get(long_boxes, i)
top = box.get_top(lbox)
bottom = box.get_bottom(lbox)
if trigger_low < top and box.get_left(lbox) + box_test_delay <
bar_index and box_test_sv
if box_hide_gray
box.set_bgcolor(lbox, #00000000)
box.set_border_color(lbox, #00000000)
else
box.set_bgcolor(lbox, color.rgb(192, 192, 192, 80))
box.set_border_color(lbox, color.rgb(192, 192, 192, 80))
if trigger_low < bottom and box.get_left(lbox) + box_fill_delay <
bar_index
if box_stop_sv
box.set_right(lbox, bar_index)
box.set_extend(lbox, extend.none)
array.remove(long_boxes, i)

//////////////////////////////////////////////////////////////////////
// //
// REVISION HISTORY //
// v 1.0 Initial release //
// v 1.1 Added interface elements and refactored code //
// v. 1.2 Added ability to set EMA length //
// //
//////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////////
/////////////////
//
//
// This indicator is an English version of the "Mtf Supertrend Table"
//
// coded by FxTraderProAsistan. Credit goes to him. I have
//
// modified this version for my own needs, in the English language.
//
// Future enhancements will include alerts to changes in
//
// directions on the time frames specified.
//
//
//
///////////////////////////////////////////////////////////////////////////////////
/////////////////

// Choose trend calculation to use


grp1 = 'Trend Calculation'
// trendCalc = input.string(defval = "EMA", title = "Trend Mode",
options=["Supertrend", "EMA"], group = grp1)

// Statistics Table
// --------
grp2 = 'Trend Table'
// trendTable = input(true, 'Show Trend Table', group=grp2)

times1 = input.timeframe('1', 'TimeFrame - A', group=grp2, inline = "1")


showtimes1 = input.bool(true,title="Show", group = grp2, inline = "1")
times2 = input.timeframe('5', 'TimeFrame - B', group=grp2, inline = "2")
showtimes2 = input.bool(true,title="Show", group = grp2, inline = "2")
times3 = input.timeframe('15', 'TimeFrame - C', group=grp2, inline = "3")
showtimes3 = input.bool(true,title="Show", group = grp2, inline = "3")
times4 = input.timeframe('30','TimeFrame - D', group=grp2, inline = "4")
showtimes4 = input.bool(true,title="Show", group = grp2, inline = "4")
times5 = input.timeframe('60', 'TimeFrame - E', group=grp2, inline = "5")
showtimes5 = input.bool(true,title="Show", group = grp2, inline = "5")
times6 = input.timeframe('240', 'TimeFrame - F', group=grp2, inline = "6")
showtimes6 = input.bool(true,title="Show", group = grp2, inline = "6")
// showDXY = input.bool(false, title = 'Show DXY', group = grp2)

// Dashboard Settings
grp3 = 'Table Display'
dashColor = input.color(color.new(#00b2ff,0) , 'Background Color ',
group=grp3)
upColor = input.color(color.green , 'Up Trend Color ', group=grp3)
downColor = input.color(color.red , 'Down Trend Color ', group=grp3)
TablePos = input.string('Bottom Right', 'Table Position', ['Top Right', 'Top
Center', 'Middle Right', 'Bottom Left',"Bottom Right"], group=grp3)
TablePosTextCol = input.color(color.black, 'Text Color', group=grp3)

TextSize1 = input.string('Small', 'Table Font Size', ['Normal', 'Small',


'Large', 'Huge'], group=grp3)
textSize = TextSize1=='Huge' ? size.huge : TextSize1=='Normal'? size.small :
TextSize1=='Small'? size.tiny : size.normal

tabPos = TablePos == 'Top Right' ? position.top_right : TablePos == 'Bottom Left' ?


position.bottom_left : TablePos == 'Middle Right' ? position.middle_right :
TablePos == 'Bottom Right' ? position.bottom_right : TablePos == 'Top Center' ?
position.top_center : position.bottom_right
var SuperTrendTable = table.new(tabPos, 50, 50, color.new(color.black,100),
color.new(color.black,100), 1, color.new(color.black,1),1)

//------------------------
grp4 = 'SuperTrend Settings'
atrPeriod = input(10, "ATR Length", group = grp4)
factor = input.float(3.0, "Factor", step = 0.01, group = grp4)

grp5 = 'EMA Trend Settings'


fastEMA = input.int(defval = 20, title = 'Fast EMA', minval = 1, maxval = 600, step
= 1, group = grp5)
slowEMA = input.int(defval = 50, title = 'Slow EMA', minval = 1, maxval = 600, step
= 1, group = grp5)

conditionSuper = 0.0

// Super Trend Calculation


if trendCalc == 'Supertrend'
[supertrend, direction] = ta.supertrend(factor, atrPeriod)
conditionSuper := direction < 0 ? 1 : direction > 0 ? -1 : na

// EMA Calculation

is20EMAHigherThan50EMA() =>
ema20 = ta.ema(close, fastEMA)
ema50 = ta.ema(close, slowEMA)
ema20 > ema50 ? -1 : 1

if trendCalc == "EMA"
emadirection = is20EMAHigherThan50EMA()
conditionSuper := emadirection < 0 ? 1 : emadirection > 0 ? -1 : na

functionSuper()=>
conditionSuper

functionSuperColor(x) => x==" Up " ? upColor : x== "Down" ? downColor : na

// Function to convert minutes to hours if divisible by 60


minutesToHours(timeframe) =>

// Check if the timeframe is only in minutes


containsLetters = str.match(timeframe, "[a-zA-Z]")

if na(containsLetters)
if str.tonumber(timeframe) % 60 == 0
result = "H" + str.tostring(str.tonumber(timeframe) / 60)
else
result = "M" + str.tostring(str.tonumber(timeframe))
else
result = containsLetters

fTable(colNumber,times,symbol )=>

// Depending upon user input, use the appropriate calculation for newSuper
(Supertrend)
newSuper = request.security(symbol, times, functionSuper())
newSuperDirection = newSuper == 1 ? " Up " : newSuper == -1 ? "Down" : na
superColor=functionSuperColor(newSuperDirection)

if trendTable
table.cell(SuperTrendTable, 0, 0, "TimeFrame" ,
text_color=TablePosTextCol, text_size=textSize, bgcolor=dashColor)
table.cell(SuperTrendTable, 0, 1, syminfo.ticker,
text_color=TablePosTextCol, text_size=textSize, bgcolor=dashColor)

tfDes = times==''? timeframe.period : minutesToHours(times)

if symbol != "DXY"
table.cell(SuperTrendTable,colNumber, 0, tfDes ,
text_color=TablePosTextCol, text_size=textSize, bgcolor=dashColor)
table.cell(SuperTrendTable,colNumber, 1, newSuperDirection,
text_color=TablePosTextCol, text_size=textSize, bgcolor=superColor, tooltip =
str.tostring(symbol))
if showDXY and symbol == "DXY"
table.cell(SuperTrendTable, 0, 3, "DXY" ,
text_color=TablePosTextCol, text_size=textSize, bgcolor=dashColor)
table.cell(SuperTrendTable,colNumber, 3, newSuperDirection,
text_color=TablePosTextCol, text_size=textSize, bgcolor=superColor, tooltip =
str.tostring(symbol))

symbol = syminfo.tickerid
dxy = syminfo.ticker("TVC:DXY")
if showtimes1
fTable(1,times1, symbol)
if showtimes2
fTable(2,times2, symbol)
if showtimes3
fTable(3,times3, symbol)
if showtimes4
fTable(4,times4, symbol)
if showtimes5
fTable(5,times5, symbol)
if showtimes6
fTable(6,times6, symbol)

// Calculate DXY Special Selection


if showDXY
if showtimes1
fTable(1,times1, dxy)
if showtimes2
fTable(2,times2, dxy)
if showtimes3
fTable(3,times3, dxy)
if showtimes4
fTable(4,times4, dxy)
if showtimes5
fTable(5,times5, dxy)
if showtimes6
fTable(6,times6, dxy)
// Trendlines

// showTL = input(true, 'TrendLine', group = 'TrendLines')

//general
f_barssince(_cond, _count) =>
_barssince = bar_index - ta.valuewhen(_cond, bar_index, _count)
_barssince

barssince(_cond, _count) => int(math.max(1, nz(f_barssince(_cond, _count))))


f_vw(cond, expr, count) => ta.valuewhen(cond, expr, count)

tostring(x, y)=> x + str.tostring(y)

var int dec = str.length(str.tostring(syminfo.mintick))-2

// Trendlines
gr5 = 'Trendlines'
showPriceTl = false
newestTL = true
newestBreak = true
// periodlen = input.string('Adaptive', 'Trendline Term', ['Long Term', 'Short
Term','Adaptive'])
period = (periodlen == 'Adaptive' ? 30 : periodlen == 'Long Term' ? 40 : periodlen
== 'Short Term' ? 20 : 0)
//period = input(30, 'Trendline Period')
srcI = input.string('Wick', 'TrendLine Source', ['Close Body', 'Wick'])
srcL = srcI=='Wick'? low : close
srcH = srcI=='Wick'? high : close
lStyleI = input.string('Solid', 'TrendLine Style', ['Solid', 'Dashed',
'Dotted'])
y2_mult = 1
lStyle = lStyleI=='Solid'? line.style_solid : lStyleI=='Dashed'?
line.style_dashed : line.style_dotted
lWidth = input(1, 'TrendLine Width')
lColor = color.blue
supTextCol = color.red
resTextCol = color.blue

truncate(number) =>
factor = math.pow(10, dec)
int(number * factor) / factor

EndTime = timestamp('19 Jan 2022 00:00 +0000')


inDateRange = time<=EndTime

fVwSeries (x, xVal, xBar)=>


x0 = truncate(ta.valuewhen(x, xVal, 0))
x1 = truncate(ta.valuewhen(x, xVal, 1))
x2 = truncate(ta.valuewhen(x, xVal, 2))
x0Bar = ta.valuewhen(x, xBar, 0) - f_barssince(x, 0)
x1Bar = ta.valuewhen(x, xBar, 1) - f_barssince(x, 1)
x2Bar = ta.valuewhen(x, xBar, 2) - f_barssince(x, 2)

[x0, x1, x2, x0Bar, x1Bar, x2Bar]

fTst(x, y)=> x + str.tostring(y)


phFound = ta.pivothigh(srcH, period, period)
plFound = ta.pivotlow (srcL, period, period)
phVal = ta.valuewhen(phFound, srcH[period], 0)
plVal = ta.valuewhen(plFound, srcL[period], 0)
phVal1 = ta.valuewhen(phFound, srcH[period], 1)
plVal1 = ta.valuewhen(plFound, srcL[period], 1)

a_bar_time = time - time[1]


noneCol = color.new(color.red, 100)

fGetPriceTl(slope_, x2_, y2_) =>


current_price = y2_ + (slope_/(x2_ - time))
current_price

f_trendline(cond_, y1Val_, x1Bar_, y2Val_, x2Bar_, color_, tlPriceText, textCol) =>

x1 = ta.valuewhen(cond_, time[x1Bar_], 0)
x2 = ta.valuewhen(cond_, time[x2Bar_], 0)
y1 = ta.valuewhen(cond_, y1Val_, 0)
y2 = ta.valuewhen(cond_, y2Val_, 0)
slope_ = ta.valuewhen(cond_, (y2-y1)/(x2-x1), 0)

currentPrice = truncate(y2 + (time-x2)*slope_)


var label tlPrice = na

if close and newestTL


a_trendline = line.new (x1, y1, time, currentPrice, xloc.bar_time,
color=lColor, style=lStyle, width=lWidth)
line.delete (a_trendline[1])

a_trendline

newY2 = x2 + (y2_mult * a_bar_time * 25)

if cond_ and not newestTL


a_trendline = line.new(x1, y1, newY2, currentPrice, xloc.bar_time,
color=lColor, style=lStyle, width=lWidth)
a_trendline
if showPriceTl
tlPrice := label.new(bar_index+10, currentPrice, fTst(tlPriceText,
currentPrice), color=noneCol, style=label.style_label_left, textcolor=textCol)
label.delete(tlPrice[1])

currentPrice

newUp = phFound and phVal<phVal1 and showTL


newLo = plFound and plVal>plVal1 and showTL
upperTl = f_trendline(newUp, phVal1, f_barssince(phFound,1)+period, phVal,
f_barssince(phFound,0)+period,color.black, 'Upper = ', resTextCol)
lowerTl = f_trendline(newLo, plVal1, f_barssince(plFound,1)+period, plVal,
f_barssince(plFound,0)+period,color.black, 'Lower = ', supTextCol)

highestSince = ta.highest(srcH, barssince(phFound and phVal<phVal1 and


showTL,0))
lowestSince = ta.lowest (srcL, barssince(plFound and plVal>plVal1 and
showTL,0))
breakUpper = srcH[1]<upperTl[1] and srcH>upperTl
breakLower = srcL[1]>lowerTl[1] and srcL<lowerTl
// MTF S/R //
group = "MULTI-TIMEFRAME S/R AREA (Beta Feature)"
// showSR = input.bool(true, title = "", inline = "01", group=group)
// timef = input.timeframe("", "", inline = "01", group=group)
levels = input.int(7 , "Levels", inline = "01", group = group)
linewidth = input.int(1, "Width", inline = "02", group = group) * 20
supportcolor = #0089774b
resistancecolor = #b228344b
labelon = input.string("On", "Label", ["On", "Off"], inline = "03",
group = group)
labelsize = input.string("Default", "Size", ["Small", "Default",
"Large"], inline = "03", group = group)
labelcol = input.color(#787b86, "", inline = "03", group = group)
labelloc = input.int(10, "Offset", inline = "04", group = group) + 30
showtimef = input.bool(true, "Show Timeframe", inline = "04", group =
group)
showtprice = input.bool(false, "Show Price", inline = "04", group = group)

// get data on ticker based on chosen timeframe


src_c = request.security(syminfo.tickerid,timef,close, gaps = barmerge.gaps_off,
lookahead = barmerge.lookahead_off)
src_o = request.security(syminfo.tickerid,timef,open, gaps = barmerge.gaps_off,
lookahead = barmerge.lookahead_off)
f_resInMinutes() =>
_resInMinutes = 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)
_resInMinutes
f_timefResInMinutes(_res) =>
request.security(syminfo.tickerid, _res, f_resInMinutes())
f_timefIsIntraday(_res) =>
[intraday, daily, weekly, monthly] = request.security(syminfo.tickerid, _res,
[timeframe.isintraday, timeframe.isdaily, timeframe.isweekly, timeframe.ismonthly])
check = intraday ? "Intraday" : daily ? "Daily" : weekly ? "Weekly" : monthly ?
"Monthly" : "Error"
check
mtimef_multiplier = int (f_timefResInMinutes(timef) / f_resInMinutes())
prd_ = 10
maxnumpp = 284
ChannelW_ = 10
min_strength = 2
prd_ := prd_ * mtimef_multiplier
float src1 = math.max(src_c, src_o)
float src2 = math.min(src_c, src_o)
float src3 = math.max(close, open)
float src4 = math.min(close, open)
float phsa = ta.pivothigh(src1, prd_, prd_)
float plsa = ta.pivotlow(src2, prd_, prd_)
Lstyle = line.style_solid
timef_res = f_timefIsIntraday(timef)
timef_text = str.tostring(timef)
if str.tostring(timef) == ""
timef_text := na(timeframe.multiplier / 60) ? timeframe.period :
timeframe.multiplier < 60 ? timeframe.period + " M |" :
str.tostring(timeframe.multiplier / 60) + " H |"
else if timef_res == "Intraday"
timef_text := na(str.tonumber(timef) / 60) ? str.tostring(timef) :
str.tonumber(timef) < 60 ? str.tostring(timef) + " M |" :
str.tostring(str.tonumber(timef) / 60) + " H |"
else
timef_text := str.tostring(timef)
//calculate maximum S/R channel zone width
prdhighest_ = request.security(syminfo.tickerid, timef, ta.highest(300))
prdlowest_ = request.security(syminfo.tickerid, timef, ta.lowest(300))
cwidth_ = (prdhighest_ - prdlowest_) * ChannelW_ / 100
var pivotvals = array.new_float(0)
if phsa or plsa
array.unshift(pivotvals, phsa ? phsa : plsa)
if array.size(pivotvals) > maxnumpp // limit the array size
array.pop(pivotvals)
get_sr_vals(ind) =>
float lo = array.get(pivotvals, ind)
float hi = lo
int numpp = 0
for y = 0 to array.size(pivotvals) - 1 by 1
float cpp = array.get(pivotvals, y)
float wdth = cpp <= lo ? hi - cpp : cpp - lo
if wdth <= cwidth_ // fits the max channel width?
lo := cpp <= lo ? cpp : lo
hi := cpp > lo ? cpp : hi
numpp += 1
numpp
[hi, lo, numpp]
var sr_up_level = array.new_float(0)
var sr_dn_level = array.new_float(0)
sr_strength = array.new_float(0)

find_loc(strength) =>
ret = array.size(sr_strength)
for i = ret > 0 ? array.size(sr_strength) - 1 : na to 0 by 1
if strength <= array.get(sr_strength, i)
break
ret := i
ret
ret

check_sr(hi, lo, strength) =>


ret = true
for i = 0 to array.size(sr_up_level) > 0 ? array.size(sr_up_level) - 1 : na by
1
//included?
if array.get(sr_up_level, i) >= lo and array.get(sr_up_level, i) <= hi or
array.get(sr_dn_level, i) >= lo and array.get(sr_dn_level, i) <= hi
if strength >= array.get(sr_strength, i)
array.remove(sr_strength, i)
array.remove(sr_up_level, i)
array.remove(sr_dn_level, i)
ret
else
ret := false
ret
break
ret

var sr_lines_ = array.new_line(11, na)


var sr_labels_ = array.new_label(11, na)
var timef_labels = array.new_label(11, na)

if phsa or plsa
//because of new calculation, remove old S/R levels
array.clear(sr_up_level)
array.clear(sr_dn_level)
array.clear(sr_strength)
//find S/R zones
for x = 0 to array.size(pivotvals) - 1 by 1
[hi, lo, strength] = get_sr_vals(x)
if check_sr(hi, lo, strength)
loc = find_loc(strength)
// if strength is in first levels sr then insert it to the arrays
if loc < levels and strength >= min_strength
array.insert(sr_strength, loc, strength)
array.insert(sr_up_level, loc, hi)
array.insert(sr_dn_level, loc, lo)
// keep size of the arrays = 5
if array.size(sr_strength) > levels
array.pop(sr_strength)
array.pop(sr_up_level)
array.pop(sr_dn_level)

for x = 1 to 10 by 1
line.delete(array.get(sr_lines_, x))
label.delete(array.get(sr_labels_, x))
label.delete(array.get(timef_labels, x))

for x = 0 to array.size(sr_up_level) > 0 ? array.size(sr_up_level) - 1 : na by


1
float mid = math.round_to_mintick((array.get(sr_up_level, x) +
array.get(sr_dn_level, x)) / 2)
if showSR
array.set(sr_lines_, x + 1, line.new(x1=bar_index, y1=mid, x2=bar_index
- 1, y2=mid, extend=extend.both, color=mid >= close ? resistancecolor :
supportcolor, style=Lstyle, width=linewidth))
if labelon == "On"
size = labelsize == "Small" ? size.small : labelsize == "Default" ?
size.normal : size.large
array.set(sr_labels_, x + 1, label.new(x=bar_index + labelloc,
y=mid, text=(showtimef ? timef_text : na) + (showtprice ? (" " + str.tostring(mid))
: na), color=mid >= close ? #ff525200 : #00e67700, textcolor=labelcol,
size = size, style=label.style_label_left))

f_crossed_over() =>
ret = false
for x = 0 to array.size(sr_up_level) > 0 ? array.size(sr_up_level) - 1 : na by
1
float mid = math.round_to_mintick((array.get(sr_up_level, x) +
array.get(sr_dn_level, x)) / 2)
if close[1] <= mid and close > mid
ret := true
ret
ret
f_crossed_under() =>
ret = false
for x = 0 to array.size(sr_up_level) > 0 ? array.size(sr_up_level) - 1 : na by
1
float mid = math.round_to_mintick((array.get(sr_up_level, x) +
array.get(sr_dn_level, x)) / 2)
if close[1] >= mid and close < mid
ret := true
ret
ret

//RSI
// rsicol = input.bool(false, title='Show RSI colors?', group='Settings',
tooltip='Show RSI Levels On Bars')
srcRSI = close
lenRSI = input.int(14, minval=1, title='RSI Length', group='RSI Settings')
up = ta.rma(math.max(ta.change(srcRSI), 0), lenRSI)
down = ta.rma(-math.min(ta.change(srcRSI), 0), lenRSI)
rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - 100 / (1 + up / down)

//coloring method below


srcRSI1 = close
lenRSI1 = input.int(60, minval=1, title='Over Bought', group='RSI Settings')
srcRSI2 = close
lenRSI2 = input.int(40, minval=1, title='Over Sold', group='RSI Settings')
isup() =>
rsi > lenRSI1
isdown() =>
rsi < lenRSI2
barcolor(rsicol and isup() ? color.yellow : rsicol and isdown() ? color.orange :
na)

///////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////

//@version=5
//indicator("Merged Inside Bar & Breakout/Breakdown with Volume Confirmation",
overlay=true)

// Input for volume threshold display


showVolumeThreshold = input.bool(false, title="Show Volume Threshold")

// Input for line color


lineColor1 = input(color.new(#b2b5be, 0), title="Line Color")

// Input for inside bar color


insideBarColor1 = color.orange

// Input for line width


lineWidth1 = input.int(2, title="Line Width1")

// Input for line style


styleOption = input.string("────", title="Line Style1",
options=["────", "┈┈┈", "╌╌╌"])

lineStyle1 = styleOption == "dotted (┈)" ? line.style_dotted :


styleOption == "dashed (╌)" ? line.style_dashed :
styleOption == "arrow left (←)" ? line.style_arrow_left :
styleOption == "arrow right (→)" ? line.style_arrow_right :
styleOption == "arrows both (↔)" ? line.style_arrow_both :
line.style_solid

// Function to identify inside bars


isInsideBar() =>
high[1] > high and low[1] < low

// Color the inside bars


barcolor(isInsideBar() ? insideBarColor1 : na, title="Inside Bar")

// Initialize variables for breakout/breakdown


var float mhigh = na
var float mlow = na
var line mhighLine = na
var line mlowLine = na

// Track if breakout or breakdown has already occurred


var bool breakoutOccurred = false
var bool breakdownOccurred = false

// If the current bar is an inside bar, set mhigh and mlow to the previous bar's
high and low
if (isInsideBar())
mhigh := high[1]
mlow := low[1]

// Delete previous lines


if (not na(mhighLine))
line.delete(mhighLine)
if (not na(mlowLine))
line.delete(mlowLine)

// Draw new lines


mhighLine := line.new(x1=bar_index[1], y1=mhigh, x2=bar_index+10, y2=mhigh,
color=lineColor1, width=lineWidth, style=lineStyle1)
mlowLine := line.new(x1=bar_index[1], y1=mlow, x2=bar_index+10, y2=mlow,
color=lineColor1, width=lineWidth, style=lineStyle1)

// Reset breakout/breakdown occurrence tracking


breakoutOccurred := false
breakdownOccurred := false

// Define volume threshold


volumeThreshold = showVolumeThreshold ? 100000 : na

// Logic for breakout or breakdown with volume confirmation


breakout = (not na(mhigh)) and (close > mhigh) and (not na(volumeThreshold) ?
volume > volumeThreshold : true) and not breakdownOccurred
breakdown = (not na(mlow)) and (close < mlow) and (not na(volumeThreshold) ? volume
> volumeThreshold : true) and not breakoutOccurred

// Label and bar color handling


plotshape(series=breakout and not breakoutOccurred, style=shape.triangleup,
location=location.belowbar, color=color.green, text="Breakout",
textcolor=color.green, size=size.tiny)
plotshape(series=breakdown and not breakdownOccurred, style=shape.triangledown,
location=location.abovebar, color=color.red, text="Breakdown", textcolor=color.red,
size=size.tiny)

// Change bar color to yellow when breakout or breakdown label is printed


barcolor((breakout and not breakoutOccurred) or (breakdown and not
breakdownOccurred) ? color.yellow : na, title="")

// Update breakout/breakdown occurrence tracking


if (breakout)
breakoutOccurred := true
if (breakdown)
breakdownOccurred := true

// HMI Inputs
var incount = 1
var inside = false
var topinside = 0.0
var lowinside = 0.0

// Locate and track inside bars


if high < high[1] and low > low[1] and not inside
inside := true
topinside := high[1]
lowinside := low[1]

if inside and (close > high[incount] or close < low[incount])


incount := 1
inside := false
topinside := 0
lowinside := 0
else if inside
incount := incount + 1

// Plot inside bar values


plot(topinside == 0 ? na : topinside, 'Top Inside Value', ta.change(topinside) ? na
: color.new(color.blue, 30), linewidth=2)
plot(lowinside == 0 ? na : lowinside, 'Low Inside Value', ta.change(lowinside) ? na
: color.new(color.blue, 30), linewidth=2)

//////////
// This source code is subject to the terms of the Mozilla Public License 2.0 at
https://mozilla.org/MPL/2.0/
// © LudoGH68
//@version=5
import LudoGH68/Drawings_public/1 as d

getLineStyle(lineOption) =>
lineOption == "┈" ? line.style_dotted : lineOption == "╌" ? line.style_dashed :
line.style_solid

get_structure_highest_bar(lookback) =>

var int idx = 0


maxBar = bar_index > lookback ? ta.highestbars(high, lookback) :
ta.highestbars(high, bar_index + 1)

for i = 0 to lookback - 1 by 1
if high[i+1] > high[i+2] and high[i] <= high[i+1] and ((i+1) * -1) >=
maxBar
idx := (i+1) * -1
//break

idx := idx == 0 ? maxBar : idx

get_structure_lowest_bar(lookback) =>

var int idx = 0


minBar = bar_index > lookback ? ta.lowestbars(low, lookback) :
ta.lowestbars(low, bar_index + 1)

for i = 0 to lookback - 1 by 1
if low[i+1] < low[i+2] and low[i] >= low[i+1] and ((i+1) * -1) >=
minBar
idx := (i+1) * -1
//break

idx := idx == 0 ? minBar : idx

is_structure_high_broken(_highStructBreakPrice, _structureHigh,
_structureHighStartIndex, _structureDirection) =>
var bool res = false

if (_highStructBreakPrice > _structureHigh and bar_index[1] >


_structureHighStartIndex) or (_structureDirection == 1 and _highStructBreakPrice >
_structureHigh)
res := true
else
res := false

res

// Fear Value Gap


isFvgToShow = input(true, title='Display FVG', group="Fear Value Gap")
bullishFvgColor = input(color.new(color.green, 50), 'Bullish FVG Color',
group="Fear Value Gap")
bearishFvgColor = input(color.new(color.red, 50), 'Bearish FVG Color', group="Fear
Value Gap")
mitigatedFvgColor = input(color.new(color.gray, 50), 'Mitigated FVG Color',
group="Fear Value Gap")
fvgHistoryNbr = input.int(5, 'Number of FVG to show', minval=1, maxval=50)
isMitigatedFvgToReduce = input(false, title='Reduce mitigated FVG', group="Fear
Value Gap")

// Structures
isStructBodyCandleBreak = input(true, title='Break with candle\'s body',
group="Structures")
isCurrentStructToShow = input(true, title='Display current structure',
group="Structures")
bullishBosColor = input(color.silver, 'Bullish BOS Color', group="Structures")
bearishBosColor = input(color.silver, 'Bearish BOS Color', group="Structures")
bosLineStyleOption = input.string("─", title="BOS Style", group="Structures",
options=["─", "┈", "╌"])
bosLineStyle = getLineStyle(bosLineStyleOption)
bosLineWidth = input.int(1, title="BOS Width", group="Structures", minval=1,
maxval=5)
bullishChochColor = input(color.yellow, 'Bullish CHoCH Color', group="Structures")
bearishChochColor = input(color.yellow, 'Bearish CHoCH Color', group="Structures")
chochLineStyleOption = input.string("─", title="CHoCH Style", group="Structures",
options=["─", "┈", "╌"])
chochLineStyle = getLineStyle(chochLineStyleOption)
chochLineWidth = input.int(1, title="MSB Width", group="Structures", minval=1,
maxval=5)
currentStructColor = input(color.blue, 'Current structure Color',
group="Structures")
currentStructLineStyleOption = input.string("─", title="Current structure Style",
group="Structures", options=["─", "┈", "╌"])
currentStructLineStyle = getLineStyle(currentStructLineStyleOption)
currentStructLineWidth = input.int(1, title="Current structure Width",
group="Structures", minval=1, maxval=5)
structHistoryNbr = input.int(10, 'Number of break to show', minval=1, maxval=50)

// Fibonacci 1
isFibo1ToShow = input(true, title = "", group="Structure Fibonacci", inline =
"Fibo1")
fibo1Value = input.float(0.786, title = "", group="Structure Fibonacci", inline =
"Fibo1")
fibo1Color = input(#64b5f6, title = "", group="Structure Fibonacci", inline =
"Fibo1")
fibo1StyleOption = input.string("─", title = "", group="Structure Fibonacci",
options=["─", "┈", "╌"], inline = "Fibo1")
fibo1Style = getLineStyle(fibo1StyleOption)
fibo1LineWidth = input.int(1, title = "", group="Structure Fibonacci", minval=1,
maxval=5, inline = "Fibo1")

// Fibonacci 2
isFibo2ToShow = input(true, title = "", group="Structure Fibonacci", inline =
"Fibo2")
fibo2Value = input.float(0.705, title = "", group="Structure Fibonacci", inline =
"Fibo2")
fibo2Color = input(#f23645, title = "", group="Structure Fibonacci", inline =
"Fibo2")
fibo2StyleOption = input.string("─", title = "", group="Structure Fibonacci",
options=["─", "┈", "╌"], inline = "Fibo2")
fibo2Style = getLineStyle(fibo2StyleOption)
fibo2LineWidth = input.int(1, title = "", group="Structure Fibonacci", minval=1,
maxval=5, inline = "Fibo2")

// Fibonacci 3
isFibo3ToShow = input(true, title = "", group="Structure Fibonacci", inline =
"Fibo3")
fibo3Value = input.float(0.618, title = "", group="Structure Fibonacci", inline =
"Fibo3")
fibo3Color = input(#089981, title = "", group="Structure Fibonacci", inline =
"Fibo3")
fibo3StyleOption = input.string("─", title = "", group="Structure Fibonacci",
options=["─", "┈", "╌"], inline = "Fibo3")
fibo3Style = getLineStyle(fibo3StyleOption)
fibo3LineWidth = input.int(1, title = "", group="Structure Fibonacci", minval=1,
maxval=5, inline = "Fibo3")

// Fibonacci 3
isFibo4ToShow = input(true, title = "", group="Structure Fibonacci", inline =
"Fibo4")
fibo4Value = input.float(0.5, title = "", group="Structure Fibonacci", inline =
"Fibo4")
fibo4Color = input(#4caf50, title = "", group="Structure Fibonacci", inline =
"Fibo4")
fibo4StyleOption = input.string("─", title = "", group="Structure Fibonacci",
options=["─", "┈", "╌"], inline = "Fibo4")
fibo4Style = getLineStyle(fibo4StyleOption)
fibo4LineWidth = input.int(1, title = "", group="Structure Fibonacci", minval=1,
maxval=5, inline = "Fibo4")

// Fibonacci 5
isFibo5ToShow = input(true, title = "", group="Structure Fibonacci", inline =
"Fibo5")
fibo5Value = input.float(0.382, title = "", group="Structure Fibonacci", inline =
"Fibo5")
fibo5Color = input(#81c784, title = "", group="Structure Fibonacci", inline =
"Fibo5")
fibo5StyleOption = input.string("─", title = "", group="Structure Fibonacci",
options=["─", "┈", "╌"], inline = "Fibo5")
fibo5Style = getLineStyle(fibo5StyleOption)
fibo5LineWidth = input.int(1, title = "", group="Structure Fibonacci", minval=1,
maxval=5, inline = "Fibo5")

// Draw FVG into graph


FVGDraw(_boxes, _fvgTypes, _isFvgMitigated) =>

// Loop into all values of the array


for [index, value] in _boxes

// Processing bullish FVG


if(array.get(_fvgTypes, index))

// Check if FVG has been totally mitigated


if(low <= box.get_bottom(value))
array.remove(_boxes, index)
array.remove(_fvgTypes, index)
array.remove(_isFvgMitigated, index)
box.delete(value)
else
if(low < box.get_top((value)))
box.set_bgcolor(value, mitigatedFvgColor)

// Mitigated FVG Alert


if(not(array.get(_isFvgMitigated, index)))
alert("FVG has been mitigated", alert.freq_once_per_bar)
array.set(_isFvgMitigated, index, true)

// Reduce FVG if needed


if(isMitigatedFvgToReduce)
box.set_top(value, low)

box.set_right(value, bar_index)

// Processing bearish FVG


else

// Check if FVG has been mitigated


if(high >= box.get_top(value))
array.remove(_boxes, index)
array.remove(_fvgTypes, index)
array.remove(_isFvgMitigated, index)
box.delete(value)
else
if(high > box.get_bottom((value)))
box.set_bgcolor(value, mitigatedFvgColor)

// Mitigated FVG Alert


if(not(array.get(_isFvgMitigated, index)))
alert("FVG has been mitigated", alert.freq_once_per_bar)
array.set(_isFvgMitigated, index, true)

// Reduce FVG if needed


if(isMitigatedFvgToReduce)
box.set_bottom(value, high)

box.set_right(value, bar_index)

// Arrays variable
var array<line> structureLines = array.new_line(0)
var array<label> structureLabels = array.new_label(0)
var array<box> fvgBoxes = array.new_box(0)
var array<bool> fvgTypes = array.new_bool(0)
var array<bool> isFvgMitigated = array.new_bool(0)

// Price variables
var float structureHigh = 0.0
var float structureLow = 0.0
var float fibo1Price = 0.0
var float fibo2Price = 0.0
var float fibo3Price = 0.0
var float fibo4Price = 0.0
var float fibo5Price = 0.0

// Index variable
var int structureHighStartIndex = 0
var int structureLowStartIndex = 0
var int structureDirection = 0
var int fibo1StartIndex = 0
var int fibo2StartIndex = 0
var int fibo3StartIndex = 0
var int fibo4StartIndex = 0
var int fibo5StartIndex = 0

// Line variable
var line structureHighLine = na
var line structureLowLine = na
var line fibo1Line = na
var line fibo2Line = na
var line fibo3Line = na
var line fibo4Line = na
var line fibo5Line = na

// Label variable
var label fibo1Label = na
var label fibo2Label = na
var label fibo3Label = na
var label fibo4Label = na
var label fibo5Label = na
//
//
//
===================================================================================
=======
// FAIR VALUE GAP FINDER PROCESSING
//
===================================================================================
=======
//
//
// Define FVG type
isBullishFVG = high[3] < low[1]
isBearishFVG = low[3] > high[1]

// Bullish FVG process


if(isBullishFVG and isFvgToShow)

// Add FVG into FVG's array


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))
array.push(fvgBoxes, _box)
array.push(fvgTypes, true)
array.push(isFvgMitigated, false)

// Check if FVG to show is upper than user parameter


if(array.size(fvgBoxes) > fvgHistoryNbr + 1)

// Delete the FVG and its index from arrays


box.delete(array.get(fvgBoxes, 0))
array.remove(fvgBoxes, 0)
array.remove(fvgTypes, 0)
array.remove(isFvgMitigated, 0)

// Bearish FVG process


if(isBearishFVG and isFvgToShow)

// Add FVG into FVG's array


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))
array.push(fvgBoxes, _box)
array.push(fvgTypes, false)
array.push(isFvgMitigated, false)

// Check if FVG to show is upper than user parameter


if(array.size(fvgBoxes) > fvgHistoryNbr + 1)

// Delete the FVG and its index from arrays


box.delete(array.get(fvgBoxes, 0))
array.remove(fvgBoxes, 0)
array.remove(fvgTypes, 0)
array.remove(isFvgMitigated, 0)

// Draw FVG
FVGDraw(fvgBoxes, fvgTypes, isFvgMitigated)
//
//
//
===================================================================================
=======
// STRUCTURES PROCESSING
//
===================================================================================
=======
//
//
// Initialize value for bar 0
if(bar_index == 0)
structureHighStartIndex := bar_index
structureLowStartIndex := bar_index
structureHigh := high
structureLow := low

highest = bar_index > 10 ? ta.highest(10) : ta.highest(bar_index + 1)


highestBar = bar_index > 10 ? ta.highestbars(high, 10) : ta.highestbars(high,
bar_index + 1)
lowest = bar_index > 10 ? ta.lowest(10) : ta.lowest(bar_index + 1)
lowestBar = bar_index > 10 ? ta.lowestbars(low, 10) : ta.lowestbars(low, bar_index
+ 1)
structureMaxBar = bar_index + get_structure_highest_bar(10)
structureMinBar = bar_index + get_structure_lowest_bar(10)
lowStructBreakPrice = isStructBodyCandleBreak ? close : low
highStructBreakPrice = isStructBodyCandleBreak ? close : high
isStuctureLowBroken = (lowStructBreakPrice < structureLow and
lowStructBreakPrice[1] >= structureLow and lowStructBreakPrice[2] >= structureLow
and lowStructBreakPrice[3] >= structureLow and bar_index[1] >
structureLowStartIndex and bar_index[2] > structureLowStartIndex and bar_index[3]
> structureLowStartIndex) or (structureDirection == 2 and lowStructBreakPrice <
structureLow)
isStructureHighBroken = (highStructBreakPrice > structureHigh and
highStructBreakPrice[1] <= structureHigh and highStructBreakPrice[2] <=
structureHigh and highStructBreakPrice[3] <= structureHigh and bar_index[1] >
structureHighStartIndex and bar_index[2] > structureHighStartIndex and
bar_index[3] > structureHighStartIndex) or (structureDirection == 1 and
highStructBreakPrice > structureHigh)

//if((low < structureLow and low[1] >= structureLow and low[2] >= structureLow and
low[3] >= structureLow and bar_index[1] > structureLowStartIndex and bar_index[2]
> structureLowStartIndex and bar_index[3] > structureLowStartIndex) or
(structureDirection == 2 and low < structureLow))
if(isStuctureLowBroken)
// Check if structures to show is upper than user parameter
if(array.size(structureLines) >= structHistoryNbr)

// Delete the line and its index from arrays


d.delete_line(array.get(structureLines, 0), array.get(structureLabels, 0))
array.remove(structureLabels, 0)
array.remove(structureLines, 0)

// Create BOS line


if(structureDirection == 1)
array.push(structureLines, line.new(structureLowStartIndex, structureLow,
bar_index, structureLow, xloc=xloc.bar_index, extend=extend.none,
color=bearishBosColor, style=bosLineStyle, width=bosLineWidth))
array.push(structureLabels, label.new((bar_index +
structureLowStartIndex) / 2, structureLow, text="BOS", style=label.style_none,
textcolor=bearishBosColor))
// Create CHoCH line
else
array.push(structureLines, line.new(structureLowStartIndex, structureLow,
bar_index, structureLow, xloc=xloc.bar_index, extend=extend.none,
color=bearishChochColor, style=chochLineStyle, width=chochLineWidth))
array.push(structureLabels, label.new((bar_index +
structureLowStartIndex) / 2, structureLow, text="CHoCH", style=label.style_none,
textcolor=bearishChochColor))

// Update values for new structure


structureDirection := 1
structureHighStartIndex := structureMaxBar
structureLowStartIndex := bar_index
structureHigh := high[bar_index - structureHighStartIndex] //highest
structureLow := low

// Check for breakout


else if(isStructureHighBroken)

// Check if structures to show is upper than user parameter


if(array.size(structureLines) >= structHistoryNbr)

// Delete the line and its index from arrays


d.delete_line(array.get(structureLines, 0), array.get(structureLabels, 0))
array.remove(structureLabels, 0)
array.remove(structureLines, 0)

// Create BOS line


if(structureDirection == 2)
array.push(structureLines, line.new(structureHighStartIndex, structureHigh,
bar_index, structureHigh, xloc=xloc.bar_index, extend=extend.none,
color=bullishBosColor, style=bosLineStyle, width=bosLineWidth))
array.push(structureLabels, label.new((bar_index + structureHighStartIndex)
/ 2, structureHigh, text="BOS", style=label.style_none, textcolor=bullishBosColor))

// Create CHoCH line


else
array.push(structureLines, line.new(structureHighStartIndex, structureHigh,
bar_index, structureHigh, xloc=xloc.bar_index, extend=extend.none,
color=bullishChochColor, style=chochLineStyle, width=chochLineWidth))
array.push(structureLabels, label.new((bar_index + structureHighStartIndex)
/ 2, structureHigh, text="CHoCH", style=label.style_none,
textcolor=bullishChochColor))

// Update values for new structure


structureDirection := 2
structureHighStartIndex := bar_index
structureLowStartIndex := structureMinBar
structureHigh := high
structureLow := low[bar_index - structureLowStartIndex] //lowest
else
if(high > structureHigh and (structureDirection == 0 or structureDirection ==
2))
if(not(isStructBodyCandleBreak) or not(isStructBodyCandleBreak and
bar_index[1] > structureHighStartIndex and bar_index[2] > structureHighStartIndex
and bar_index[3] > structureHighStartIndex))
structureHigh := high
structureHighStartIndex := bar_index
else if(low < structureLow and (structureDirection == 0 or structureDirection
== 1))
if(not(isStructBodyCandleBreak) or not(isStructBodyCandleBreak and
bar_index[1] > structureLowStartIndex and bar_index[2] > structureLowStartIndex and
bar_index[3] > structureLowStartIndex))
structureLow := low
structureLowStartIndex := bar_index

structureRange = math.abs(structureHigh - structureLow)

// Affichage de la structure actuelle


if(isCurrentStructToShow)
d.delete_line(structureHighLine, na)
d.delete_line(structureLowLine, na)
structureHighLine := line.new(structureHighStartIndex, structureHigh,
bar_index, structureHigh, xloc.bar_index, color=currentStructColor, style =
currentStructLineStyle, width = currentStructLineWidth)
structureLowLine := line.new(structureLowStartIndex, structureLow, bar_index,
structureLow, xloc.bar_index, color=currentStructColor, style =
currentStructLineStyle, width = currentStructLineWidth)

// Affichage du Fibonnacci 1 de la structure actuelle


if(isFibo1ToShow)
d.delete_line(fibo1Line, fibo1Label)
fibo1Price := structureDirection == 1 ? structureHigh - (structureRange -
structureRange * fibo1Value) : structureLow + (structureRange - structureRange *
fibo1Value)
fibo1StartIndex := structureDirection == 1 ? structureHighStartIndex :
structureLowStartIndex
fibo1Line := line.new(fibo1StartIndex, fibo1Price, bar_index, fibo1Price,
xloc.bar_index, color = fibo1Color, style = fibo1Style, width = fibo1LineWidth)
fibo1Label := label.new(bar_index + 20, fibo1Price, text =
str.tostring(fibo1Value) + "(" + str.tostring(fibo1Price) + ")", style =
label.style_none, textcolor = fibo1Color)

// Affichage du Fibonnacci 2 de la structure actuelle


if(isFibo2ToShow)
d.delete_line(fibo2Line, fibo2Label)
fibo2Price := structureDirection == 1 ? structureHigh - (structureRange -
structureRange * fibo2Value) : structureLow + (structureRange - structureRange *
fibo2Value)
fibo2StartIndex := structureDirection == 1 ? structureHighStartIndex :
structureLowStartIndex
fibo2Line := line.new(fibo2StartIndex, fibo2Price, bar_index, fibo2Price,
xloc.bar_index, color = fibo2Color, style = fibo2Style, width = fibo2LineWidth)
fibo2Label := label.new(bar_index + 20, fibo2Price, text =
str.tostring(fibo2Value) + "(" + str.tostring(fibo2Price) + ")", style =
label.style_none, textcolor = fibo2Color)

// Affichage du Fibonnacci 3 de la structure actuelle


if(isFibo3ToShow)
d.delete_line(fibo3Line, fibo3Label)
fibo3Price := structureDirection == 1 ? structureHigh - (structureRange -
structureRange * fibo3Value) : structureLow + (structureRange - structureRange *
fibo3Value)
fibo3StartIndex := structureDirection == 1 ? structureHighStartIndex :
structureLowStartIndex
fibo3Line := line.new(fibo3StartIndex, fibo3Price, bar_index, fibo3Price,
xloc.bar_index, color = fibo3Color, style = fibo3Style, width = fibo3LineWidth)
fibo3Label := label.new(bar_index + 20, fibo3Price, text =
str.tostring(fibo3Value) + "(" + str.tostring(fibo3Price) + ")", style =
label.style_none, textcolor = fibo3Color)

// Affichage du Fibonnacci 1 de la structure actuelle


if(isFibo4ToShow)
d.delete_line(fibo4Line, fibo4Label)
fibo4Price := structureDirection == 1 ? structureHigh - (structureRange -
structureRange * fibo4Value) : structureLow + (structureRange - structureRange *
fibo4Value)
fibo4StartIndex := structureDirection == 1 ? structureHighStartIndex :
structureLowStartIndex
fibo4Line := line.new(fibo4StartIndex, fibo4Price, bar_index, fibo4Price,
xloc.bar_index, color = fibo4Color, style = fibo4Style, width = fibo4LineWidth)
fibo4Label := label.new(bar_index + 20, fibo4Price, text =
str.tostring(fibo4Value) + "(" + str.tostring(fibo4Price) + ")", style =
label.style_none, textcolor = fibo4Color)

// Affichage du Fibonnacci 1 de la structure actuelle


if(isFibo5ToShow)
d.delete_line(fibo5Line, fibo5Label)
fibo5Price := structureDirection == 1 ? structureHigh - (structureRange -
structureRange * fibo5Value) : structureLow + (structureRange - structureRange *
fibo5Value)
fibo5StartIndex := structureDirection == 1 ? structureHighStartIndex :
structureLowStartIndex
fibo5Line := line.new(fibo5StartIndex, fibo5Price, bar_index, fibo5Price,
xloc.bar_index, color = fibo5Color, style = fibo5Style, width = fibo5LineWidth)
fibo5Label := label.new(bar_index + 20, fibo5Price, text =
str.tostring(fibo5Value) + "(" + str.tostring(fibo5Price) + ")", style =
label.style_none, textcolor = fibo5Color)

plot(na)

You might also like