0% found this document useful (0 votes)
33 views13 pages

FVG

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)
33 views13 pages

FVG

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/ 13

//@version=5

//This source code is subject to the terms of the Mozilla Public License 2.0 at
https://mozilla.org/MPL/2.0/
indicator('VUGS _ SND/FVG/BoS', overlay=true, max_boxes_count=500,
max_lines_count=500)

plotOB = input.bool(defval=true, title='Plot OB', group='Order Blocks')

filterMitOB = input.bool(defval=false, title='Custom Color Mitigated OB',


group='Order Blocks')
mitOBColor = input.color(defval=color.new(color.gray, 90), title='Mitigated OB
Color', group='Order Blocks', inline='Set Custom Color Mit OB', tooltip='Set
Transparency to 0 to make mitigated OB disappear')
plotFVG = input.bool(defval=true, title='Plot FVG', group='Fair Value Gaps',
inline='FVG sets')
plotStructureBreakingFVG = input.bool(defval=true, title='Plot Structure Breaking
FVG', group='Fair Value Gaps', inline='FVG sets')
fvgBullColor = input.color(defval=color.new(color.black, 90), title='Bullish FVG
Color', inline='Set Custom Color', group='Fair Value Gaps')
fvgBearColor = input.color(defval=color.new(color.black, 90), title='Bearish FVG
Color', inline='Set Custom Color', group='Fair Value Gaps')
fvgStructBreakingColor = input.color(defval=color.new(color.blue, 90),
title='Structure Breaking FVG Color', inline='Set Custom Color', group='Fair Value
Gaps')
fvgBoxBorder = input.string(defval=line.style_solid, title='FVG Box Border Style',
options=[line.style_dashed, line.style_dotted, line.style_solid], group='Fair Value
Gaps', tooltip='To disable border, set Border Width below to 0')
fvgBorderTransparency = input.int(defval=80, title='FVG Border Box Transparency',
minval=0, maxval=100, group='Fair Value Gaps')
fvgMaxBoxSet = input.int(defval=10, title='Maximum FVG Box Displayed', minval=1,
maxval=100, group='Fair Value Gaps', tooltip='Minimum = 1, Maximum = 100')
filterMitFVG = input.bool(defval=false, title='Custom Color Mitigated FVG',
group='Fair Value Gaps')
plotRJB = input.bool(defval=false, title='Plot RJB', group='Rejection Blocks',
inline='RJB sets')
filterMitRJB = input.bool(defval=false, title='Custom Color Mitigated RJB',
group='Rejection Blocks')
plotPVT = input.bool(defval=true, title='Plot Pivots', group='Pivots')
pivotLookup = input.int(defval=1, minval=1, maxval=5,title='Pivot Lookup',
group='Pivots', tooltip='Minimum = 1, Maximum = 5')
bosMaxBoxSet = input.int(defval=10, title='Maximum BoS Box Displayed', minval=1,
maxval=100, group='Crossovers', tooltip='Minimum = 1, Maximum = 100')
plotLabelFVG = input.bool(defval=true, title='Plot FVG Label', inline='FVG label',
group='Label Options')
fvgLabelColor = input.color(defval=color.gray, title='Color', inline='FVG label',
group='Label Options')
fvgLabelSize = input.string(defval=size.tiny, title="Size", options=[size.huge,
size.large, size.small, size.tiny, size.auto, size.normal], inline='FVG label',
group='Label Options')
bosBoxFlag = input.bool(title='BoS Box Length Manually', defval=false,
group='Crossovers', tooltip='If activated the BoS Boxes will not extend unitl
crossed by price. Instead will extendby the amount of bars choosen in the "Set BoS
Box Length Manually" option')
//-----Input-------
customTF = input.timeframe(defval="",title = "Show Other TimeFrame")
GroupGann = "Gann"
showGann = input.bool(false, 'Show Gann/Color/Width', group = GroupGann, inline =
"Gann1")
colorGann = input.color(color.aqua, '', group = GroupGann,inline = "Gann1")
widthGann = input.int(defval=1,title = "",minval=1,step=1, group = GroupGann,inline
= "Gann1")

GroupSGann = "Swing of Gann"

showSGann = input.bool(true, 'Show Swing/Color/Width', group = GroupSGann,inline =


"Swing1")
colorSGann = input.color(color.blue, '', group = GroupSGann,inline = "Swing1")
widthSGann = input.int(defval=1,title = "",minval=1,step=1, group =
GroupSGann,inline = "Swing1")

showChoCh = input.bool(false, 'Show ChoCh/Color/Width', group = GroupSGann,inline =


"Choch")
colorChoch = input.color(color.red, '', group = GroupSGann,inline = "Choch")
widthChoch = input.int(defval=1,title = "",minval=1,step=1, group =
GroupSGann,inline = "Choch")

show2ChoCh = input.bool(false, 'Show 2Choch/Color/Width', group = GroupSGann,inline


= "2Choch")
color2Choch = input.color(color.purple, '', group = GroupSGann,inline = "2Choch")
width2Choch = input.int(defval=1,title = "",minval=1,step=1, group =
GroupSGann,inline = "2Choch")

showLabel = input.bool(false, 'Show Label TimeFrame',group = GroupSGann)

//showLinePrice = input.bool(true, 'Show LinePrice/Color/Width', group =


GroupSGann,inline = "LinePrice")
//colorLinePrice = input.color(color.blue, '', group = GroupSGann,inline =
"LinePrice")
//widthLinePrice = input.int(defval=1,title = "",minval=1,step=1, group =
GroupSGann,inline = "LinePrice")

///tùy chọn line//


lineGann = input.string(title="",options=['(─)', '(╌)', '(┈)'],defval='(╌)', group
= GroupGann, inline = "Gann1")
lineStyleGann = lineGann == "(┈)" ? line.style_dotted : lineGann == "(╌)" ?
line.style_dashed : line.style_solid

lineSGann = input.string(title="",options=["(─)", "(╌)", "(┈)"],defval="(─)", group


= GroupSGann, inline = "Swing1")
lineStyleSGann = lineSGann == "(┈)" ? line.style_dotted : lineSGann == "(╌)" ?
line.style_dashed : line.style_solid

line2Choch = input.string(title="",options=["(─)", "(╌)", "(┈)"],defval="(╌)",


group = GroupSGann, inline = "2Choch")
lineStyle2Choch = line2Choch == "(┈)" ? line.style_dotted : line2Choch == "(╌)" ?
line.style_dashed : line.style_dashed

lineChoch = input.string(title="",options=["(─)", "(╌)", "(┈)","(←)", "(→)",


"(↔)"],defval="(─)", group = GroupSGann, inline = "Choch")
lineStyleChoch = lineChoch == "(┈)" ? line.style_dotted : lineChoch == "(╌)" ?
line.style_dashed : lineChoch == "(←)" ? line.style_arrow_left : lineChoch == "(→)"
? line.style_arrow_right : lineChoch == "(↔)" ? line.style_arrow_both :
line.style_solid

linetargetOTL = input.string(title="",options=["(─)", "(╌)", "(┈)","(←)", "(→)",


"(↔)"],defval="(→)", group = GroupSGann, inline = "target")
lineStyletargetOTL = linetargetOTL == "(┈)" ? line.style_dotted : linetargetOTL ==
"(╌)" ? line.style_dashed : linetargetOTL == "(←)" ? line.style_arrow_left :
linetargetOTL == "(→)" ? line.style_arrow_right : linetargetOTL == "(↔)" ?
line.style_arrow_both : line.style_arrow_both

//Box Types
var int _ob = 1
var int _fvg = 2
var int _rjb = 3
var int _bos = 4

//Box Labels
var string _obLabel = "OB"
var string _fvgLabel = "FVG"
var string _rjbLabel = "RJB"
var string _bosLabel = "BoS"
var string _plus = "+"
var string _minus = "-"
var string _empty = ""

//Box Arrays
var box[] _bearBoxesOB = array.new_box()
var box[] _bullBoxesOB = array.new_box()
var box[] _bearBoxesFVG = array.new_box()
var box[] _bullBoxesFVG = array.new_box()
var box[] _bearBoxesRJB = array.new_box()
var box[] _bullBoxesRJB = array.new_box()
var box[] _bearBoxesBOS = array.new_box()
var box[] _bullBoxesBOS = array.new_box()

//Functions
isUp(index) =>
close[index] > open[index]

isDown(index) =>
close[index] < open[index]

isObUp(index) =>
isDown(index + 1) and isUp(index) and close[index] > high[index + 1]

isObDown(index) =>
isUp(index + 1) and isDown(index) and close[index] < low[index + 1]

isFvgUp(index) =>
(low[index] > high[index + 2])

isFvgDown(index) =>
(high[index] < low[index + 2])

//Function to Calculte Box Length


_controlBox(_boxes, _high, _low, _type) =>
if array.size(_boxes) > 0
for i = array.size(_boxes) - 1 to 0 by 1
_box = array.get(_boxes, i)
_boxLow = box.get_bottom(_box)
_boxHigh = box.get_top(_box)
_boxRight = box.get_right(_box)
if (filterMitOB and _type == _ob) or (filterMitFVG and _type == _fvg)
or (filterMitRJB and _type == _rjb)
if na or (bar_index == _boxRight and not((_high > _boxLow and _low
< _boxLow) or (_high > _boxHigh and _low < _boxHigh)))
box.set_right(_box, bar_index + 1)

else
if na or (bar_index == _boxRight and not((_high > _boxLow and _low
< _boxLow) or (_high > _boxHigh and _low < _boxHigh)))
box.set_right(_box, bar_index + 1)

//////////////////// Pivots ////////////////////


hih = ta.pivothigh(high, pivotLookup, pivotLookup)
lol = ta.pivotlow(low , pivotLookup, pivotLookup)
top = ta.valuewhen(hih, high[pivotLookup], 0)
bottom = ta.valuewhen(lol, low [pivotLookup], 0)

//////////////////// Order Block //////////////////

//////////////////// Fair Value Gap //////////////////


//Bullish FVG Box Plotting
if isFvgUp(0)
box _bullboxFVG = na
if plotStructureBreakingFVG and (close[1] > top) and (low[1] < top) and
(high[2] < top) and (low > top)
_bullboxFVG := box.new(left=bar_index-2, top=low[0], right=bar_index,
bottom=high[2], bgcolor=fvgStructBreakingColor,
border_color=color.new(fvgStructBreakingColor, fvgBorderTransparency),
border_style=fvgBoxBorder, border_width=1,
text=plotLabelFVG ? _fvgLabel + _plus : _empty,
text_halign=text.align_right, text_valign=text.align_bottom,
text_size=fvgLabelSize, text_color=fvgLabelColor)
else if plotFVG
_bullboxFVG := box.new(left=bar_index-2, top=low[0], right=bar_index,
bottom=high[2], bgcolor=fvgBullColor, border_color=color.new(fvgBullColor,
fvgBorderTransparency), border_style=fvgBoxBorder, border_width=1,
text=plotLabelFVG ? _fvgLabel + _plus : _empty,
text_halign=text.align_right, text_valign=text.align_bottom,
text_size=fvgLabelSize, text_color=fvgLabelColor)
if array.size(_bullBoxesFVG) > fvgMaxBoxSet
box.delete(array.shift(_bullBoxesFVG))
array.push(_bullBoxesFVG, _bullboxFVG)

//Bearish FVG Box Plotting


if isFvgDown(0)
box _bearboxFVG = na
if plotStructureBreakingFVG and (close[1] < bottom) and (high[1] > bottom) and
(low[2] > bottom) and (high < bottom)
_bearboxFVG := box.new(left=bar_index-2, top=low[2], right=bar_index,
bottom=high[0], bgcolor=fvgStructBreakingColor,
border_color=color.new(fvgStructBreakingColor, fvgBorderTransparency),
border_style=fvgBoxBorder, border_width=1,
text=plotLabelFVG ? _fvgLabel + _minus : _empty,
text_halign=text.align_right, text_valign=text.align_bottom,
text_size=fvgLabelSize, text_color=fvgLabelColor)
else if plotFVG
_bearboxFVG := box.new(left=bar_index-2, top=low[2], right=bar_index,
bottom=high[0], bgcolor=fvgBearColor, border_color=color.new(fvgBearColor,
fvgBorderTransparency), border_style=fvgBoxBorder, border_width=1,
text=plotLabelFVG ? _fvgLabel + _minus : _empty,
text_halign=text.align_right, text_valign=text.align_bottom,
text_size=fvgLabelSize, text_color=fvgLabelColor)
if array.size(_bearBoxesFVG) > fvgMaxBoxSet
box.delete(array.shift(_bearBoxesFVG))
array.push(_bearBoxesFVG, _bearboxFVG)

if plotFVG or plotStructureBreakingFVG
_controlBox(_bearBoxesFVG, high, low, _fvg)
_controlBox(_bullBoxesFVG, high, low, _fvg)

//Bullish RJB Box Plotting


//in out side bar//
OSB_up_down ="Ousidebar up down"

//////////////////////////Global//////////////////////////
var arrayLineTemp = array.new_line()
// Funtion
f_resInMinutes() =>
_resInMinutes = timeframe.multiplier * (
timeframe.isseconds ? 1. / 60. :
timeframe.isminutes ? 1. :
timeframe.isdaily ? 1440. :
timeframe.isweekly ? 10080. :
timeframe.ismonthly ? 43800. : na)
// Converts a resolution expressed in minutes into a string usable by "security()"
f_resFromMinutes(_minutes) =>
_minutes < 1 ? str.tostring(math.round(_minutes*60)) + "S" :
_minutes < 60 ? str.tostring(math.round(_minutes)) + "m" :
_minutes < 1440 ? str.tostring(math.round(_minutes/60)) + "H" :
_minutes < 10080 ? str.tostring(math.round(math.min(_minutes / 1440,
7))) + "D" :
_minutes < 43800 ? str.tostring(math.round(math.min(_minutes /
10080, 4))) + "W" :
str.tostring(math.round(math.min(_minutes / 43800, 12))) + "M"
f_tfRes(_res,_exp) =>
request.security(syminfo.tickerid,_res,_exp,lookahead=barmerge.lookahead_on)

var arrayLineChoCh = array.new_line()


var label labelTF = label.new(time, close, text = "",color = color.new(showSGann ?
colorSGann : colorGann,95), textcolor = showSGann ? colorSGann : colorGann,xloc =
xloc.bar_time, textalign = text.align_left)
//var line line_Price = line.new(x1= time , y1=close,x2=time, y2= close,color =
showSGann ? colorLinePrice : colorGann,xloc = xloc.bar_time,style =
lineStyleLinePrice, width = widthLinePrice)

styleGann = showSGann ? line.style_dashed : line.style_solid


var arrayXGann = array.new_int(5,time)
var arrayYGann = array.new_float(5,close)
var arrayLineGann = array.new_line()
int drawLineGann = 0

_high = high
_low = low
_close = close
_open = open
if(customTF != timeframe.period)
_high := f_tfRes(customTF,high)
_low := f_tfRes(customTF,low)
_close := f_tfRes(customTF,close)
_open := f_tfRes(customTF,open)

highPrev = _high
lowPrev = _low
// drawLineGann => 2:Tiếp tục 1:Đảo chiều; // Outsidebar 2:Tiếp tục 3:Tiếp tục và
Đảo chiều 4 : Đảo chiều 2 lần
drawLineGann := 0
if(_high[0] > highPrev[1] and _low[0] > lowPrev[1])
if(array.get(arrayYGann,0) > array.get(arrayYGann,1))
if(_high[0] <= high)
array.set(arrayXGann, 0, time)
array.set(arrayYGann, 0, _high[0])
drawLineGann := 2
else
array.unshift(arrayXGann,time)
array.unshift(arrayYGann,_high[0])
drawLineGann := 1
else if(_high[0] < highPrev[1] and _low[0] < lowPrev[1])
if(array.get(arrayYGann,0) > array.get(arrayYGann,1))
array.unshift(arrayXGann,time)
array.unshift(arrayYGann,_low[0])
drawLineGann := 1
else
if(_low[0] >= low)
array.set(arrayXGann, 0, time)
array.set(arrayYGann, 0, _low[0])
drawLineGann := 2
else if(_high[0] >= highPrev[1] and _low[0] < lowPrev[1] or _high[0] > highPrev[1]
and _low[0] <= lowPrev[1])
if(array.get(arrayYGann,0) > array.get(arrayYGann,1))
if(_high[0] >= array.get(arrayYGann,0) and array.get(arrayYGann,1) <
_low[0])
if(_high[0] <= high)
array.set(arrayXGann, 0, time)
array.set(arrayYGann, 0, _high[0])
drawLineGann := 2
else if(_high[0] >= array.get(arrayYGann,0) and array.get(arrayYGann,1) >
_low[0])
if(_close < _open)
if(_high[0] <= high)
array.set(arrayXGann, 0, time)
array.set(arrayYGann, 0, _high[0])
array.unshift(arrayXGann,time)
array.unshift(arrayYGann,_low[0])
drawLineGann := 3
else
array.unshift(arrayXGann,time)
array.unshift(arrayYGann,_low[0])
array.unshift(arrayXGann,time)
array.unshift(arrayYGann,_high[0])
drawLineGann := 4
else if(array.get(arrayYGann,0) < array.get(arrayYGann,1))
if(_low[0] <= array.get(arrayYGann,0) and _high[0] <
array.get(arrayYGann,1))
if(_low[0] >= low)
array.set(arrayXGann, 0, time)
array.set(arrayYGann, 0, _low[0])
drawLineGann := 2
else if(_low[0] <= array.get(arrayYGann,0) and _high[0] >
array.get(arrayYGann,1))
if(_close > _open)
if(_low[0] >= low)
array.set(arrayXGann, 0, time)
array.set(arrayYGann, 0, _low[0])
array.unshift(arrayXGann,time)
array.unshift(arrayYGann,_high[0])
drawLineGann := 3
else
array.unshift(arrayXGann,time)
array.unshift(arrayYGann,_high[0])
array.unshift(arrayXGann,time)
array.unshift(arrayYGann,_low[0])
drawLineGann := 4
else if((_high[0] <= highPrev[1] and _low[0] >= lowPrev[1]))
highPrev := highPrev[1]
lowPrev := lowPrev[1]
if(f_resInMinutes() < f_tfRes(customTF,f_resInMinutes()) and drawLineGann == 0)
if(array.get(arrayYGann,0) > array.get(arrayYGann,1))
if(array.get(arrayYGann,0) <= high)
array.set(arrayXGann, 0, time)
drawLineGann := 2
else
if(array.get(arrayYGann,0) >= low)
array.set(arrayXGann, 0, time)
drawLineGann := 2
if(showGann and f_resInMinutes() <= f_tfRes(customTF,f_resInMinutes()))
if(drawLineGann == 2)
if(array.size(arrayLineGann) >0)

line.set_xy2(array.get(arrayLineGann,0),array.get(arrayXGann,0),array.get(arrayYGan
n,0))
else

array.unshift(arrayLineGann,line.new(array.get(arrayXGann,1),array.get(arrayYGann,1
),array.get(arrayXGann,0),array.get(arrayYGann,0), color = colorGann,xloc =
xloc.bar_time, style = lineStyleGann,width = widthGann))
else if(drawLineGann == 1)

array.unshift(arrayLineGann,line.new(array.get(arrayXGann,1),array.get(arrayYGann,1
),array.get(arrayXGann,0),array.get(arrayYGann,0), color = colorGann,xloc =
xloc.bar_time, style = lineStyleGann,width = widthGann))
else if(drawLineGann == 3)
if(array.size(arrayLineGann) >0)

line.set_xy2(array.get(arrayLineGann,0),array.get(arrayXGann,1),array.get(arrayYGan
n,1))
else

array.unshift(arrayLineGann,line.new(array.get(arrayXGann,2),array.get(arrayYGann,2
),array.get(arrayXGann,1),array.get(arrayYGann,1), color = colorGann,xloc =
xloc.bar_time, style = lineStyleGann,width = widthGann))

array.unshift(arrayLineGann,line.new(array.get(arrayXGann,1),array.get(arrayYGann,1
),array.get(arrayXGann,0),array.get(arrayYGann,0), color = colorGann,xloc =
xloc.bar_time, style = lineStyleGann,width = widthGann))
else if(drawLineGann == 4)

array.unshift(arrayLineGann,line.new(array.get(arrayXGann,2),array.get(arrayYGann,2
),array.get(arrayXGann,1),array.get(arrayYGann,1), color = colorGann,xloc =
xloc.bar_time, style = lineStyleGann,width = widthGann))

array.unshift(arrayLineGann,line.new(array.get(arrayXGann,1),array.get(arrayYGann,1
),array.get(arrayXGann,0),array.get(arrayYGann,0), color = colorGann,xloc =
xloc.bar_time, style = lineStyleGann,width = widthGann))

//////////////////////////Swing Gann//////////////////////////
var arrayXSGann = array.new_int(5,time)
var arrayYSGann = array.new_float(5,close)
var arrayLineSGann = array.new_line()
int drawLineSGann = 0
int drawLineSGann1 = 0
bool runCheckChoChSGann = false
runCheckChoChSGann := runCheckChoChSGann[1]
if(showSGann)
if(math.max(array.get(arrayYSGann,0),array.get(arrayYSGann,1)) <
math.min(array.get(arrayYGann,0),array.get(arrayYGann,1)) or
math.min(array.get(arrayYSGann,0),array.get(arrayYSGann,1)) >
math.max(array.get(arrayYGann,0),array.get(arrayYGann,1)))
//Khởi tạo bắt đầu
drawLineSGann1 := 5
array.set(arrayXSGann, 0, array.get(arrayXGann,1))
array.set(arrayYSGann, 0, array.get(arrayYGann,1))
array.unshift(arrayXSGann,array.get(arrayXGann,0))
array.unshift(arrayYSGann,array.get(arrayYGann,0))
// drawLineSGann kiểm tra điểm 1 => 13:Tiếp tục có sóng hồi // 12|
19(reDraw):Tiếp tục không có sóng hồi // 14:Đảo chiều
if(array.get(arrayXGann,0) == array.get(arrayXGann,1))
if(array.get(arrayXSGann,0) >= array.get(arrayXGann,2) and
array.get(arrayYSGann,0) != array.get(arrayYGann,1) and ((array.get(arrayYGann,1) >
array.get(arrayYGann,2) and array.get(arrayYSGann,0) > array.get(arrayYSGann,1)) or
(array.get(arrayYGann,1) < array.get(arrayYGann,2) and array.get(arrayYSGann,0) <
array.get(arrayYSGann,1))))
drawLineSGann1 := 12
array.set(arrayXSGann, 0, array.get(arrayXGann,1))
array.set(arrayYSGann, 0, array.get(arrayYGann,1))
else if(array.get(arrayXSGann,0) <= array.get(arrayXGann,2))
if((array.get(arrayYSGann,0) > array.get(arrayYSGann,1) and
array.get(arrayYGann,1) < array.get(arrayYSGann,1)) or (array.get(arrayYSGann,0) <
array.get(arrayYSGann,1) and array.get(arrayYGann,1) > array.get(arrayYSGann,1)))
drawLineSGann1 := 14
runCheckChoChSGann := true
array.unshift(arrayXSGann,array.get(arrayXGann,1))
array.unshift(arrayYSGann,array.get(arrayYGann,1))
else if((array.get(arrayYSGann,0) > array.get(arrayYSGann,1) and
array.get(arrayYGann,1) > array.get(arrayYSGann,0)) or (array.get(arrayYSGann,0) <
array.get(arrayYSGann,1) and array.get(arrayYGann,1) < array.get(arrayYSGann,0)))
drawLineSGann1 := 13
_max =
math.min(array.get(arrayYSGann,0),array.get(arrayYSGann,1))
_min =
math.max(array.get(arrayYSGann,0),array.get(arrayYSGann,1))
_max_idx = 0
_min_idx = 0
for i = 2 to array.size(arrayXGann)
if(array.get(arrayXSGann,0) >=
array.get(arrayXGann,i))
break
if(_min > array.get(arrayYGann,i))
_min := array.get(arrayYGann,i)
_min_idx := array.get(arrayXGann,i)
if(_max < array.get(arrayYGann,i))
_max := array.get(arrayYGann,i)
_max_idx := array.get(arrayXGann,i)
if(array.get(arrayYSGann,0) > array.get(arrayYSGann,1))
array.unshift(arrayXSGann,_min_idx)
array.unshift(arrayYSGann,_min)
else if(array.get(arrayYSGann,0) <
array.get(arrayYSGann,1))
array.unshift(arrayXSGann,_max_idx)
array.unshift(arrayYSGann,_max)
array.unshift(arrayXSGann,array.get(arrayXGann,1))
array.unshift(arrayYSGann,array.get(arrayYGann,1))

if(f_resInMinutes() < f_tfRes(customTF,f_resInMinutes()))


if(array.get(arrayYSGann,0) == array.get(arrayYGann,1) and
array.get(arrayXSGann,0) != array.get(arrayXGann,1))
array.set(arrayXSGann, 0, array.get(arrayXGann,1))
drawLineSGann1 := 19
if(f_resInMinutes() <= f_tfRes(customTF,f_resInMinutes()))
if(drawLineSGann1 == 12 or drawLineSGann1 == 19)
if(array.size(arrayLineSGann) >0)

line.set_xy2(array.get(arrayLineSGann,0),array.get(arrayXSGann,0),array.get(arrayYS
Gann,0))
else

array.unshift(arrayLineSGann,line.new(array.get(arrayXSGann,1),array.get(arrayYSGan
n,1),array.get(arrayXSGann,0),array.get(arrayYSGann,0), color = colorSGann,xloc =
xloc.bar_time,width = widthSGann, style = lineStyleSGann))
else if(drawLineSGann1 == 14)

array.unshift(arrayLineSGann,line.new(array.get(arrayXSGann,1),array.get(arrayYSGan
n,1),array.get(arrayXSGann,0),array.get(arrayYSGann,0), color = colorSGann,xloc =
xloc.bar_time,width = widthSGann,style = lineStyleSGann))
else if(drawLineSGann1 == 13)

array.unshift(arrayLineSGann,line.new(array.get(arrayXSGann,2),array.get(arrayYSGan
n,2),array.get(arrayXSGann,1),array.get(arrayYSGann,1), color = colorSGann,xloc =
xloc.bar_time,width = widthSGann,style = lineStyleSGann))

array.unshift(arrayLineSGann,line.new(array.get(arrayXSGann,1),array.get(arrayYSGan
n,1),array.get(arrayXSGann,0),array.get(arrayYSGann,0), color = colorSGann,xloc =
xloc.bar_time,width = widthSGann,style = lineStyleSGann))
else if(drawLineSGann1 == 15)
if(array.size(arrayLineSGann) >0)

line.set_xy2(array.get(arrayLineSGann,0),array.get(arrayXSGann,1),array.get(arrayYS
Gann,1))
else

array.unshift(arrayLineSGann,line.new(array.get(arrayXSGann,2),array.get(arrayYSGan
n,2),array.get(arrayXSGann,1),array.get(arrayYSGann,1), color = colorSGann,xloc =
xloc.bar_time,width = widthSGann,style = lineStyleSGann))

array.unshift(arrayLineSGann,line.new(array.get(arrayXSGann,1),array.get(arrayYSGan
n,1),array.get(arrayXSGann,0),array.get(arrayYSGann,0), color = colorSGann,xloc =
xloc.bar_time,width = widthSGann,style = lineStyleSGann))
if(runCheckChoChSGann)
runCheckChoChSGann := false
// ChoCh Trường hợp chữ N ngược, chữ N
if((array.get(arrayYSGann,3) > array.get(arrayYSGann,2) and
array.get(arrayYSGann,3) < array.get(arrayYSGann,1) and array.get(arrayYSGann,0) <
array.get(arrayYSGann,2)) or (array.get(arrayYSGann,3) < array.get(arrayYSGann,2)
and array.get(arrayYSGann,3) > array.get(arrayYSGann,1) and
array.get(arrayYSGann,0) > array.get(arrayYSGann,2)))
alert(syminfo.ticker + " : " + timeframe.period + "
=> Swing of Gann ChoCh" + (array.get(arrayYSGann,0) > array.get(arrayYSGann,1) ? "+
⇑" : "- ⇓"))
if(showChoCh)
array.unshift(arrayLineChoCh,line.new(x1=
array.get(arrayXSGann,2) , y1=array.get(arrayYSGann,2),x2=array.get(arrayXSGann,0),
y2=array.get(arrayYSGann,2),color = colorChoch,xloc = xloc.bar_time,style =
lineStyleChoch,width = widthChoch))
// ChoCh 2 Đầu Trường hợp chữ N ngược, chữ N
if(show2ChoCh and ((array.get(arrayYSGann,1) >
array.get(arrayYSGann,3) and array.get(arrayYSGann,3) > array.get(arrayYSGann,4)
and array.get(arrayYSGann,4) > array.get(arrayYSGann,2) and
array.get(arrayYSGann,2) > array.get(arrayYSGann,0)) or (array.get(arrayYSGann,0) >
array.get(arrayYSGann,2) and array.get(arrayYSGann,2) > array.get(arrayYSGann,4)
and array.get(arrayYSGann,4) > array.get(arrayYSGann,3) and
array.get(arrayYSGann,3) > array.get(arrayYSGann,1))))

line.set_width(array.get(arrayLineSGann,1),width2Choch)
line.set_style(array.get(arrayLineSGann,1),
lineStyle2Choch)

line.set_color(array.get(arrayLineSGann,1),color2Choch)

// drawLineSGann kiểm tra điểm 0 => 3:Tiếp tục có sóng hồi // 2|


9(reDraw):Tiếp tục không có sóng hồi // 4:Đảo chiều
if(array.get(arrayXSGann,0) >= array.get(arrayXGann,1) and
array.get(arrayYSGann,0) != array.get(arrayYGann,0) and ((array.get(arrayYGann,0) >
array.get(arrayYGann,1) and array.get(arrayYSGann,0) > array.get(arrayYSGann,1)) or
(array.get(arrayYGann,0) < array.get(arrayYGann,1) and array.get(arrayYSGann,0) <
array.get(arrayYSGann,1))))
drawLineSGann := 2
array.set(arrayXSGann, 0, array.get(arrayXGann,0))
array.set(arrayYSGann, 0, array.get(arrayYGann,0))
else if(array.get(arrayXSGann,0) <= array.get(arrayXGann,1))
if((array.get(arrayYSGann,0) > array.get(arrayYSGann,1) and
array.get(arrayYGann,0) < array.get(arrayYSGann,1)) or (array.get(arrayYSGann,0) <
array.get(arrayYSGann,1) and array.get(arrayYGann,0) > array.get(arrayYSGann,1)))
drawLineSGann := 4
runCheckChoChSGann := true
array.unshift(arrayXSGann,array.get(arrayXGann,0))
array.unshift(arrayYSGann,array.get(arrayYGann,0))
else if((array.get(arrayYSGann,0) > array.get(arrayYSGann,1) and
array.get(arrayYGann,0) > array.get(arrayYSGann,0)) or (array.get(arrayYSGann,0) <
array.get(arrayYSGann,1) and array.get(arrayYGann,0) < array.get(arrayYSGann,0)))
drawLineSGann := 3
_max =
math.min(array.get(arrayYSGann,0),array.get(arrayYSGann,1))
_min =
math.max(array.get(arrayYSGann,0),array.get(arrayYSGann,1))
_max_idx = 0
_min_idx = 0
for i = 1 to array.size(arrayXGann)
if(array.get(arrayXSGann,0) >= array.get(arrayXGann,i))
break
if(_min > array.get(arrayYGann,i))
_min := array.get(arrayYGann,i)
_min_idx := array.get(arrayXGann,i)
if(_max < array.get(arrayYGann,i))
_max := array.get(arrayYGann,i)
_max_idx := array.get(arrayXGann,i)
if(array.get(arrayYSGann,0) > array.get(arrayYSGann,1))
array.unshift(arrayXSGann,_min_idx)
array.unshift(arrayYSGann,_min)
else if(array.get(arrayYSGann,0) < array.get(arrayYSGann,1))
array.unshift(arrayXSGann,_max_idx)
array.unshift(arrayYSGann,_max)
array.unshift(arrayXSGann,array.get(arrayXGann,0))
array.unshift(arrayYSGann,array.get(arrayYGann,0))

if(f_resInMinutes() < f_tfRes(customTF,f_resInMinutes()))


if(array.get(arrayYSGann,0) == array.get(arrayYGann,0) and
array.get(arrayXSGann,0) != array.get(arrayXGann,0))
array.set(arrayXSGann, 0, array.get(arrayXGann,0))
drawLineSGann := 9
if(f_resInMinutes() <= f_tfRes(customTF,f_resInMinutes()))
if(drawLineSGann == 2 or drawLineSGann == 9)
if(array.size(arrayLineSGann) >0)

line.set_xy2(array.get(arrayLineSGann,0),array.get(arrayXSGann,0),array.get(arrayYS
Gann,0))
else

array.unshift(arrayLineSGann,line.new(array.get(arrayXSGann,1),array.get(arrayYSGan
n,1),array.get(arrayXSGann,0),array.get(arrayYSGann,0), color = colorSGann,xloc =
xloc.bar_time,width = widthSGann,style = lineStyleSGann))
else if(drawLineSGann == 4)

array.unshift(arrayLineSGann,line.new(array.get(arrayXSGann,1),array.get(arrayYSGan
n,1),array.get(arrayXSGann,0),array.get(arrayYSGann,0), color = colorSGann,xloc =
xloc.bar_time,width = widthSGann,style = lineStyleSGann))
else if(drawLineSGann == 3)

array.unshift(arrayLineSGann,line.new(array.get(arrayXSGann,2),array.get(arrayYSGan
n,2),array.get(arrayXSGann,1),array.get(arrayYSGann,1), color = colorSGann,xloc =
xloc.bar_time,width = widthSGann,style = lineStyleSGann))

array.unshift(arrayLineSGann,line.new(array.get(arrayXSGann,1),array.get(arrayYSGan
n,1),array.get(arrayXSGann,0),array.get(arrayYSGann,0), color = colorSGann,xloc =
xloc.bar_time,width = widthSGann,style = lineStyleSGann))
else if(drawLineSGann == 5)
if(array.size(arrayLineSGann) >0)

line.set_xy2(array.get(arrayLineSGann,0),array.get(arrayXSGann,1),array.get(arrayYS
Gann,1))
else

array.unshift(arrayLineSGann,line.new(array.get(arrayXSGann,2),array.get(arrayYSGan
n,2),array.get(arrayXSGann,1),array.get(arrayYSGann,1), color = colorSGann,xloc =
xloc.bar_time,width = widthSGann,style = lineStyleSGann))

array.unshift(arrayLineSGann,line.new(array.get(arrayXSGann,1),array.get(arrayYSGan
n,1),array.get(arrayXSGann,0),array.get(arrayYSGann,0), color = colorSGann,xloc =
xloc.bar_time,width = widthSGann,style = lineStyleSGann))

if(runCheckChoChSGann)
runCheckChoChSGann := false
// ChoCh Trường hợp chữ N ngược, chữ N
if((array.get(arrayYSGann,3) > array.get(arrayYSGann,2) and
array.get(arrayYSGann,3) < array.get(arrayYSGann,1) and array.get(arrayYSGann,0) <
array.get(arrayYSGann,2)) or (array.get(arrayYSGann,3) < array.get(arrayYSGann,2)
and array.get(arrayYSGann,3) > array.get(arrayYSGann,1) and
array.get(arrayYSGann,0) > array.get(arrayYSGann,2)))
alert(syminfo.ticker + " : " + timeframe.period + " =>
Swing of Gann ChoCh" + (array.get(arrayYSGann,0) > array.get(arrayYSGann,1) ? "+ ⇑"
: "- ⇓"))
if(showChoCh)
array.unshift(arrayLineChoCh,line.new(x1=
array.get(arrayXSGann,2) , y1=array.get(arrayYSGann,2),x2=array.get(arrayXSGann,0),
y2=array.get(arrayYSGann,2),color = colorChoch,xloc = xloc.bar_time,style =
lineStyleChoch,width = widthChoch))
// ChoCh 2 Đầu Trường hợp chữ N ngược, chữ N
if(show2ChoCh and ((array.get(arrayYSGann,1) >
array.get(arrayYSGann,3) and array.get(arrayYSGann,3) > array.get(arrayYSGann,4)
and array.get(arrayYSGann,4) > array.get(arrayYSGann,2) and
array.get(arrayYSGann,2) > array.get(arrayYSGann,0)) or (array.get(arrayYSGann,0) >
array.get(arrayYSGann,2) and array.get(arrayYSGann,2) > array.get(arrayYSGann,4)
and array.get(arrayYSGann,4) > array.get(arrayYSGann,3) and
array.get(arrayYSGann,3) > array.get(arrayYSGann,1))))
line.set_width(array.get(arrayLineSGann,1),width2Choch)
line.set_style(array.get(arrayLineSGann,1),lineStyle2Choch)
line.set_color(array.get(arrayLineSGann,1),color2Choch)

///////////////////////Other//////////////////////////////////
if(f_resInMinutes() <= f_tfRes(customTF,f_resInMinutes()))
if(showSGann)

if(showLabel and (barstate.islast or barstate.islastconfirmedhistory))


texLabel = f_resInMinutes() == f_tfRes(customTF,f_resInMinutes())
? f_resFromMinutes(f_resInMinutes()) :
f_resFromMinutes(f_tfRes(customTF,f_resInMinutes()))

label.set_xy(labelTF,array.get(arrayXSGann,0),array.get(arrayYSGann,0))
label.set_text(labelTF,texLabel)
label.set_style(labelTF,array.get(arrayYSGann,0) <
array.get(arrayYSGann,1) ? label.style_label_upper_right :
label.style_label_lower_right)
else if(showGann)
if(showLabel and (barstate.islast or barstate.islastconfirmedhistory))
texLabel = f_resInMinutes() == f_tfRes(customTF,f_resInMinutes())
? f_resFromMinutes(f_resInMinutes()) :
f_resFromMinutes(f_tfRes(customTF,f_resInMinutes()))

label.set_xy(labelTF,array.get(arrayXGann,0),array.get(arrayYGann,0))
label.set_text(labelTF,texLabel)
label.set_style(labelTF,array.get(arrayYGann,0) <
array.get(arrayYGann,1) ? label.style_label_upper_right :
label.style_label_lower_right)

You might also like