HighLowBox+220MAs[libHTF]
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © nazomobile
//@description HighLowBox+220MAs [libHTF]
//
//This is a sample script of libHTF: use HTF values without request.security().
//
// HTF candles are calculated internally using 'GMT+3' from current TF candles.
//To calcurate Higher TF candles, please display many past bars at first.
//The advantage and disadvantage is that the data can be generated at the current TF granularity.
//Although the signal can be displayed more sensitively, plots such as MAs are not smooth.
//
//In this script, assigned ➊,➋,➌,➍ for htf1,htf2,htf3,htf4.
//
// - HTF candles
// Draw candles for HTF1-4 on the right edge of the chart. 2 candles for each HTF.
//They are updated with every current TF bar update.
//Left edge of HTF candles is located at the x-postion latest bar_index + offset.
//
// - DMI HTF
// ADX/+DI/DI arrows(8lines) are shown each timeframes range.
//Current TF's is located at left side of the HighLowBox.
//HTF's are located at HighLowBox of HTF candles.
//The top of HighLowBox is 100, The bottom of HighLowBox is 0.
//
// - HighLowBox HTF
//Enclose in a square high and low range in each timeframe.
//Shows price range and duration of each box.
//
//In current timeframe, shows Fibonacci Scale inside(23.6%, 38.2%, 50.0%, 61.8%, 76.4%)/outside of each box.
//Outside(161.8%,261.8,361.8%) would be shown as next target, if break top/bottom of each box.
//In HTF, shows Fibonacci Level of the current price at latest box only.
//
//Boxes:
// .1 for current timeframe.
// .4 for higher timeframes.(Steps of timeframe: 5, 15, 60, 240, D, W, M, 3M, 6M, Y)
//
// - HighLowBox TrendLine
//Draw TrendLine for each HighLow Range. TrendLine is drawn between high and return high(or low and return low) of each HighLowBox.
//Style of TrendLine is same as each HighLowBox.
//
// - HighLowBox RSI
//
// RSI Signals are shown at the bottom(RSI<=30) or the top(RSI>=70) of HighLowBox in each timeframe.
//RSI Signal is color coded by RSI9 and RSI14 in each timeframe.(current TF: ●, HTF1-4: ➊➋➌➍)
//
//In case of RSI<=30,
//. Location: bottom of the HighLowBox
//.white: only RSI9 is <=30
//.aqua: RSI9&RSI14 <=30 and RSI9<RSI14
//.blue: RSI9&RSI14 <=30 and RSI9>RSI14
//.green: only RSI14 <=30
//In case of RSI>=70,
//.Location: top of the HighLowBox
//.white: only RSI9 is >=70
//.yellow: RSI9&RSI14 >=70 and RSI9>RSI14
//.orange: RSI9&RSI14 >=70 and RSI9<RSI14
//.red: only RSI14 >=70
//
//blue/green and orange/red could be a oversold/overbought sign.
// 
// - 20/200 MAs
// Shows 20 and 200 MAs in each TFs(tfChart and 4 Higher).
//
//TFs:
//current TF
//HTF1-4
//MAs:
//20SMA
//20EMA
//200SMA
//200EMA
//
//@version=5
indicator(title="HighLowBox+220MAs[libHTF]",shorttitle="HiLo+220MA",overlay=true,explicit_plot_zorder=true,max_lines_count=500,max_labels_count=500,max_boxes_count=500)
import nazomobile/libHTFwoRS/2 as H


//*****
//colors
//*****
colorSMA=color.new(color.aqua,5)
colorEMA=color.new(color.yellow,5)
colorRMA=color.new(#ffe4e1,5)

colorLabelText=color.new(color.white,60)

colorBoxT=color.new(color.white,5)
colorBoxU=color.new(#aaffaa,5)
colorBoxD=color.new(#ffaaaa,5)

//minimap colors(exprimental) 
colorMinimap_middle_low= color.new(color.orange,20)
colorMinimap_low=color.new(color.red,60)
colorMinimap_low2=color.new(color.red,40)
colorMinimap_break_bottom=color.new(color.red,20)
colorMinimap_middle_high=color.new(color.yellow,20)
colorMinimap_high=color.new(color.blue,60)
colorMinimap_high2=color.new(color.blue,40)
colorMinimap_break_top=color.new(color.blue,20)

colorRSIi=color.new(color.white,5)
colorRSIt1=color.new(color.yellow,5)
colorRSIt2=color.new(color.orange,5)
colorRSIt3=color.new(color.red,5)
colorRSIb1=color.new(color.aqua,5)
colorRSIb2=color.new(color.blue,5)
colorRSIb3=color.new(color.green,5)

colorTLresistance=color.new(#ba55d3,20)
colorTLsupport=color.new(#7b68ee,20)

colorCandleU =color.new(#53b987,20)
colorCandleD =color.new(#eb4d5c,20)
colorCandleT =color.new(color.white,20)
//*****
//end of colors
//*****

//*****
//functions
//*****
l00="solid",l01="dashed",l02="dotted"
f_linestyle (x) => x==l00?line.style_solid: x==l01?line.style_dashed: x==l02?line.style_dotted:na
s00="auto",s01="huge",s02="large",s03="normal",s04="small",s05="tiny"
f_textsize (x) => x==s00?size.auto: x==s01?size.huge: x==s02?size.large: x==s03?size.normal: x==s04?size.small: x==s05?size.tiny:na
p01="top_left",p02="top_center",p03="top_right",p04="middle_left",p05="middle_center",p06="middle_right",p07="bottom_left",p08="bottom_center",p09="bottom_right"
f_position(x) =>
 x==p01?position.top_left: x==p02?position.top_center: x==p03?position.top_right:
 x==p04?position.middle_left: x==p05?position.middle_center: x==p06?position.middle_right:
 x==p07?position.bottom_left: x==p08?position.bottom_center: x==p09?position.bottom_right:na
ps00="steplinebr",ps01="line",ps02="linebr",ps03="stepline",ps04="stepline_diamond",ps05="histogram",ps06="areabr",ps07="cross",ps08="columns",ps09="circles"
f_plotstyle(x) =>
 x==ps00?plot.style_steplinebr: x==ps01?plot.style_line: x==ps02?plot.style_linebr: x==ps03?plot.style_stepline: x==ps04?plot.style_stepline_diamond:
 x==ps05?plot.style_histogram: x==ps06?plot.style_areabr: x==ps07?plot.style_cross: x==ps08?plot.style_columns: x==ps09?plot.style_circles:na

// t00,t01,t02,t03,t04,t05,t06,t07,t08,t09,t10,t11,t12,t13,t14,t15
t00="Chart", t01="1", t02="3", t03="5", t04="15", t05="30",t06="60",t07="120", t08="180",t09="240",
t10="D", t11='W',t12="M",t13="3M", t14="6M",t15="Y"
b_tfgt(_tfa,_tfb) => timeframe.in_seconds(_tfa)>timeframe.in_seconds(_tfb)
b_tflt(_tfa,_tfb) => timeframe.in_seconds(_tfa)<timeframe.in_seconds(_tfb)

f_line_delete_all (_array) =>
    if array.size(_array)>0
        for i = 0 to array.size(_array)-1
            line.delete(array.get(_array,i))

f_fibo(a,z) =>
    diff = z-a
    [z-diff*3.618,z-diff*2.618,z-diff*1.618,
     a+diff*0.236,a+diff*0.382,a+diff*0.5,a+diff*0.618,a+diff*0.786,
     a+diff*1.618,a+diff*2.618,a+diff*3.618]

f_fibo_range(a,z,x) =>
    diff = z-a
    _rti=-1
    _rbi=-1
    listfibo = array.from(z-diff*3.618,z-diff*2.618,z-diff*1.618,a,a+diff*0.236,a+diff*0.382,a+diff*0.5,a+diff*0.618,a+diff*0.786,z,a+diff*1.618,a+diff*2.618,a+diff*3.618)
    s_listfibo = array.from("3.618fromT","2.618fromT","1.618fromT","____Bottom","0.236fromB","0.382fromB","____Center","0.382fromT","0.236fromT","_______Top","1.618fromB","2.618fromB","3.618fromB")
    for i = 0 to array.size(listfibo)-1
        if x<array.get(listfibo,i)
            _rti:=i
            break
    for i = array.size(listfibo)-1 to 0
        if x>array.get(listfibo,i)
            _rbi:=i
            break
    [_rti==-1?na:array.get(listfibo,_rti),_rti==-1?na:array.get(s_listfibo,_rti),
     _rbi==-1?na:array.get(listfibo,_rbi),_rbi==-1?na:array.get(s_listfibo,_rbi)]

f_time_ddhhmm (_t)=>
    _s=1000
    _m=60*_s
    _h=60*_m
    _d=24*_h
    _sec = _t
    _day = int(_sec/_d)
    _mod = _sec%_d
    _hour= int(_mod/_h)
    _mod:= _mod%_h
    _min = int(_mod/_m)
    (_day>0?str.tostring(_day,"00")+"d":"")+str.tostring(_hour,"00")+"h"+str.tostring(_min,"00")+"m"

f_draw_candle (_open,_close,_high,_low,_x1,_x2,_text,_colorUP,_colorDN,_colorT) =>
    _c = _open<_close?_colorUP:_colorDN
    _t = _open>_close?_open:_close
    _b = _open>_close?_close:_open
    _center=int((_x1+_x2)/2)
    [box.new(_x1,_t,_x2,_b,xloc=xloc.bar_time,border_color=_c,bgcolor=_c,text=_text,text_color=_colorT,text_size=size.normal),
     line.new(_center,_high,_center,_low,xloc=xloc.bar_time,color=_c,width=2)]
f_draw_candle_barindex (_open,_close,_high,_low,_offset,_x,_text,_colorUP,_colorDN,_colorT) =>
    _c = _open<_close?_colorUP:_colorDN
    _t = _open>_close?_open:_close
    _b = _open>_close?_close:_open
    _x1 = _offset+_x
    _x2 = _offset+_x+2
    _center=int((_x1+_x2)/2)
    _h=_high<=_t?na:_high
    _l=_low>=_b?na:_low
    [box.new(_x1,_t,_x2,_b,xloc=xloc.bar_index,border_color=_c,bgcolor=_c,text=_text,text_color=_colorT,text_size=size.normal),
     line.new(_center,_h,_center,_t,xloc=xloc.bar_index,color=_c,width=2),
     line.new(_center,_l,_center,_b,xloc=xloc.bar_index,color=_c,width=2)
     ]

f_madev(val, ma) => (val - ma) / ma * 100
s_madev(val, ma) => str.tostring(val-ma,"0.0000")+"("+str.tostring(math.round(f_madev(val,ma),2))+"%)"

f_ma_label (_s,_offset,_tf,_span,_type,_color,_b) =>
    tp=s_madev(close,_s)
    info=_b?":"+tp:""
    na(_s)?na:label.new(x=bar_index+_offset,y=_s,
     text=_tf+": "+str.tostring(_span)+_type+info,style=label.style_none,textcolor=_color,textalign=text.align_left,tooltip=tp)

//*****
//end of functions
//*****

group_HTF='HTFlib'
TZ = input.string(defval="GMT+3", title="TZ for calculating HTF",options=["GMT+2","GMT+3"],group=group_HTF)
tooltip_HTF='Steps of timeframe:\n[1, 5, 15, 60, 240, D, W, M, 3M, 6M, Y]\n'
symbol_htf1 = input.string(defval="➊", title="Symbol for HTF1 (HigherTF of current Chart)",group=group_HTF,tooltip=tooltip_HTF)
symbol_htf2 = input.string(defval="➋", title="Symbol for HTF2 (HigherTF of HTF1)",group=group_HTF,tooltip=tooltip_HTF)
symbol_htf3 = input.string(defval="➌", title="Symbol for HTF3 (HigherTF of HTF2)",group=group_HTF,tooltip=tooltip_HTF)
symbol_htf4 = input.string(defval="➍", title="Symbol for HTF4 (HigherTF of HTF3)",group=group_HTF,tooltip=tooltip_HTF)
tooltip_SRC='Data soruce for HTFlib'
sr0="open",sr1="high",sr2="low",sr3="close",sr4="hl2",sr5="hlc3",sr6="ohlc4",sr7="hlcc4"
_src = input.string(title="src", defval=sr7,options=[sr0,sr1,sr2,sr3,sr4,sr5,sr6,sr7],group=group_HTF, tooltip=tooltip_SRC)
tooltip_bartime_price='true: The price of peak/bottom is set by price of latest bar\nfalse: The price of peak/bottom is set by comparison of "last close" and "current open"'
b_bartime_price = input.bool(defval=true,title="prioritize latest bars for peak/bottom instead of actural price.",group=group_HTF,tooltip=tooltip_bartime_price)

var tfChart = timeframe.period
var string htf1 = H.tf_higher(tfChart)
var string htf2 = H.tf_higher(htf1)
var string htf3 = H.tf_higher(htf2)
var string htf4 = H.tf_higher(htf3)

b_new_bar=ta.change(time)
[b_new_bar1,m1]=H.htf_candle(htf1)
[b_new_bar2,m2]=H.htf_candle(htf2)
[b_new_bar3,m3]=H.htf_candle(htf3)
[b_new_bar4,m4]=H.htf_candle(htf4)

[i_renew,a_high,a_time_high,a_return_high,a_time_return_high,a_low,a_time_low,a_return_low,a_time_return_low] =
 H.highlow(b_bartime_price)
[i_renew1,a_high1,a_time_high1,a_return_high1,a_time_return_high1,a_low1,a_time_low1,a_return_low1,a_time_return_low1] =
 H.htfhighlow(m1,b_bartime_price)
[i_renew2,a_high2,a_time_high2,a_return_high2,a_time_return_high2,a_low2,a_time_low2,a_return_low2,a_time_return_low2] =
 H.htfhighlow(m2,b_bartime_price)
[i_renew3,a_high3,a_time_high3,a_return_high3,a_time_return_high3,a_low3,a_time_low3,a_return_low3,a_time_return_low3] =
 H.htfhighlow(m3,b_bartime_price)
[i_renew4,a_high4,a_time_high4,a_return_high4,a_time_return_high4,a_low4,a_time_low4,a_return_low4,a_time_return_low4] =
 H.htfhighlow(m4,b_bartime_price)

src=H.set_src(_src)
htf1src=H.set_htfsrc(_src,b_new_bar1,m1)
htf2src=H.set_htfsrc(_src,b_new_bar2,m2)
htf3src=H.set_htfsrc(_src,b_new_bar3,m3)
htf4src=H.set_htfsrc(_src,b_new_bar4,m4)

group_HTF_candle='HTF Candles'
tooltip_HTF_candle='Draw candles for HTF1-4 on the right edge of the chart.\n2 candles for each HTF.'
tooltip_HTF_candle_offset='Left edge of HTF candles is located at the x-postion latest bar_index + offset.'
b_fake_candle = input.bool(defval=true,title="show HTF Candles",inline="HTFcandle",group=group_HTF_candle, tooltip=tooltip_HTF_candle)
i_offset_candle = input.int(defval=15,title="offset of HTF candles",inline="HTCcandle",group=group_HTF_candle,tooltip=tooltip_HTF_candle_offset)
trans_candle = input.int(defval=40,minval=0,maxval=99,title="transpar",inline="text",group=group_HTF_candle)
cCandleU = input.color(defval=colorCandleU,title="Bullish",inline="color",group=group_HTF_candle)
cCandleD = input.color(defval=colorCandleD,title="Bearish",inline="color",group=group_HTF_candle)
cCandleT = input.color(defval=colorCandleT,title="Text",inline="color",group=group_HTF_candle)

group_DMI='DMI'
b_DMI = input.bool(defval=true,title="show DMI",inline="DMI",group=group_DMI)
cADX = input.color(defval=color.gray,title="ADX",inline="color",group=group_DMI)
cDI = input.color(defval=color.green,title="+DI",inline="color",group=group_DMI)
c_DI = input.color(defval=color.red,title="-DI",inline="color",group=group_DMI)

group_HLBOX='HighLowBox'

_cBoxU = input.color(defval=colorBoxU,title="newHigh",inline="color",group=group_HLBOX)
_cBoxD = input.color(defval=colorBoxD,title="newLow",inline="color",group=group_HLBOX)
_cBoxT = input.color(defval=colorBoxT,title="text",inline="color",group=group_HLBOX)
b_info = input.bool(defval=true,title="range info",inline="text",group=group_HLBOX)
transInfo = input.int(defval=30,minval=0,maxval=99,title="transpar",inline="text",group=group_HLBOX)
_infoSize = input.string(defval=s04,options=[s01,s02,s03,s04,s05],title="size",inline="text",group=group_HLBOX)
infoSize = f_textsize(_infoSize)
cBoxT = color.new(_cBoxT,transInfo)

tooltip_max_boxes='Max # of boxes@Current TF. 0 is no limit. Only 500 boxes can be shown in this script.'
group_HLBOX_ctf="HighLowBox@Current TF"
show0 = input.bool(defval=true,title="CTF",inline="Box",group=group_HLBOX_ctf)
transBox = input.int(defval=40,minval=0,maxval=99,title="transpar",inline="Box",group=group_HLBOX_ctf)
cBoxU=color.new(_cBoxU,transBox)
cBoxD=color.new(_cBoxD,transBox)
widthBox = input.int(defval=1,minval=1,maxval=4,title="width",inline="Box",group=group_HLBOX_ctf)
_styleBox = input.string(defval=l01,options=[l00,l01,l02],title="box style",inline="Box",group=group_HLBOX_ctf)
styleBox = f_linestyle(_styleBox)
tooltip_HLBOX_fill_box='Fill the HighLowBox(only current TF).'
b_fibo = input.bool(defval=true,title="show fibonacci scale",inline="fibo",group=group_HLBOX_ctf)
b_fibo_clear = input.bool(defval=true,title="delete fibonacci scale in past range",inline="fibo",group=group_HLBOX_ctf)
i_maxBoxes = input.int(defval=100,minval=0,maxval=500,title="max# of Boxes",inline="Box",group=group_HLBOX_ctf,tooltip=tooltip_max_boxes)

group_HLBOX_htf="HighLowBox@HTF"
show1 = input.bool(defval=true,title="HTF1",group=group_HLBOX_htf)
transBox1 = input.int(defval=45,minval=0,maxval=99,title="transpar",inline="tfH1",group=group_HLBOX_htf)
cBoxU1=color.new(_cBoxU,transBox1)
cBoxD1=color.new(_cBoxD,transBox1)
widthBox1 = input.int(defval=2,minval=1,maxval=4,title="width",inline="tfH1",group=group_HLBOX_htf)
_styleBox1 = input.string(defval=l00,options=[l00,l01,l02],title="box style",inline="tfH1",group=group_HLBOX_htf)
styleBox1 = f_linestyle(_styleBox1)
b_fibo1 = input.bool(defval=true,title="show fibonacci level",inline="tfH1",group=group_HLBOX_htf)

show2 = input.bool(defval=true,title="HTF2",group=group_HLBOX_htf)
transBox2 = input.int(defval=50,minval=0,maxval=99,title="transpar",inline="tfH2",group=group_HLBOX_htf)
cBoxU2=color.new(_cBoxU,transBox2)
cBoxD2=color.new(_cBoxD,transBox2)
widthBox2 = input.int(defval=4,minval=1,maxval=4,title="width",inline="tfH2",group=group_HLBOX_htf)
_styleBox2 = input.string(defval=l01,options=[l00,l01,l02],title="box style",inline="tfH2",group=group_HLBOX_htf)
styleBox2 = f_linestyle(_styleBox2)
b_fibo2 = input.bool(defval=true,title="show fibonacci level",inline="tfH2",group=group_HLBOX_htf)

show3 = input.bool(defval=true,title="HTF3",group=group_HLBOX_htf)
transBox3 = input.int(defval=55,minval=0,maxval=99,title="transpar",inline="tfH3",group=group_HLBOX_htf)
cBoxU3=color.new(_cBoxU,transBox3)
cBoxD3=color.new(_cBoxD,transBox3)
widthBox3 = input.int(defval=4,minval=1,maxval=4,title="width",inline="tfH3",group=group_HLBOX_htf)
_styleBox3 = input.string(defval=l00,options=[l00,l01,l02],title="box style",inline="tfH3",group=group_HLBOX_htf)
styleBox3 = f_linestyle(_styleBox3)
b_fibo3 = input.bool(defval=true,title="show fibonacci level",inline="tfH3",group=group_HLBOX_htf)

show4 = input.bool(defval=true,title="HTF4",group=group_HLBOX_htf)
transBox4 = input.int(defval=60,minval=0,maxval=99,title="transpar",inline="tfH4",group=group_HLBOX_htf)
cBoxU4=color.new(_cBoxU,transBox4)
cBoxD4=color.new(_cBoxD,transBox4)
widthBox4 = input.int(defval=4,minval=1,maxval=4,title="width",inline="tfH4",group=group_HLBOX_htf)
_styleBox4 = input.string(defval=l02,options=[l00,l01,l02],title="box style",inline="tfH4",group=group_HLBOX_htf)
styleBox4 = f_linestyle(_styleBox4)
b_fibo4 = input.bool(defval=true,title="show fibonacci level",inline="tfH4",group=group_HLBOX_htf)

group_HLBOX_tl="HighLowBox TrendLine"
b_TL = input.bool(defval=true,title="show trend line",inline="TL",group=group_HLBOX_tl)
b_TL_clear = input.bool(defval=true,title="delete lines in past range",inline="TL",group=group_HLBOX_tl)
b_TL_obsolete = input.bool(defval=true,title="delete obsolete TL",inline="TL",group=group_HLBOX_tl)
transTL = input.int(defval=80,minval=0,maxval=99,title="obsolete TL transpar",inline="TL",group=group_HLBOX_tl)
cTLr = input.color(defval=colorTLresistance,title="bearish line",inline="TL",group=group_HLBOX_tl)
cTLs = input.color(defval=colorTLsupport,title="bullish line",inline="TL",group=group_HLBOX_tl)
cTLro =color.new(cTLr,transTL)
cTLso =color.new(cTLs,transTL)

//*****
//HighLowBox
//*****

//current tf box
var mybox=box.new(na,na,na,na,xloc=xloc.bar_time,bgcolor=na,border_color=na)
var a_tl_resistance=array.new_line(0,na)
var a_tl_support=array.new_line(0,na)
var a_mybox=array.new_box(0,na)

var myfibo23=line.new(na,na,na,na,xloc=xloc.bar_time)
var myfibo38=line.new(na,na,na,na,xloc=xloc.bar_time)
var myfibo50=line.new(na,na,na,na,xloc=xloc.bar_time)
var myfibo61=line.new(na,na,na,na,xloc=xloc.bar_time)
var myfibo78=line.new(na,na,na,na,xloc=xloc.bar_time)
var myfibo161=label.new(na,na,na,xloc=xloc.bar_time,style=label.style_none)
var myfibo261=label.new(na,na,na,xloc=xloc.bar_time,style=label.style_none)
var myfibo361=label.new(na,na,na,xloc=xloc.bar_time,style=label.style_none)
var myfibom161=label.new(na,na,na,xloc=xloc.bar_time,style=label.style_none)
var myfibom261=label.new(na,na,na,xloc=xloc.bar_time,style=label.style_none)
var myfibom361=label.new(na,na,na,xloc=xloc.bar_time,style=label.style_none)

var i_breakT=0
var i_breakf161=0
var i_breakf261=0
var i_breakB=0
var i_breakfm161=0
var i_breakfm261=0

i_peak_bottom =H.peak_bottom(H.is_up(),H.last_is_up())

top= a_high.lastx()
top_time=  a_time_high.lastx()
bottom= a_low.lastx()
bottom_time= a_time_low.lastx()

c_box=bottom_time<top_time?cBoxU:cBoxD

_h = array.from(int(top_time),int(bottom_time))
_v = array.from(top,bottom)
_t = array.max(_v)
_b = array.min(_v)
_l = array.min(_h)

[fm361,fm261,fm161,f23,f38,f50,f61,f78,f161,f261,f361] = f_fibo(_b,_t)

if show0 and i_renew!=0
    if b_TL_clear
        f_line_delete_all(a_tl_resistance)
        f_line_delete_all(a_tl_support)
    if array.size(a_tl_resistance)>0
        line.set_extend(array.last(a_tl_resistance),extend.none)
        array.clear(a_tl_resistance)
    if array.size(a_tl_support)>0
        line.set_extend(array.last(a_tl_support),extend.none)
        array.clear(a_tl_support)

    mybox:=box.new(_l,na,na,na,xloc=xloc.bar_time,border_width=widthBox,text_halign=text.align_center,text_size=infoSize,
     border_color=c_box,text_color=cBoxT,bgcolor=na,border_style=styleBox)
    array.push(a_mybox,mybox)
    if i_maxBoxes >0 and array.size(a_mybox)>i_maxBoxes
        box.delete(array.shift(a_mybox))

    if b_fibo
        if b_fibo_clear
            line.delete(myfibo23)
            line.delete(myfibo38)
            line.delete(myfibo50)
            line.delete(myfibo61)
            line.delete(myfibo78)
            label.delete(myfibo161),label.delete(myfibo261),label.delete(myfibo361)
            label.delete(myfibom161),label.delete(myfibom261),label.delete(myfibom361)
        myfibo23:=line.new(_l,f23,na,f23,xloc.bar_time,extend.none,c_box,line.style_dashed,1)
        myfibo38:=line.new(_l,f38,na,f38,xloc.bar_time,extend.none,c_box,line.style_dashed,1)
        myfibo50:=line.new(_l,f50,na,f50,xloc.bar_time,extend.none,c_box,line.style_solid,1)
        myfibo61:=line.new(_l,f61,na,f61,xloc.bar_time,extend.none,c_box,line.style_dashed,1)
        myfibo78:=line.new(_l,f78,na,f78,xloc.bar_time,extend.none,c_box,line.style_dashed,1)
        myfibo161:=label.new(na,f161,"___1.618:"+str.tostring(f161,"#.0000")+"___",xloc.bar_time,yloc.price,c_box,label.style_none,c_box,infoSize)
        myfibo261:=label.new(na,f261,"___2.618:"+str.tostring(f261,"#.0000")+"___",xloc.bar_time,yloc.price,c_box,label.style_none,c_box,infoSize)
        myfibo361:=label.new(na,f361,"___3.618:"+str.tostring(f361,"#.0000")+"___",xloc.bar_time,yloc.price,c_box,label.style_none,c_box,infoSize)
        myfibom161:=label.new(na,fm161,"___1.618:"+str.tostring(fm161,"#.0000")+"___",xloc.bar_time,yloc.price,c_box,label.style_none,c_box,infoSize)
        myfibom261:=label.new(na,fm261,"___2.618:"+str.tostring(fm261,"#.0000")+"___",xloc.bar_time,yloc.price,c_box,label.style_none,c_box,infoSize)
        myfibom361:=label.new(na,fm361,"___3.618:"+str.tostring(fm361,"#.0000")+"___",xloc.bar_time,yloc.price,c_box,label.style_none,c_box,infoSize)
    else
        label.delete(myfibo161),label.delete(myfibo261),label.delete(myfibo361)
        label.delete(myfibom161),label.delete(myfibom261),label.delete(myfibo361)
    i_breakT:=0
    i_breakB:=0
    i_breakf161:=0
    i_breakf261:=0
    i_breakfm161:=0
    i_breakfm261:=0
else if show0 and i_peak_bottom==1 and b_TL
    if (array.size(a_high)>0)
        if array.size(a_tl_resistance)
            if b_TL_obsolete
                f_line_delete_all(a_tl_resistance)
            else
                line.set_style(array.last(a_tl_resistance),line.style_dotted)
                line.set_extend(array.last(a_tl_resistance),extend.none)
                line.set_color(array.last(a_tl_resistance),cTLro)
        if a_high.lastx()!=a_return_high.lastx()
            array.push(a_tl_resistance,line.new(
             a_time_high.lastx(),
             a_high.lastx(),
             a_time_return_high.lastx(),
             a_return_high.lastx(),
             xloc.bar_time,extend.right,cTLr,styleBox,widthBox))
else if show0 and i_peak_bottom==-1 and b_TL
    if (array.size(a_low)>0)
        if array.size(a_tl_support)
            if b_TL_obsolete
                f_line_delete_all(a_tl_support)
            else
                line.set_style(array.last(a_tl_support),line.style_dotted)
                line.set_extend(array.last(a_tl_support),extend.none)
                line.set_color(array.last(a_tl_support),cTLso)
        if a_low.lastx()!=a_return_low.lastx()
            array.push(a_tl_support,line.new(
             a_time_low.lastx(),
             a_low.lastx(),
             a_time_return_low.lastx(),
             a_return_low.lastx(),
             xloc.bar_time,extend.right,cTLs,styleBox,widthBox))

i_breakT+=high>_t?1:0
i_breakB+=low<_t?1:0
i_breakf161+=high>f161?1:0
i_breakf261+=high>f261?1:0
i_breakfm161+=low<fm161?1:0
i_breakfm261+=low<fm261?1:0

if show0
    box.set_right(mybox,time_close)
    box.set_bottom(mybox,_b)
    box.set_top(mybox,_t)
    box.set_text(mybox,
     b_info?
      "TF="+tfChart+":"+f_time_ddhhmm(box.get_right(mybox)-box.get_left(mybox))+":"+
      str.tostring(math.abs(box.get_top(mybox)-box.get_bottom(mybox))):na)

    line.set_x2(myfibo23,time_close)
    line.set_x2(myfibo38,time_close)
    line.set_x2(myfibo50,time_close)
    line.set_x2(myfibo61,time_close)
    line.set_x2(myfibo78,time_close)

    if i_breakT>0
        label.set_xy(myfibo161,(_l+time_close)/2,f161)
    if i_breakf161>0
        label.set_xy(myfibo261,(_l+time_close)/2,f261)
    if i_breakf261>0
        label.set_xy(myfibo361,(_l+time_close)/2,f361)
    if i_breakB>0
        label.set_xy(myfibom161,(_l+time_close)/2,fm161)
    if i_breakfm161>0
        label.set_xy(myfibom261,(_l+time_close)/2,fm261)
    if i_breakfm261>0
        label.set_xy(myfibom361,(_l+time_close)/2,fm361)

//box htf1
var mybox1=box.new(na,na,na,na,xloc=xloc.bar_time,bgcolor=na,border_color=na)
var a_tl_resistance1=array.new_line(0,na)
var a_tl_support1=array.new_line(0,na)

i_peak_bottom1 =H.peak_bottom(H.htf_is_up(m1),H.htf_last_is_up(m1))

top1= a_high1.lastx()
top_time1=  a_time_high1.lastx()
bottom1= a_low1.lastx()
bottom_time1= a_time_low1.lastx()

c_box1=bottom_time1<top_time1?cBoxU1:cBoxD1
va1=bottom_time1<top_time1?text.align_top:text.align_bottom

_h1 = array.from(int(top_time1),int(bottom_time1))
_v1 = array.from(top1,bottom1)
_t1 = array.max(_v1)
_b1 = array.min(_v1)
_l1 = array.min(_h1)

if show1 and i_renew1!=0
    if b_TL_clear
        f_line_delete_all(a_tl_resistance1)
        f_line_delete_all(a_tl_support1)
    if array.size(a_tl_resistance1)>0
        line.set_extend(array.last(a_tl_resistance1),extend.none)
        array.clear(a_tl_resistance1)
    if array.size(a_tl_support1)>0
        line.set_extend(array.last(a_tl_support1),extend.none)
        array.clear(a_tl_support1)
    if not (_l1[1]==_l1 and (_b1[1]==_b1 or _t1[1]==_t1))
        mybox1:=box.new(_l1,na,na,na,xloc=xloc.bar_time,bgcolor=na,border_width=widthBox1,border_style=styleBox1,
         text_halign=text.align_right,text_valign=va1,text_size=infoSize,border_color=c_box1,text_color=cBoxT)
else if show1 and i_peak_bottom1==1 and b_TL
    if (array.size(a_high1)>0)
        if array.size(a_tl_resistance1)
            if b_TL_obsolete
                f_line_delete_all(a_tl_resistance1)
            else
                line.set_style(array.last(a_tl_resistance1),line.style_dotted)
                line.set_extend(array.last(a_tl_resistance1),extend.none)
                line.set_color(array.last(a_tl_resistance1),cTLro)
        if a_high1.lastx()!=a_return_high1.lastx()
            array.push(a_tl_resistance1,line.new(
             a_time_high1.lastx(),
             a_high1.lastx(),
             a_time_return_high1.lastx(),
             a_return_high1.lastx(),
             xloc.bar_time,extend.right,cTLr,styleBox1,widthBox1))
else if show1 and i_peak_bottom1==-1 and b_TL
    if (array.size(a_low1)>0)
        if array.size(a_tl_support1)
            if b_TL_obsolete
                f_line_delete_all(a_tl_support1)
            else
                line.set_style(array.last(a_tl_support1),line.style_dotted)
                line.set_extend(array.last(a_tl_support1),extend.none)
                line.set_color(array.last(a_tl_support1),cTLso)
        if a_low1.lastx()!=a_return_low1.lastx()
            array.push(a_tl_support1,line.new(
             a_time_low1.lastx(),
             a_low1.lastx(),
             a_time_return_low1.lastx(),
             a_return_low1.lastx(),
             xloc.bar_time,extend.right,cTLs,styleBox1,widthBox1))

if show1
    box.set_right(mybox1,int(m1.lastx("time_close")))
    box.set_bottom(mybox1,_b1)
    box.set_top(mybox1,_t1)
    box.set_text(mybox1,b_info?"TF"+symbol_htf1+"="+htf1+"\n"+
     f_time_ddhhmm(box.get_right(mybox1)-box.get_left(mybox1))+"\n"+
     str.tostring(math.abs(box.get_top(mybox1)-box.get_bottom(mybox1))):na)

//box htf2
var mybox2=box.new(na,na,na,na,xloc=xloc.bar_time,bgcolor=na,border_color=na)
var a_tl_resistance2=array.new_line(0,na)
var a_tl_support2=array.new_line(0,na)

i_peak_bottom2 =H.peak_bottom(H.htf_is_up(m2),H.htf_last_is_up(m2))

top2= a_high2.lastx()
top_time2=  a_time_high2.lastx()
bottom2= a_low2.lastx()
bottom_time2= a_time_low2.lastx()

c_box2=bottom_time2<top_time2?cBoxU2:cBoxD2
va2=bottom_time2<top_time2?text.align_top:text.align_bottom

_h2 = array.from(int(top_time2),int(bottom_time2))
_v2 = array.from(top2,bottom2)
_t2 = array.max(_v2)
_b2 = array.min(_v2)
_l2 = array.min(_h2)

if show2 and i_renew2!=0
    if b_TL_clear
        f_line_delete_all(a_tl_resistance2)
        f_line_delete_all(a_tl_support2)
    if array.size(a_tl_resistance2)>0
        line.set_extend(array.last(a_tl_resistance2),extend.none)
        array.clear(a_tl_resistance2)
    if array.size(a_tl_support2)>0
        line.set_extend(array.last(a_tl_support2),extend.none)
        array.clear(a_tl_support2)
    if not (_l2[1]==_l2 and (_b2[1]==_b2 or _t2[1]==_t2))
        mybox2:=box.new(_l2,na,na,na,xloc=xloc.bar_time,bgcolor=na,border_width=widthBox2,border_style=styleBox2,
         text_halign=text.align_right,text_valign=va2,text_size=infoSize,border_color=c_box2,text_color=cBoxT)
else if show2 and i_peak_bottom2==1 and b_TL
    if (array.size(a_high2)>0)
        if array.size(a_tl_resistance2)
            if b_TL_obsolete
                f_line_delete_all(a_tl_resistance2)
            else
                line.set_style(array.last(a_tl_resistance2),line.style_dotted)
                line.set_extend(array.last(a_tl_resistance2),extend.none)
                line.set_color(array.last(a_tl_resistance2),cTLro)
        if a_high2.lastx()!=a_return_high2.lastx()
            array.push(a_tl_resistance2,line.new(
             a_time_high2.lastx(),
             a_high2.lastx(),
             a_time_return_high2.lastx(),
             a_return_high2.lastx(),
             xloc.bar_time,extend.right,cTLr,styleBox2,widthBox2))
else if show2 and i_peak_bottom2==-1 and b_TL
    if (array.size(a_low2)>0)
        if array.size(a_tl_support2)
            if b_TL_obsolete
                f_line_delete_all(a_tl_support2)
            else
                line.set_style(array.last(a_tl_support2),line.style_dotted)
                line.set_extend(array.last(a_tl_support2),extend.none)
                line.set_color(array.last(a_tl_support2),cTLso)
        if a_low2.lastx()!=a_return_low2.lastx()
            array.push(a_tl_support2,line.new(
             a_time_low2.lastx(),
             a_low2.lastx(),
             a_time_return_low2.lastx(),
             a_return_low2.lastx(),
             xloc.bar_time,extend.right,cTLs,styleBox2,widthBox2))

if show2
    box.set_right(mybox2,int(m2.lastx("time_close")))
    box.set_bottom(mybox2,_b2)
    box.set_top(mybox2,_t2)
    box.set_text(mybox2,b_info?"TF"+symbol_htf2+"="+htf2+"\n"+
     f_time_ddhhmm(box.get_right(mybox2)-box.get_left(mybox2))+"\n"+
     str.tostring(math.abs(box.get_top(mybox2)-box.get_bottom(mybox2))):na)

//box htf3
var mybox3=box.new(na,na,na,na,xloc=xloc.bar_time,bgcolor=na,border_color=na)
var a_tl_resistance3=array.new_line(0,na)
var a_tl_support3=array.new_line(0,na)

i_peak_bottom3 =H.peak_bottom(H.htf_is_up(m3),H.htf_last_is_up(m3))

top3= a_high3.lastx()
top_time3= a_time_high3.lastx()
bottom3= a_low3.lastx()
bottom_time3= a_time_low3.lastx()

c_box3=bottom_time3<top_time3?cBoxU3:cBoxD3
va3=bottom_time3<top_time3?text.align_top:text.align_bottom

_h3 = array.from(int(top_time3),int(bottom_time3))
_v3 = array.from(top3,bottom3)
_t3 = array.max(_v3)
_b3 = array.min(_v3)
_l3 = array.min(_h3)

if show3 and i_renew3!=0
    if b_TL_clear
        f_line_delete_all(a_tl_resistance3)
        f_line_delete_all(a_tl_support3)
    if array.size(a_tl_resistance3)>0
        line.set_extend(array.last(a_tl_resistance3),extend.none)
        array.clear(a_tl_resistance3)
    if array.size(a_tl_support3)>0
        line.set_extend(array.last(a_tl_support3),extend.none)
        array.clear(a_tl_support3)
    if not (_l3[1]==_l3 and (_b3[1]==_b3 or _t3[1]==_t3))
        mybox3:=box.new(_l3,na,na,na,xloc=xloc.bar_time,bgcolor=na,border_width=widthBox3,border_style=styleBox3,
         text_halign=text.align_right,text_valign=va3,text_size=infoSize,border_color=c_box3,text_color=cBoxT)
else if show3 and i_peak_bottom3==1 and b_TL
    if (array.size(a_high3)>0)
        if array.size(a_tl_resistance3)
            if b_TL_obsolete
                f_line_delete_all(a_tl_resistance3)
            else
                line.set_style(array.last(a_tl_resistance3),line.style_dotted)
                line.set_extend(array.last(a_tl_resistance3),extend.none)
                line.set_color(array.last(a_tl_resistance3),cTLro)
        if a_high3.lastx()!=a_return_high3.lastx()
            array.push(a_tl_resistance3,line.new(
             a_time_high3.lastx(),
             a_high3.lastx(),
             a_time_return_high3.lastx(),
             a_return_high3.lastx(),
             xloc.bar_time,extend.right,cTLr,styleBox3,widthBox3))
else if show3 and i_peak_bottom3==-1 and b_TL
    if (array.size(a_low3)>0)
        if array.size(a_tl_support3)
            if b_TL_obsolete
                f_line_delete_all(a_tl_support3)
            else
                line.set_style(array.last(a_tl_support3),line.style_dotted)
                line.set_extend(array.last(a_tl_support3),extend.none)
                line.set_color(array.last(a_tl_support3),cTLso)
        if a_low3.lastx()!=a_return_low3.lastx()
            array.push(a_tl_support3,line.new(
             a_time_low3.lastx(),
             a_low3.lastx(),
             a_time_return_low3.lastx(),
             a_return_low3.lastx(),
             xloc.bar_time,extend.right,cTLs,styleBox3,widthBox3))

if show3
    box.set_right(mybox3,int(m3.lastx("time_close")))
    box.set_bottom(mybox3,_b3)
    box.set_top(mybox3,_t3)
    box.set_text(mybox3,b_info?"TF"+symbol_htf3+"="+htf3+"\n"+
     f_time_ddhhmm(box.get_right(mybox3)-box.get_left(mybox3))+"\n"+
     str.tostring(math.abs(box.get_top(mybox3)-box.get_bottom(mybox3))):na)

//box htf4
var mybox4=box.new(na,na,na,na,xloc=xloc.bar_time,bgcolor=na,border_color=na)
var a_tl_resistance4=array.new_line(0,na)
var a_tl_support4=array.new_line(0,na)

i_peak_bottom4=H.peak_bottom(H.htf_is_up(m4),H.htf_last_is_up(m4))

top4= a_high4.lastx()
top_time4=  a_time_high4.lastx()
bottom4= a_low4.lastx()
bottom_time4= a_time_low4.lastx()

c_box4=bottom_time4<top_time4?cBoxU4:cBoxD4
va4=bottom_time4<top_time4?text.align_top:text.align_bottom

_h4 = array.from(int(top_time4),int(bottom_time4))
_v4 = array.from(top4,bottom4)
_t4 = array.max(_v4)
_b4 = array.min(_v4)
_l4 = array.min(_h4)

if show4 and i_renew4!=0
    if b_TL_clear
        f_line_delete_all(a_tl_resistance4)
        f_line_delete_all(a_tl_support4)
    if array.size(a_tl_resistance4)>0
        line.set_extend(array.last(a_tl_resistance4),extend.none)
        array.clear(a_tl_resistance4)
    if array.size(a_tl_support4)>0
        line.set_extend(array.last(a_tl_support4),extend.none)
        array.clear(a_tl_support4)
    if not (_l4[1]==_l4 and (_b4[1]==_b4 or _t4[1]==_t4))
        mybox4:=box.new(_l4,na,na,na,xloc=xloc.bar_time,bgcolor=na,border_width=widthBox4,border_style=styleBox4,
         text_halign=text.align_right,text_valign=va4,text_size=infoSize,border_color=c_box4,text_color=cBoxT)
else if show4 and i_peak_bottom4==1 and b_TL
    if (array.size(a_high4)>0)
        if array.size(a_tl_resistance4)
            if b_TL_obsolete
                f_line_delete_all(a_tl_resistance4)
            else
                line.set_style(array.last(a_tl_resistance4),line.style_dotted)
                line.set_extend(array.last(a_tl_resistance4),extend.none)
                line.set_color(array.last(a_tl_resistance4),cTLro)
        if a_high4.lastx()!=a_return_high4.lastx()
            array.push(a_tl_resistance4,line.new(
             a_time_high4.lastx(),
             a_high4.lastx(),
             a_time_return_high4.lastx(),
             a_return_high4.lastx(),
             xloc.bar_time,extend.right,cTLr,styleBox4,widthBox4))
else if show4 and i_peak_bottom4==-1 and b_TL
    if (array.size(a_low4)>0)
        if array.size(a_tl_support4)
            if b_TL_obsolete
                f_line_delete_all(a_tl_support4)
            else
                line.set_style(array.last(a_tl_support4),line.style_dotted)
                line.set_extend(array.last(a_tl_support4),extend.none)
                line.set_color(array.last(a_tl_support4),cTLso)
        if a_low4.lastx()!=a_return_low4.lastx()
            array.push(a_tl_support4,line.new(
             a_time_low4.lastx(),
             a_low4.lastx(),
             a_time_return_low4.lastx(),
             a_return_low4.lastx(),
             xloc.bar_time,extend.right,cTLs,styleBox4,widthBox4))

if show4
    box.set_right(mybox4,int(m4.lastx("time_close")))
    box.set_bottom(mybox4,_b4)
    box.set_top(mybox4,_t4)
    box.set_text(mybox4,b_info?"TF"+symbol_htf2+"="+htf4+"\n"+
     f_time_ddhhmm(box.get_right(mybox4)-box.get_left(mybox4))+"\n"+
     str.tostring(math.abs(box.get_top(mybox4)-box.get_bottom(mybox4))):na)

//
//fibonacci levels of higher boxes
//
var l_mybox1_rt=label.new(na,na,na,xloc.bar_time,yloc.price,na,label.style_none,na,infoSize,text.align_left)
var l_mybox1_rb=label.new(na,na,na,xloc.bar_time,yloc.price,na,label.style_none,na,infoSize,text.align_left)
var l_mybox2_rt=label.new(na,na,na,xloc.bar_time,yloc.price,na,label.style_none,na,infoSize,text.align_left)
var l_mybox2_rb=label.new(na,na,na,xloc.bar_time,yloc.price,na,label.style_none,na,infoSize,text.align_left)
var l_mybox3_rt=label.new(na,na,na,xloc.bar_time,yloc.price,na,label.style_none,na,infoSize,text.align_left)
var l_mybox3_rb=label.new(na,na,na,xloc.bar_time,yloc.price,na,label.style_none,na,infoSize,text.align_left)
var l_mybox4_rt=label.new(na,na,na,xloc.bar_time,yloc.price,na,label.style_none,na,infoSize,text.align_left)
var l_mybox4_rb=label.new(na,na,na,xloc.bar_time,yloc.price,na,label.style_none,na,infoSize,text.align_left)

if show1 and b_fibo1
    [_top,_tops,_bottom,_bottoms] = f_fibo_range(box.get_bottom(mybox1),box.get_top(mybox1),close)
    label.set_xy(l_mybox1_rt,box.get_right(mybox1),_top)
    label.set_textcolor(l_mybox1_rt,c_box1)
    label.set_text(l_mybox1_rt,"_____"+_tops+":"+str.tostring(_top,"#.0000")+"@"+symbol_htf1+htf1)
    label.set_xy(l_mybox1_rb,box.get_right(mybox1),_bottom)
    label.set_textcolor(l_mybox1_rb,c_box1)
    label.set_text(l_mybox1_rb,"_____"+_bottoms+":"+str.tostring(_bottom,"#.0000")+"@"+symbol_htf1+htf1)
if show2 and b_fibo2
    [_top,_tops,_bottom,_bottoms] = f_fibo_range(box.get_bottom(mybox2),box.get_top(mybox2),close)
    label.set_xy(l_mybox2_rt,box.get_right(mybox2),_top)
    label.set_textcolor(l_mybox2_rt,c_box2)
    label.set_text(l_mybox2_rt,"_____"+_tops+":"+str.tostring(_top,"#.0000")+"@"+symbol_htf2+htf2)
    label.set_xy(l_mybox2_rb,box.get_right(mybox2),_bottom)
    label.set_textcolor(l_mybox2_rb,c_box2)
    label.set_text(l_mybox2_rb,"_____"+_bottoms+":"+str.tostring(_bottom,"#.0000")+"@"+symbol_htf2+htf2)
if show3 and b_fibo3
    [_top,_tops,_bottom,_bottoms] = f_fibo_range(box.get_bottom(mybox3),box.get_top(mybox3),close)
    label.set_xy(l_mybox3_rt,box.get_right(mybox3),_top)
    label.set_textcolor(l_mybox3_rt,c_box3)
    label.set_text(l_mybox3_rt,"_____"+_tops+":"+str.tostring(_top,"#.0000")+"@"+symbol_htf3+htf3)
    label.set_xy(l_mybox3_rb,box.get_right(mybox3),_bottom)
    label.set_textcolor(l_mybox3_rb,c_box3)
    label.set_text(l_mybox3_rb,"_____"+_bottoms+":"+str.tostring(_bottom,"#.0000")+"@"+symbol_htf3+htf3)
if show4 and b_fibo4
    [_top,_tops,_bottom,_bottoms] = f_fibo_range(box.get_bottom(mybox4),box.get_top(mybox4),close)
    label.set_xy(l_mybox4_rt,box.get_right(mybox4),_top)
    label.set_textcolor(l_mybox4_rt,c_box4)
    label.set_text(l_mybox4_rt,"_____"+_tops+":"+str.tostring(_top,"#.0000")+"@"+symbol_htf4+htf4)
    label.set_xy(l_mybox4_rb,box.get_right(mybox4),_bottom)
    label.set_textcolor(l_mybox4_rb,c_box4)
    label.set_text(l_mybox4_rb,"_____"+_bottoms+":"+str.tostring(_bottom,"#.0000")+"@"+symbol_htf4+htf4)
//*****
//end of HighLowBox
//*****

//*****
//HighLowBox RSI
//*****

group_HLBOX_rsi="HighLowBox RSI"

spanRSI_1 = input.int(defval=9,minval=1,maxval=30,title="span1", inline="span", group=group_HLBOX_rsi)
spanRSI_2 = input.int(defval=14,minval=1,maxval=30,title="span2", inline="span", group=group_HLBOX_rsi)
b_RSIchange = input.bool(defval=true,title="dont plot same SIGNAL condition",group=group_HLBOX_rsi)

group_HLBOX_rsi_caution="HighLowBox RSI caution"
_cRSIi = input.color(defval=colorRSIi,title="only span1>=70 or only span1<=30",inline="top",group=group_HLBOX_rsi_caution)
group_HLBOX_rsi_overbought="HighLowBox RSI overbought"
_cRSIt1 = input.color(defval=colorRSIt1,title="both>=70 and span1>span2",inline="top",group=group_HLBOX_rsi_overbought)
_cRSIt2 = input.color(defval=colorRSIt2,title="both>=70 and span1<span2",inline="top",group=group_HLBOX_rsi_overbought)
_cRSIt3 = input.color(defval=colorRSIt3,title="span1<70",inline="top",group=group_HLBOX_rsi_overbought)
group_HLBOX_rsi_oversold="HighLowBox RSI oversold"
_cRSIb1 = input.color(defval=colorRSIb1,title="both<=30 and span1<span2",inline="top",group=group_HLBOX_rsi_oversold)
_cRSIb2 = input.color(defval=colorRSIb2,title="both<=30 and span1>span2",inline="top",group=group_HLBOX_rsi_oversold)
_cRSIb3 = input.color(defval=colorRSIb3,title="span1>30",inline="top",group=group_HLBOX_rsi_oversold)

showRSI = input.bool(defval=true,title="use RSI in current TF",inline="tf",group=group_HLBOX_rsi)
transRSI = input.int(defval=50,minval=0,maxval=99,title="transpar",inline="tf",group=group_HLBOX_rsi)
cRSIi=color.new(_cRSIi,transRSI)
cRSIt1=color.new(_cRSIt1,transRSI)
cRSIt2=color.new(_cRSIt2,transRSI)
cRSIt3=color.new(_cRSIt3,transRSI)
cRSIb1=color.new(_cRSIb1,transRSI)
cRSIb2=color.new(_cRSIb2,transRSI)
cRSIb3=color.new(_cRSIb3,transRSI)

showRSI1 = input.bool(defval=true,title="use RSI in Higher TF1",inline="tf1",group=group_HLBOX_rsi)
transRSI1 = input.int(defval=40,minval=0,maxval=99,title="transpar",inline="tf1",group=group_HLBOX_rsi)
cRSI1i=color.new(_cRSIi,transRSI1)
cRSI1t1=color.new(_cRSIt1,transRSI1)
cRSI1t2=color.new(_cRSIt2,transRSI1)
cRSI1t3=color.new(_cRSIt3,transRSI1)
cRSI1b1=color.new(_cRSIb1,transRSI1)
cRSI1b2=color.new(_cRSIb2,transRSI1)
cRSI1b3=color.new(_cRSIb3,transRSI1)

showRSI2 = input.bool(defval=true,title="use RSI in Higher TF2",inline="tf2",group=group_HLBOX_rsi)
transRSI2 = input.int(defval=35,minval=0,maxval=99,title="transpar",inline="tf2",group=group_HLBOX_rsi)
cRSI2i=color.new(_cRSIi,transRSI2)
cRSI2t1=color.new(_cRSIt1,transRSI2)
cRSI2t2=color.new(_cRSIt2,transRSI2)
cRSI2t3=color.new(_cRSIt3,transRSI2)
cRSI2b1=color.new(_cRSIb1,transRSI2)
cRSI2b2=color.new(_cRSIb2,transRSI2)
cRSI2b3=color.new(_cRSIb3,transRSI2)

showRSI3 = input.bool(defval=true,title="use RSI in Higher TF3",inline="tf3",group=group_HLBOX_rsi)
transRSI3 = input.int(defval=30,minval=0,maxval=99,title="transpar",inline="tf3",group=group_HLBOX_rsi)
cRSI3i=color.new(_cRSIi,transRSI3)
cRSI3t1=color.new(_cRSIt1,transRSI3)
cRSI3t2=color.new(_cRSIt2,transRSI3)
cRSI3t3=color.new(_cRSIt3,transRSI3)
cRSI3b1=color.new(_cRSIb1,transRSI3)
cRSI3b2=color.new(_cRSIb2,transRSI3)
cRSI3b3=color.new(_cRSIb3,transRSI3)

showRSI4 = input.bool(defval=true,title="use RSI in Higher TF4",inline="tf4",group=group_HLBOX_rsi)
transRSI4 = input.int(defval=25,minval=0,maxval=99,title="transpar",inline="tf4",group=group_HLBOX_rsi)
cRSI4i=color.new(_cRSIi,transRSI4)
cRSI4t1=color.new(_cRSIt1,transRSI4)
cRSI4t2=color.new(_cRSIt2,transRSI4)
cRSI4t3=color.new(_cRSIt3,transRSI4)
cRSI4b1=color.new(_cRSIb1,transRSI4)
cRSI4b2=color.new(_cRSIb2,transRSI4)
cRSI4b3=color.new(_cRSIb3,transRSI4)

//
//RSI
//
var int RSIt =70
var int RSIb =30
var RSIchange=false
var l_RSI=label.new(na,na,yloc=yloc.price,style=label.style_none)

s_RSI_1= show0 and showRSI?ta.rsi(src,spanRSI_1):na
s_RSI_2= show0 and showRSI?ta.rsi(src,spanRSI_2):na

b_RSI_70 = s_RSI_1>=RSIt or s_RSI_2>=RSIt
b_RSI_30 = s_RSI_1<=RSIb or s_RSI_2<=RSIb

cRSI=
 s_RSI_1==s_RSI_1[1] and s_RSI_2==s_RSI_2[1]?na:
 b_RSI_70? s_RSI_1>s_RSI_2? s_RSI_2<RSIt?cRSIi: cRSIt1: s_RSI_1<RSIt?cRSIt3: cRSIt2:
 b_RSI_30? s_RSI_1<s_RSI_2? s_RSI_2>RSIb?cRSIi: cRSIb1: s_RSI_1>RSIb?cRSIb3: cRSIb2:na
RSIchange:=cRSI!=cRSI[1]?true:RSIchange

RSIy=b_RSI_70? box.get_top(mybox): b_RSI_30?box.get_bottom(mybox):na
RSIchange:=RSIy!=RSIy[1]?true:RSIchange

if not na(RSIy)
    if RSIchange
        if l_RSI.get_x()==bar_index
            l_RSI.set_color(cRSI)
        else 
            l_RSI:=label.new(bar_index,RSIy,textcolor=cRSI,color=cRSI,yloc=yloc.price,style=label.style_none)
            if b_RSI_70
                l_RSI.set_style(label.style_label_down)
            else if b_RSI_30
                l_RSI.set_style(label.style_label_up)

//H1
s_RSI1_1= show1 and showRSI1?H.htf_rsi(htf1src,b_new_bar1,spanRSI_1):na
s_RSI1_2= show1 and showRSI1?H.htf_rsi(htf1src,b_new_bar1,spanRSI_2):na

b_RSI1_70 = s_RSI1_1>=RSIt or s_RSI1_2>=RSIt
b_RSI1_30 = s_RSI1_1<=RSIb or s_RSI1_2<=RSIb

cRSI1=
 s_RSI1_1==s_RSI1_1[1] and s_RSI1_2==s_RSI1_2[1]?na:
 b_RSI1_70? s_RSI1_1>s_RSI1_2? s_RSI1_2<RSIt?cRSI1i: cRSI1t1: s_RSI1_1<RSIt?cRSI1t3: cRSI1t2:
 b_RSI1_30? s_RSI1_1<s_RSI1_2? s_RSI1_2>RSIb?cRSI1i: cRSI1b1: s_RSI1_1>RSIb?cRSI1b3: cRSI1b2:na
RSI1y=b_RSI1_70? box.get_top(mybox1): b_RSI1_30?box.get_bottom(mybox1):na

plotchar(b_RSIchange?ta.change(RSI1y)?RSI1y: cRSI1!=cRSI1[1]?RSI1y: b_new_bar1?RSI1y: na:RSI1y,"SIG_RSI1",char=symbol_htf1,location=location.absolute,color=cRSI1,size=size.small,text=" ¹",textcolor=cRSI1)
//l_RSI1=label.new(bar_index,b_RSIchange?ta.change(RSI1y)?RSI1y: cRSI1!=cRSI1[1]?RSI1y: b_new_bar1?RSI1y: na:RSI1y,symbol_htf1,textcolor=cRSI1,color=color.new(cRSI1,99),yloc=yloc.price,style=label.style_label_center,size=size.huge)
//if b_RSI1_70
//    l_RSI1.set_style(label.style_label_right)
//else if b_RSI1_30
//    l_RSI1.set_style(label.style_label_right)
   
//H2
s_RSI2_1= show2 and showRSI2?H.htf_rsi(htf2src,b_new_bar2,spanRSI_1):na
s_RSI2_2= show2 and showRSI2?H.htf_rsi(htf2src,b_new_bar2,spanRSI_2):na

b_RSI2_70 = s_RSI2_1>=RSIt or s_RSI2_2>=RSIt
b_RSI2_30 = s_RSI2_1<=RSIb or s_RSI2_2<=RSIb

cRSI2=
 s_RSI2_1==s_RSI2_1[1] and s_RSI2_2==s_RSI2_2[1]?na:
 b_RSI2_70? s_RSI2_1>s_RSI2_2? s_RSI2_2<RSIt?cRSI2i: cRSI2t1: s_RSI2_1<RSIt?cRSI2t3: cRSI2t2:
 b_RSI2_30? s_RSI2_1<s_RSI2_2? s_RSI2_2>RSIb?cRSI2i: cRSI2b1: s_RSI2_1>RSIb?cRSI2b3: cRSI2b2:na
RSI2y=b_RSI2_70? box.get_top(mybox2): b_RSI2_30?box.get_bottom(mybox2):na

plotchar(b_RSIchange?ta.change(RSI2y)?RSI2y: cRSI2!=cRSI2[1]?RSI2y: b_new_bar2?RSI2y: na:RSI2y,"SIG_RSI2",char=symbol_htf2,location=location.absolute,color=cRSI2,textcolor=cRSI2,size=size.small,text=" ₂")
//l_RSI2=label.new(bar_index,b_RSIchange?ta.change(RSI2y)?RSI2y: cRSI2!=cRSI2[1]?RSI2y: b_new_bar2?RSI2y: na:RSI2y,symbol_htf2,textcolor=cRSI2,color=color.new(cRSI2,99),yloc=yloc.price,style=label.style_label_center,size=size.huge)
//if b_RSI2_70
//    l_RSI2.set_style(label.style_label_down)
//else if b_RSI2_30
//    l_RSI2.set_style(label.style_label_up)

//H3
s_RSI3_1= show3 and showRSI3?H.htf_rsi(htf3src,b_new_bar3,spanRSI_1):na
s_RSI3_2= show3 and showRSI3?H.htf_rsi(htf3src,b_new_bar3,spanRSI_2):na

b_RSI3_70 = s_RSI3_1>=RSIt or s_RSI3_2>=RSIt
b_RSI3_30 = s_RSI3_1<=RSIb or s_RSI3_2<=RSIb

cRSI3=
 s_RSI3_1==s_RSI3_1[1] and s_RSI3_2==s_RSI3_2[1]?na:
 b_RSI3_70? s_RSI3_1>s_RSI3_2? s_RSI3_2<RSIt?cRSI3i: cRSI3t1: s_RSI3_1<RSIt?cRSI3t3: cRSI3t2:
 b_RSI3_30? s_RSI3_1<s_RSI3_2? s_RSI3_2>RSIb?cRSI3i: cRSI3b1: s_RSI3_1>RSIb?cRSI3b3: cRSI3b2:na
RSI3y=b_RSI3_70? box.get_top(mybox3): b_RSI3_30?box.get_bottom(mybox3):na

plotchar(b_RSIchange?ta.change(RSI3y)?RSI3y: cRSI3!=cRSI3[1]?RSI3y: b_new_bar3?RSI3y: na:RSI3y,"SIG_RSI3",char=symbol_htf3,location=location.absolute,color=cRSI3,textcolor=cRSI3,size=size.small,text="₃")
//l_RSI3=label.new(bar_index,b_RSIchange?ta.change(RSI3y)?RSI3y: cRSI3!=cRSI3[1]?RSI3y: b_new_bar3?RSI3y: na:RSI3y,symbol_htf3,textcolor=cRSI3,color=color.new(cRSI3,99),yloc=yloc.price,style=label.style_label_center,size=size.huge)
//if b_RSI3_70
//    l_RSI3.set_style(label.style_label_down)
//else if b_RSI3_30
//    l_RSI3.set_style(label.style_label_up)

//H4
s_RSI4_1= show4 and showRSI4?H.htf_rsi(htf4src,b_new_bar4,spanRSI_1):na
s_RSI4_2= show4 and showRSI4?H.htf_rsi(htf4src,b_new_bar4,spanRSI_2):na

b_RSI4_70 = s_RSI4_1>=RSIt or s_RSI4_2>=RSIt
b_RSI4_30 = s_RSI4_1<=RSIb or s_RSI4_2<=RSIb

cRSI4=
 s_RSI4_1==s_RSI4_1[1] and s_RSI4_2==s_RSI4_2[1]?na:
 b_RSI4_70? s_RSI4_1>s_RSI4_2? s_RSI4_2<RSIt?cRSI4i: cRSI4t1: s_RSI4_1<RSIt?cRSI4t3: cRSI4t2:
 b_RSI4_30? s_RSI4_1<s_RSI4_2? s_RSI4_2>RSIb?cRSI4i: cRSI4b1: s_RSI4_1>RSIb?cRSI4b3: cRSI4b2:na
RSI4y=b_RSI4_70? box.get_top(mybox4): b_RSI4_30?box.get_bottom(mybox4):na

plotchar(b_RSIchange?ta.change(RSI4y)?RSI4y: cRSI4!=cRSI4[1]?RSI4y: b_new_bar4?RSI4y: na:RSI4y,"SIG_RSI4",char=symbol_htf4,location=location.absolute,color=cRSI4,textcolor=cRSI4,size=size.small,text="⁴")
//l_RSI4=label.new(bar_index,b_RSIchange?ta.change(RSI4y)?RSI4y: cRSI4!=cRSI4[1]?RSI4y: b_new_bar4?RSI4y: na:RSI4y,symbol_htf4,textcolor=cRSI4,color=color.new(cRSI3,99),yloc=yloc.price,style=label.style_label_center,size=size.huge)
//if b_RSI4_70
//    l_RSI4.set_style(label.style_label_down)
//else if b_RSI4_30
//    l_RSI4.set_style(label.style_label_up)

//*****
//end of HighLowBox RSI
//*****

//*****
//MAs
//*****
var spanS = 20
var spanL = 200
string limit200 = "3M"

group_MA="20/200 MAs(sma/ema)"
span1MA = input.int(defval=spanS,minval=1,maxval=200,title="span1",inline="span",group=group_MA)
span2MA = input.int(defval=spanL,minval=1,maxval=200,title="span2",inline="span",group=group_MA)
_cSMA = input.color(defval=colorSMA,title="SMA",inline="color",group=group_MA)
_cEMA = input.color(defval=colorEMA,title="EMA",inline="color",group=group_MA)
b_MAlabel = input.bool(defval=true,title="show MA label",inline="MA",group=group_MA)
b_MAinfo = input.bool(defval=false,title="show MA info",inline="MA",group=group_MA)
b_MAlimit = input.bool(defval=true,title="dont show SPAN2 MA if tf>",inline="MAlim",group=group_MA)
_limit200 = input.timeframe(defval=t13, title="", options=[t01,t02,t03,t04,t05,t06,t07,t08,t09,t10,t11,t12,t13,t14,t15],inline="MAlim",group=group_MA)
limit200:=b_MAlimit?_limit200:"0S"

b_MA = input.bool(defval=true,title="CTF",inline="ctf",group=group_MA)
_transMA = input.int(defval=40,minval=0,maxval=99,title="transpar",inline="ctf",group=group_MA)
cSMA=color.new(_cSMA,_transMA)
cEMA=color.new(_cEMA,_transMA)
labeloffset = input.int(defval=10,minval=0,maxval=50,title="labeloffset",inline="ctf",group=group_MA)
widthMAs = input.int(defval=1,minval=1,maxval=4,title="SPAN1:width",inline="ctf",group=group_MA)
_styleMAs = input.string(defval=ps01,options=[ps00,ps01,ps02,ps03,ps04,ps05,ps06,ps07,ps08,ps09],title="style",inline="ctf",group=group_MA)
styleMAs = f_plotstyle(_styleMAs)
widthMAl = input.int(defval=1,minval=1,maxval=4,title="SPAN2:width",inline="ctf",group=group_MA)
_styleMAl = input.string(defval=ps01,options=[ps00,ps01,ps02,ps03,ps04,ps05,ps06,ps07,ps08,ps09],title="style",inline="ctf",group=group_MA)
styleMAl = f_plotstyle(_styleMAl)

b_MA1 = input.bool(defval=true,title="HTF1",inline="htf1",group=group_MA)
_transMA1 = input.int(defval=30,minval=0,maxval=99,title="transpar",inline="htf1",group=group_MA)
cSMA1=color.new(_cSMA,_transMA1)
cEMA1=color.new(_cEMA,_transMA1)
labeloffset1 = input.int(defval=13,minval=0,maxval=50,title="labeloffset",inline="htf1",group=group_MA)
widthMA1s = input.int(defval=2,minval=1,maxval=4,title="SPAN1:width",inline="htf1",group=group_MA)
_styleMA1s = input.string(defval=ps01,options=[ps00,ps01,ps02,ps03,ps04,ps05,ps06,ps07,ps08,ps09],title="style",inline="htf1",group=group_MA)
styleMA1s = f_plotstyle(_styleMA1s)
widthMA1l = input.int(defval=2,minval=1,maxval=4,title="SPAN2:width",inline="htf1",group=group_MA)
_styleMA1l = input.string(defval=ps01,options=[ps00,ps01,ps02,ps03,ps04,ps05,ps06,ps07,ps08,ps09],title="style",inline="htf1",group=group_MA)
styleMA1l = f_plotstyle(_styleMA1l)

b_MA2 = input.bool(defval=true,title="HTF2",inline="htf2",group=group_MA)
_transMA2 = input.int(defval=20,minval=0,maxval=99,title="transpar",inline="htf2",group=group_MA)
cSMA2=color.new(_cSMA,_transMA2)
cEMA2=color.new(_cEMA,_transMA2)
labeloffset2 = input.int(defval=16,minval=0,maxval=50,title="labeloffset",inline="htf2",group=group_MA)
widthMA2s = input.int(defval=3,minval=1,maxval=4,title="SPAN1:width",inline="htf2",group=group_MA)
_styleMA2s = input.string(defval=ps01,options=[ps00,ps01,ps02,ps03,ps04,ps05,ps06,ps07,ps08,ps09],title="style",inline="htf2",group=group_MA)
styleMA2s = f_plotstyle(_styleMA2s)
widthMA2l = input.int(defval=3,minval=1,maxval=4,title="SPAN2:width",inline="htf2",group=group_MA)
_styleMA2l = input.string(defval=ps01,options=[ps00,ps01,ps02,ps03,ps04,ps05,ps06,ps07,ps08,ps09],title="style",inline="htf2",group=group_MA)
styleMA2l = f_plotstyle(_styleMA2l)

b_MA3 = input.bool(defval=true,title="HTF3",inline="htf3",group=group_MA)
_transMA3 = input.int(defval=30,minval=0,maxval=99,title="transpar",inline="htf3",group=group_MA)
cSMA3=color.new(_cSMA,_transMA3)
cEMA3=color.new(_cEMA,_transMA3)
labeloffset3 = input.int(defval=19,minval=0,maxval=50,title="labeloffset",inline="htf3",group=group_MA)
widthMA3s = input.int(defval=4,minval=1,maxval=4,title="SPAN1:width",inline="htf3",group=group_MA)
_styleMA3s = input.string(defval=ps01,options=[ps00,ps01,ps02,ps03,ps04,ps05,ps06,ps07,ps08,ps09],title="style",inline="htf3",group=group_MA)
styleMA3s = f_plotstyle(_styleMA3s)
widthMA3l = input.int(defval=4,minval=1,maxval=4,title="SPAN2:width",inline="htf3",group=group_MA)
_styleMA3l = input.string(defval=ps01,options=[ps00,ps01,ps02,ps03,ps04,ps05,ps06,ps07,ps08,ps09],title="style",inline="htf3",group=group_MA)
styleMA3l = f_plotstyle(_styleMA3l)

b_MA4 = input.bool(defval=true,title="HTF4",inline="htf4",group=group_MA)
_transMA4 = input.int(defval=40,minval=0,maxval=99,title="transpar",inline="htf4",group=group_MA)
cSMA4=color.new(_cSMA,_transMA4)
cEMA4=color.new(_cEMA,_transMA4)
labeloffset4 = input.int(defval=22,minval=0,maxval=50,title="labeloffset",inline="htf4",group=group_MA)
widthMA4s = input.int(defval=4,minval=1,maxval=4,title="SPAN1:width",inline="htf4",group=group_MA)
_styleMA4s = input.string(defval=ps07,options=[ps00,ps01,ps02,ps03,ps04,ps05,ps06,ps07,ps08,ps09],title="style",inline="htf4",group=group_MA)
styleMA4s = f_plotstyle(_styleMA4s)
widthMA4l = input.int(defval=4,minval=1,maxval=4,title="SPAN2:width",inline="htf4",group=group_MA)
_styleMA4l = input.string(defval=ps09,options=[ps00,ps01,ps02,ps03,ps04,ps05,ps06,ps07,ps08,ps09],title="style",inline="htf4",group=group_MA)
styleMA4l = f_plotstyle(_styleMA4l)

//200MA
s_200SMA = b_MA and b_tfgt(limit200,tfChart)?ta.sma(src,span2MA):na
s_200EMA = b_MA and b_tfgt(limit200,tfChart)?ta.ema(src,span2MA):na

//20MA
s_20SMA = b_MA?ta.sma(src,span1MA):na
s_20EMA = b_MA?ta.ema(src,span1MA):na

//Higher
s_200SMA1 = b_MA1 and b_tfgt(limit200,tfChart)?H.htf_sma(htf1src,span2MA):na
s_200EMA1 = b_MA1 and b_tfgt(limit200,tfChart)?H.htf_ema(htf1src,b_new_bar1,span2MA):na
s_20SMA1 = b_MA1?H.htf_sma(htf1src,span1MA):na
s_20EMA1 = b_MA1?H.htf_ema(htf1src,b_new_bar1,span1MA):na

s_200SMA2 = b_MA2 and b_tfgt(limit200,tfChart)?H.htf_sma(htf2src,span2MA):na
s_200EMA2 = b_MA2 and b_tfgt(limit200,tfChart)?H.htf_ema(htf2src,b_new_bar2,span2MA):na
s_20SMA2 = b_MA2?H.htf_sma(htf2src,span1MA):na
s_20EMA2 = b_MA2?H.htf_ema(htf2src,b_new_bar2,span1MA):na

s_200SMA3 = b_MA3 and b_tfgt(limit200,tfChart)?H.htf_sma(htf3src,span2MA):na
s_200EMA3 = b_MA3 and b_tfgt(limit200,tfChart)?H.htf_ema(htf3src,b_new_bar3,span2MA):na
s_20SMA3 = b_MA3?H.htf_sma(htf3src,span1MA):na
s_20EMA3 = b_MA3?H.htf_ema(htf3src,b_new_bar3,span1MA):na

s_200SMA4 = b_MA4 and b_tfgt(limit200,tfChart)?H.htf_sma(htf4src,span2MA):na
s_200EMA4 = b_MA4 and b_tfgt(limit200,tfChart)?H.htf_ema(htf4src,b_new_bar4,span2MA):na
s_20SMA4 = b_MA4?H.htf_sma(htf4src,span1MA):na
s_20EMA4 = b_MA4?H.htf_ema(htf4src,b_new_bar4,span1MA):na

//plot MAs
plot(s_20SMA,linewidth=widthMAs,style=styleMAs,color=cSMA,title="SMA20")
label_20SMA = f_ma_label(b_MAlabel?s_20SMA:na,labeloffset,tfChart,span1MA,"SMA",cSMA,b_MAinfo)
label.delete(label_20SMA[1])
plot(s_20EMA,linewidth=widthMAs,style=styleMAs,color=cEMA,title="EMA20")
label_20EMA = f_ma_label(b_MAlabel?s_20EMA:na,labeloffset,tfChart,span1MA,"EMA",cEMA,b_MAinfo)
label.delete(label_20EMA[1])

plot(s_200SMA,linewidth=widthMAl,style=styleMAl,color=cSMA,title="SMA200")
label_200SMA = f_ma_label(b_MAlabel?s_200SMA:na,labeloffset,tfChart,span2MA,"SMA",cSMA,b_MAinfo)
label.delete(label_200SMA[1])
plot(s_200EMA,linewidth=widthMAl,style=styleMAl,color=cEMA,title="EMA200")
label_200EMA = f_ma_label(b_MAlabel?s_200EMA:na,labeloffset,tfChart,span2MA,"EMA",cEMA,b_MAinfo)
label.delete(label_200EMA[1])

//plot higher1
plot(s_20SMA1,linewidth=widthMA1s,style=styleMA1s,color=cSMA,title="SMA20htf1")
label_20SMA1 = f_ma_label(b_MAlabel?s_20SMA1:na,labeloffset1,symbol_htf1+htf1,span1MA,"SMA",cSMA1,b_MAinfo)
label.delete(label_20SMA1[1])
plot(s_20EMA1,linewidth=widthMA1s,style=styleMA1s,color=cEMA,title="EMA20htf1")
label_20EMA1 = f_ma_label(b_MAlabel?s_20EMA1:na,labeloffset1,symbol_htf1+htf1,span1MA,"EMA",cEMA1,b_MAinfo)
label.delete(label_20EMA1[1])

plot(s_200SMA1,linewidth=widthMA1l,style=styleMA1l,color=cSMA,title="SMA200htf1")
label_200SMA1 = f_ma_label(b_MAlabel?s_200SMA1:na,labeloffset1,symbol_htf1+htf1,span2MA,"SMA",cSMA1,b_MAinfo)
label.delete(label_200SMA1[1])
plot(s_200EMA1,linewidth=widthMA1l,style=styleMA1l,color=cEMA,title="EMA200htf1")
label_200EMA1 = f_ma_label(b_MAlabel?s_200EMA1:na,labeloffset1,symbol_htf1+htf1,span2MA,"EMA",cEMA1,b_MAinfo)
label.delete(label_200EMA1[1])

//plot higher2
plot(s_20SMA2,linewidth=widthMA2s,style=styleMA2s,color=cSMA,title="SMA20htf2")
label_20SMA2 = f_ma_label(b_MAlabel?s_20SMA2:na,labeloffset2,symbol_htf2+htf2,span1MA,"SMA",cSMA2,b_MAinfo)
label.delete(label_20SMA2[1])
plot(s_20EMA2,linewidth=widthMA2s,style=styleMA2s,color=cEMA,title="EMA20htf2")
label_20EMA2 = f_ma_label(b_MAlabel?s_20EMA2:na,labeloffset2,symbol_htf2+htf2,span1MA,"EMA",cEMA2,b_MAinfo)
label.delete(label_20EMA2[1])

plot(s_200SMA2,linewidth=widthMA2l,style=styleMA2l,color=cSMA,title="SMA200htf2")
label_200SMA2 = f_ma_label(b_MAlabel?s_200SMA2:na,labeloffset2,symbol_htf2+htf2,span2MA,"SMA",cSMA2,b_MAinfo)
label.delete(label_200SMA2[1])
plot(s_200EMA2,linewidth=widthMA2l,style=styleMA2l,color=cEMA,title="EMA200htf2")
label_200EMA2 = f_ma_label(b_MAlabel?s_200EMA2:na,labeloffset2,symbol_htf2+htf2,span2MA,"EMA",cEMA2,b_MAinfo)
label.delete(label_200EMA2[1])

//plot higher3
plot(s_20SMA3,linewidth=widthMA3s,style=styleMA2s,color=cSMA,title="SMA20htf3")
label_20SMA3 = f_ma_label(b_MAlabel?s_20SMA3:na,labeloffset3,symbol_htf3+htf3,span1MA,"SMA",cSMA3,b_MAinfo)
label.delete(label_20SMA3[1])
plot(s_20EMA3,linewidth=widthMA3s,style=styleMA2s,color=cEMA,title="EMA20htf3")
label_20EMA3 = f_ma_label(b_MAlabel?s_20EMA3:na,labeloffset3,symbol_htf3+htf3,span1MA,"EMA",cEMA3,b_MAinfo)
label.delete(label_20EMA3[1])

plot(s_200SMA3,linewidth=widthMA3l,style=styleMA2l,color=cSMA,title="SMA200htf3")
label_200SMA3 = f_ma_label(b_MAlabel?s_200SMA3:na,labeloffset3,symbol_htf3+htf3,span2MA,"SMA",cSMA3,b_MAinfo)
label.delete(label_200SMA3[1])
plot(s_200EMA3,linewidth=widthMA3l,style=styleMA2l,color=cEMA,title="EMA200htf3")
label_200EMA3 = f_ma_label(b_MAlabel?s_200EMA3:na,labeloffset3,symbol_htf3+htf3,span2MA,"EMA",cEMA3,b_MAinfo)
label.delete(label_200EMA3[1])

//plot higher4
plot(s_20SMA4,linewidth=widthMA4s,style=styleMA2s,color=cSMA,title="SMA20htf4")
label_20SMA4 = f_ma_label(b_MAlabel?s_20SMA4:na,labeloffset4,symbol_htf4+htf4,span1MA,"SMA",cSMA4,b_MAinfo)
label.delete(label_20SMA4[1])
plot(s_20EMA4,linewidth=widthMA4s,style=styleMA2s,color=cEMA,title="EMA20htf4")
label_20EMA4 = f_ma_label(b_MAlabel?s_20EMA4:na,labeloffset4,symbol_htf4+htf4,span1MA,"EMA",cEMA4,b_MAinfo)
label.delete(label_20EMA4[1])

plot(s_200SMA4,linewidth=widthMA4l,style=styleMA2l,color=cSMA,title="SMA200htf4")
label_200SMA4 = f_ma_label(b_MAlabel?s_200SMA4:na,labeloffset4,symbol_htf4+htf4,span2MA,"SMA",cSMA4,b_MAinfo)
label.delete(label_200SMA4[1])
plot(s_200EMA4,linewidth=widthMA4l,style=styleMA2l,color=cEMA,title="EMA200htf4")
label_200EMA4 = f_ma_label(b_MAlabel?s_200EMA4:na,labeloffset4,symbol_htf4+htf4,span2MA,"EMA",cEMA4,b_MAinfo)
label.delete(label_200EMA4[1])

//*****
//end of MAs
//*****

//*****
//draw fake candle
//*****
//➊➋➌➍
var range1=box.new(na,na,na,na,bgcolor=na,border_width=widthBox1,border_style=styleBox1,text_size=infoSize,text_color=cBoxT)
var range2=box.new(na,na,na,na,bgcolor=na,border_width=widthBox2,border_style=styleBox2,text_size=infoSize,text_color=cBoxT)
var range3=box.new(na,na,na,na,bgcolor=na,border_width=widthBox3,border_style=styleBox3,text_size=infoSize,text_color=cBoxT)
var range4=box.new(na,na,na,na,bgcolor=na,border_width=widthBox4,border_style=styleBox4,text_size=infoSize,text_color=cBoxT)
if b_fake_candle
    _cu=color.new(cCandleU,trans_candle)
    _cd=color.new(cCandleD,trans_candle)
    _o = i_offset_candle
    _cw=3

    _x = bar_index+40
    [mybody4_2,mywicka4_2,mywickb4_2] = f_draw_candle_barindex(m4.lastx("open",2),m4.lastx("close",2),m4.lastx("high",2),m4.lastx("low",2),_o,_x,symbol_htf4+"\n"+htf4,_cu,_cd,cCandleT)
    box.delete(mybody4_2[1])
    line.delete(mywicka4_2[1])
    line.delete(mywickb4_2[1])
    [mybody4_1,mywicka4_1,mywickb4_1] = f_draw_candle_barindex(m4.lastx("open",1),m4.lastx("close",1),m4.lastx("high",1),m4.lastx("low",1),_o,_x+_cw,symbol_htf4+"\n"+htf4,_cu,_cd,cCandleT)
    box.delete(mybody4_1[1])
    line.delete(mywicka4_1[1])
    line.delete(mywickb4_1[1])
    [mybody4,mywicka4,mywickb4] = f_draw_candle_barindex(m4.lastx("open"),m4.lastx("close"),m4.lastx("high"),m4.lastx("low"),_o,_x+_cw*2,symbol_htf4+"\n"+htf4,_cu,_cd,cCandleT)
    box.delete(mybody4[1])
    line.delete(mywicka4[1])
    line.delete(mywickb4[1])
    range4.set_lefttop(_o+_x-1,box.get_top(mybox4))
    range4.set_rightbottom(_o+_x+_cw*3,box.get_bottom(mybox4))
    range4.set_border_color(c_box4)

    _x := bar_index+30
    [mybody3_2,mywicka3_2,mywickb3_2] = f_draw_candle_barindex(m3.lastx("open",2),m3.lastx("close",2),m3.lastx("high",2),m3.lastx("low",2),_o,_x,symbol_htf3+"\n"+htf3,_cu,_cd,cCandleT)
    box.delete(mybody3_2[1])
    line.delete(mywicka3_2[1])
    line.delete(mywickb3_2[1])
    [mybody3_1,mywicka3_1,mywickb3_1] = f_draw_candle_barindex(m3.lastx("open",1),m3.lastx("close",1),m3.lastx("high",1),m3.lastx("low",1),_o,_x+_cw,symbol_htf3+"\n"+htf3,_cu,_cd,cCandleT)
    box.delete(mybody3_1[1])
    line.delete(mywicka3_1[1])
    line.delete(mywickb3_1[1])
    [mybody3,mywick3a,mywick3b] = f_draw_candle_barindex(m3.lastx("open"),m3.lastx("close"),m3.lastx("high"),m3.lastx("low"),_o,_x+_cw*2,symbol_htf3+"\n"+htf3,_cu,_cd,cCandleT)
    box.delete(mybody3[1])
    line.delete(mywick3a[1])
    line.delete(mywick3b[1])
    range3.set_lefttop(_o+_x-1,box.get_top(mybox3))
    range3.set_rightbottom(_o+_x+_cw*3,box.get_bottom(mybox3))
    range3.set_border_color(c_box3)

    _x := bar_index+20
    [mybody2_2,mywicka2_2,mywickb2_2] = f_draw_candle_barindex(m2.lastx("open",2),m2.lastx("close",2),m2.lastx("high",2),m2.lastx("low",2),_o,_x,symbol_htf2+"\n"+htf2,_cu,_cd,cCandleT)
    box.delete(mybody2_2[1])
    line.delete(mywicka2_2[1])
    line.delete(mywickb2_2[1])
    [mybody2_1,mywicka2_1,mywickb2_1] = f_draw_candle_barindex(m2.lastx("open",1),m2.lastx("close",1),m2.lastx("high",1),m2.lastx("low",1),_o,_x+_cw,symbol_htf2+"\n"+htf2,_cu,_cd,cCandleT)
    box.delete(mybody2_1[1])
    line.delete(mywicka2_1[1])
    line.delete(mywickb2_1[1])
    [mybody2,mywick2a,mywick2b] = f_draw_candle_barindex(m2.lastx("open"),m2.lastx("close"),m2.lastx("high"),m2.lastx("low"),_o,_x+_cw*2,symbol_htf2+"\n"+htf2,_cu,_cd,cCandleT)
    box.delete(mybody2[1])
    line.delete(mywick2a[1])
    line.delete(mywick2b[1])
    range2.set_lefttop(_o+_x-1,box.get_top(mybox2))
    range2.set_rightbottom(_o+_x+_cw*3,box.get_bottom(mybox2))
    range2.set_border_color(c_box2)

    _x := bar_index+10
    [mybody1_2,mywicka1_2,mywickb1_2] = f_draw_candle_barindex(m1.lastx("open",2),m1.lastx("close",2),m1.lastx("high",2),m1.lastx("low",2),_o,_x,symbol_htf1+"\n"+htf1,_cu,_cd,cCandleT)
    box.delete(mybody1_2[1])
    line.delete(mywicka1_2[1])
    line.delete(mywickb1_2[1])
    [mybody1_1,mywicka1_1,mywickb1_1] = f_draw_candle_barindex(m1.lastx("open",1),m1.lastx("close",1),m1.lastx("high",1),m1.lastx("low",1),_o,_x+_cw,symbol_htf1+"\n"+htf1,_cu,_cd,cCandleT)
    box.delete(mybody1_1[1])
    line.delete(mywicka1_1[1])
    line.delete(mywickb1_1[1])
    [mybody1,mywick1a,mywick1b] = f_draw_candle_barindex(m1.lastx("open"),m1.lastx("close"),m1.lastx("high"),m1.lastx("low"),_o,_x+_cw*2,symbol_htf1+"\n"+htf1,_cu,_cd,cCandleT)
    box.delete(mybody1[1])
    line.delete(mywick1a[1])
    line.delete(mywick1b[1])
    range1.set_lefttop(_o+_x-1,box.get_top(mybox1))
    range1.set_rightbottom(_o+_x+_cw*3,box.get_bottom(mybox1))
    range1.set_border_color(c_box1)


//*****
//end of draw fake candle
//*****

//*****
//DMI
//*****
width_bar_time=timeframe.in_seconds()*1000

f_map2box(float val,box boxid)=>
    _base=boxid.get_bottom()
    _top=boxid.get_top()
    _diff = _top-_base
    _y = _base + _diff*val/100

f_line_set_xyz(line lineid,int offset,float val1,float val2) =>
    lineid.set_xy1(offset-1,val1)
    lineid.set_xy2(offset,val2)

[di9,_di9,adx9]=ta.dmi(9,9)
[di14,_di14,adx14]=ta.dmi(14,14)

var adxline1=line.new(na,na,na,na,color=cADX,xloc=xloc.bar_time,style=line.style_arrow_right)
var adxline2=line.new(na,na,na,na,color=cADX,xloc=xloc.bar_time,style=line.style_arrow_right)
var adxline3=line.new(na,na,na,na,color=cADX,xloc=xloc.bar_time,style=line.style_arrow_right)
var adxline4=line.new(na,na,na,na,color=cADX,xloc=xloc.bar_time,style=line.style_arrow_right)
var adxline5=line.new(na,na,na,na,color=cADX,xloc=xloc.bar_time,style=line.style_arrow_right)
var adxline6=line.new(na,na,na,na,color=cADX,xloc=xloc.bar_time,style=line.style_arrow_right)
var adxline7=line.new(na,na,na,na,color=cADX,xloc=xloc.bar_time,style=line.style_arrow_right)
var adxline8=line.new(na,na,na,na,color=cADX,xloc=xloc.bar_time,style=line.style_arrow_right)

var diline1=line.new(na,na,na,na,color=cDI,xloc=xloc.bar_time,style=line.style_arrow_right)
var diline2=line.new(na,na,na,na,color=cDI,xloc=xloc.bar_time,style=line.style_arrow_right)
var diline3=line.new(na,na,na,na,color=cDI,xloc=xloc.bar_time,style=line.style_arrow_right)
var diline4=line.new(na,na,na,na,color=cDI,xloc=xloc.bar_time,style=line.style_arrow_right)
var diline5=line.new(na,na,na,na,color=cDI,xloc=xloc.bar_time,style=line.style_arrow_right)
var diline6=line.new(na,na,na,na,color=cDI,xloc=xloc.bar_time,style=line.style_arrow_right)
var diline7=line.new(na,na,na,na,color=cDI,xloc=xloc.bar_time,style=line.style_arrow_right)
var diline8=line.new(na,na,na,na,color=cDI,xloc=xloc.bar_time,style=line.style_arrow_right)

var _diline1=line.new(na,na,na,na,color=c_DI,xloc=xloc.bar_time,style=line.style_arrow_right)
var _diline2=line.new(na,na,na,na,color=c_DI,xloc=xloc.bar_time,style=line.style_arrow_right)
var _diline3=line.new(na,na,na,na,color=c_DI,xloc=xloc.bar_time,style=line.style_arrow_right)
var _diline4=line.new(na,na,na,na,color=c_DI,xloc=xloc.bar_time,style=line.style_arrow_right)
var _diline5=line.new(na,na,na,na,color=c_DI,xloc=xloc.bar_time,style=line.style_arrow_right)
var _diline6=line.new(na,na,na,na,color=c_DI,xloc=xloc.bar_time,style=line.style_arrow_right)
var _diline7=line.new(na,na,na,na,color=c_DI,xloc=xloc.bar_time,style=line.style_arrow_right)
var _diline8=line.new(na,na,na,na,color=c_DI,xloc=xloc.bar_time,style=line.style_arrow_right)

var dmibox=box.new(na,na,na,na,border_color=na,bgcolor=color.new(color.yellow,90),xloc=xloc.bar_time,text="DMI",text_color=cBoxT,text_size=size.normal)

if b_DMI
    dmibox.set_lefttop(box.get_left(mybox)-width_bar_time*8,box.get_top(mybox))
    dmibox.set_rightbottom(box.get_left(mybox),box.get_bottom(mybox))

    adxline1.set_xy1(box.get_left(mybox)-width_bar_time,f_map2box(adx14,mybox))
    adxline1.set_xy2(box.get_left(mybox),f_map2box(adx9,mybox))
    adxline2.set_xy1(box.get_left(mybox)-width_bar_time*2,f_map2box(adx14[1],mybox))
    adxline2.set_xy2(box.get_left(mybox)-width_bar_time,f_map2box(adx9[1],mybox))
    adxline3.set_xy1(box.get_left(mybox)-width_bar_time*3,f_map2box(adx14[2],mybox))
    adxline3.set_xy2(box.get_left(mybox)-width_bar_time*2,f_map2box(adx9[2],mybox))
    adxline4.set_xy1(box.get_left(mybox)-width_bar_time*4,f_map2box(adx14[3],mybox))
    adxline4.set_xy2(box.get_left(mybox)-width_bar_time*3,f_map2box(adx9[3],mybox))
    adxline5.set_xy1(box.get_left(mybox)-width_bar_time*5,f_map2box(adx14[4],mybox))
    adxline5.set_xy2(box.get_left(mybox)-width_bar_time*4,f_map2box(adx9[4],mybox))
    adxline6.set_xy1(box.get_left(mybox)-width_bar_time*6,f_map2box(adx14[5],mybox))
    adxline6.set_xy2(box.get_left(mybox)-width_bar_time*5,f_map2box(adx9[5],mybox))
    adxline7.set_xy1(box.get_left(mybox)-width_bar_time*7,f_map2box(adx14[6],mybox))
    adxline7.set_xy2(box.get_left(mybox)-width_bar_time*6,f_map2box(adx9[6],mybox))
    adxline8.set_xy1(box.get_left(mybox)-width_bar_time*8,f_map2box(adx14[7],mybox))
    adxline8.set_xy2(box.get_left(mybox)-width_bar_time*7,f_map2box(adx9[7],mybox))

    diline1.set_xy1(box.get_left(mybox)-width_bar_time,f_map2box(di14,mybox))
    diline1.set_xy2(box.get_left(mybox),f_map2box(di9,mybox))
    diline2.set_xy1(box.get_left(mybox)-width_bar_time*2,f_map2box(di14[1],mybox))
    diline2.set_xy2(box.get_left(mybox)-width_bar_time,f_map2box(di9[1],mybox))
    diline3.set_xy1(box.get_left(mybox)-width_bar_time*3,f_map2box(di14[2],mybox))
    diline3.set_xy2(box.get_left(mybox)-width_bar_time*2,f_map2box(di9[2],mybox))
    diline4.set_xy1(box.get_left(mybox)-width_bar_time*4,f_map2box(di14[3],mybox))
    diline4.set_xy2(box.get_left(mybox)-width_bar_time*3,f_map2box(di9[3],mybox))
    diline5.set_xy1(box.get_left(mybox)-width_bar_time*5,f_map2box(di14[4],mybox))
    diline5.set_xy2(box.get_left(mybox)-width_bar_time*4,f_map2box(di9[4],mybox))
    diline6.set_xy1(box.get_left(mybox)-width_bar_time*6,f_map2box(di14[5],mybox))
    diline6.set_xy2(box.get_left(mybox)-width_bar_time*5,f_map2box(di9[5],mybox))
    diline7.set_xy1(box.get_left(mybox)-width_bar_time*7,f_map2box(di14[6],mybox))
    diline7.set_xy2(box.get_left(mybox)-width_bar_time*6,f_map2box(di9[6],mybox))
    diline8.set_xy1(box.get_left(mybox)-width_bar_time*8,f_map2box(di14[7],mybox))
    diline8.set_xy2(box.get_left(mybox)-width_bar_time*7,f_map2box(di9[7],mybox))

    _diline1.set_xy1(box.get_left(mybox)-width_bar_time,f_map2box(_di14,mybox))
    _diline1.set_xy2(box.get_left(mybox),f_map2box(_di9,mybox))
    _diline2.set_xy1(box.get_left(mybox)-width_bar_time*2,f_map2box(_di14[1],mybox))
    _diline2.set_xy2(box.get_left(mybox)-width_bar_time,f_map2box(_di9[1],mybox))
    _diline3.set_xy1(box.get_left(mybox)-width_bar_time*3,f_map2box(_di14[2],mybox))
    _diline3.set_xy2(box.get_left(mybox)-width_bar_time*2,f_map2box(_di9[2],mybox))
    _diline4.set_xy1(box.get_left(mybox)-width_bar_time*4,f_map2box(_di14[3],mybox))
    _diline4.set_xy2(box.get_left(mybox)-width_bar_time*3,f_map2box(_di9[3],mybox))
    _diline5.set_xy1(box.get_left(mybox)-width_bar_time*5,f_map2box(_di14[4],mybox))
    _diline5.set_xy2(box.get_left(mybox)-width_bar_time*4,f_map2box(_di9[4],mybox))
    _diline6.set_xy1(box.get_left(mybox)-width_bar_time*6,f_map2box(_di14[5],mybox))
    _diline6.set_xy2(box.get_left(mybox)-width_bar_time*5,f_map2box(_di9[5],mybox))
    _diline7.set_xy1(box.get_left(mybox)-width_bar_time*7,f_map2box(_di14[6],mybox))
    _diline7.set_xy2(box.get_left(mybox)-width_bar_time*6,f_map2box(_di9[6],mybox))
    _diline8.set_xy1(box.get_left(mybox)-width_bar_time*8,f_map2box(_di14[7],mybox))
    _diline8.set_xy2(box.get_left(mybox)-width_bar_time*7,f_map2box(_di9[7],mybox))

[di9_1,_di9_1,adx9_1]=H.htf_dmi(m1,b_new_bar1,9)
[di14_1,_di14_1,adx14_1]=H.htf_dmi(m1,b_new_bar1,14)

var a_adx9_1=array.new_float(0,na)
var a_adx14_1=array.new_float(0,na)
var a_di9_1=array.new_float(0,na)
var a_di14_1=array.new_float(0,na)
var a__di9_1=array.new_float(0,na)
var a__di14_1=array.new_float(0,na)

a_adx9_1.htf_push(b_new_bar1,adx9_1)
a_adx14_1.htf_push(b_new_bar1,adx14_1)
a_di9_1.htf_push(b_new_bar1,di9_1)
a_di14_1.htf_push(b_new_bar1,di14_1)
a__di9_1.htf_push(b_new_bar1,_di9_1)
a__di14_1.htf_push(b_new_bar1,_di14_1)

var adxline1_1=line.new(na,na,na,na,color=cADX,style=line.style_arrow_right,width=1)
var adxline2_1=line.new(na,na,na,na,color=cADX,style=line.style_arrow_right,width=1)
var adxline3_1=line.new(na,na,na,na,color=cADX,style=line.style_arrow_right,width=1)
var adxline4_1=line.new(na,na,na,na,color=cADX,style=line.style_arrow_right,width=1)
var adxline5_1=line.new(na,na,na,na,color=cADX,style=line.style_arrow_right,width=1)
var adxline6_1=line.new(na,na,na,na,color=cADX,style=line.style_arrow_right,width=1)
var adxline7_1=line.new(na,na,na,na,color=cADX,style=line.style_arrow_right,width=1)
var adxline8_1=line.new(na,na,na,na,color=cADX,style=line.style_arrow_right,width=1)

var diline1_1=line.new(na,na,na,na,color=cDI,style=line.style_arrow_right,width=1)
var diline2_1=line.new(na,na,na,na,color=cDI,style=line.style_arrow_right,width=1)
var diline3_1=line.new(na,na,na,na,color=cDI,style=line.style_arrow_right,width=1)
var diline4_1=line.new(na,na,na,na,color=cDI,style=line.style_arrow_right,width=1)
var diline5_1=line.new(na,na,na,na,color=cDI,style=line.style_arrow_right,width=1)
var diline6_1=line.new(na,na,na,na,color=cDI,style=line.style_arrow_right,width=1)
var diline7_1=line.new(na,na,na,na,color=cDI,style=line.style_arrow_right,width=1)
var diline8_1=line.new(na,na,na,na,color=cDI,style=line.style_arrow_right,width=1)

var _diline1_1=line.new(na,na,na,na,color=c_DI,style=line.style_arrow_right,width=1)
var _diline2_1=line.new(na,na,na,na,color=c_DI,style=line.style_arrow_right,width=1)
var _diline3_1=line.new(na,na,na,na,color=c_DI,style=line.style_arrow_right,width=1)
var _diline4_1=line.new(na,na,na,na,color=c_DI,style=line.style_arrow_right,width=1)
var _diline5_1=line.new(na,na,na,na,color=c_DI,style=line.style_arrow_right,width=1)
var _diline6_1=line.new(na,na,na,na,color=c_DI,style=line.style_arrow_right,width=1)
var _diline7_1=line.new(na,na,na,na,color=c_DI,style=line.style_arrow_right,width=1)
var _diline8_1=line.new(na,na,na,na,color=c_DI,style=line.style_arrow_right,width=1)

if b_DMI
    range1.set_text(symbol_htf1+"DMI")
    f_line_set_xyz(adxline1_1,box.get_right(range1)-1,f_map2box(a_adx14_1.lastx(),range1),f_map2box(a_adx9_1.lastx(),range1))
    f_line_set_xyz(adxline2_1,box.get_right(range1)-2,f_map2box(a_adx14_1.lastx(1),range1),f_map2box(a_adx9_1.lastx(1),range1))
    f_line_set_xyz(adxline3_1,box.get_right(range1)-3,f_map2box(a_adx14_1.lastx(2),range1),f_map2box(a_adx9_1.lastx(2),range1))
    f_line_set_xyz(adxline4_1,box.get_right(range1)-4,f_map2box(a_adx14_1.lastx(3),range1),f_map2box(a_adx9_1.lastx(3),range1))
    f_line_set_xyz(adxline5_1,box.get_right(range1)-5,f_map2box(a_adx14_1.lastx(4),range1),f_map2box(a_adx9_1.lastx(4),range1))
    f_line_set_xyz(adxline6_1,box.get_right(range1)-6,f_map2box(a_adx14_1.lastx(5),range1),f_map2box(a_adx9_1.lastx(5),range1))
    f_line_set_xyz(adxline7_1,box.get_right(range1)-7,f_map2box(a_adx14_1.lastx(6),range1),f_map2box(a_adx9_1.lastx(6),range1))
    f_line_set_xyz(adxline8_1,box.get_right(range1)-8,f_map2box(a_adx14_1.lastx(7),range1),f_map2box(a_adx9_1.lastx(7),range1))

    f_line_set_xyz(diline1_1,box.get_right(range1)-1,f_map2box(a_di14_1.lastx(),range1),f_map2box(a_di9_1.lastx(),range1))
    f_line_set_xyz(diline2_1,box.get_right(range1)-2,f_map2box(a_di14_1.lastx(1),range1),f_map2box(a_di9_1.lastx(1),range1))
    f_line_set_xyz(diline3_1,box.get_right(range1)-3,f_map2box(a_di14_1.lastx(2),range1),f_map2box(a_di9_1.lastx(2),range1))
    f_line_set_xyz(diline4_1,box.get_right(range1)-4,f_map2box(a_di14_1.lastx(3),range1),f_map2box(a_di9_1.lastx(3),range1))
    f_line_set_xyz(diline5_1,box.get_right(range1)-5,f_map2box(a_di14_1.lastx(4),range1),f_map2box(a_di9_1.lastx(4),range1))
    f_line_set_xyz(diline6_1,box.get_right(range1)-6,f_map2box(a_di14_1.lastx(5),range1),f_map2box(a_di9_1.lastx(5),range1))
    f_line_set_xyz(diline7_1,box.get_right(range1)-7,f_map2box(a_di14_1.lastx(6),range1),f_map2box(a_di9_1.lastx(6),range1))
    f_line_set_xyz(diline8_1,box.get_right(range1)-8,f_map2box(a_di14_1.lastx(7),range1),f_map2box(a_di9_1.lastx(7),range1))

    f_line_set_xyz(_diline1_1,box.get_right(range1)-1,f_map2box(a__di14_1.lastx(),range1),f_map2box(a__di9_1.lastx(),range1))
    f_line_set_xyz(_diline2_1,box.get_right(range1)-2,f_map2box(a__di14_1.lastx(1),range1),f_map2box(a__di9_1.lastx(1),range1))
    f_line_set_xyz(_diline3_1,box.get_right(range1)-3,f_map2box(a__di14_1.lastx(2),range1),f_map2box(a__di9_1.lastx(2),range1))
    f_line_set_xyz(_diline4_1,box.get_right(range1)-4,f_map2box(a__di14_1.lastx(3),range1),f_map2box(a__di9_1.lastx(3),range1))
    f_line_set_xyz(_diline5_1,box.get_right(range1)-5,f_map2box(a__di14_1.lastx(4),range1),f_map2box(a__di9_1.lastx(4),range1))
    f_line_set_xyz(_diline6_1,box.get_right(range1)-6,f_map2box(a__di14_1.lastx(5),range1),f_map2box(a__di9_1.lastx(5),range1))
    f_line_set_xyz(_diline7_1,box.get_right(range1)-7,f_map2box(a__di14_1.lastx(6),range1),f_map2box(a__di9_1.lastx(6),range1))
    f_line_set_xyz(_diline8_1,box.get_right(range1)-8,f_map2box(a__di14_1.lastx(7),range1),f_map2box(a__di9_1.lastx(7),range1))


[di9_2,_di9_2,adx9_2]=H.htf_dmi(m2,b_new_bar2,9)
[di14_2,_di14_2,adx14_2]=H.htf_dmi(m2,b_new_bar2,14)

var a_adx9_2=array.new_float(0,na)
var a_adx14_2=array.new_float(0,na)
var a_di9_2=array.new_float(0,na)
var a_di14_2=array.new_float(0,na)
var a__di9_2=array.new_float(0,na)
var a__di14_2=array.new_float(0,na)

a_adx9_2.htf_push(b_new_bar2,adx9_2)
a_adx14_2.htf_push(b_new_bar2,adx14_2)
a_di9_2.htf_push(b_new_bar2,di9_2)
a_di14_2.htf_push(b_new_bar2,di14_2)
a__di9_2.htf_push(b_new_bar2,_di9_2)
a__di14_2.htf_push(b_new_bar2,_di14_2)

var adxline1_2=line.new(na,na,na,na,color=cADX,style=line.style_arrow_right,width=2)
var adxline2_2=line.new(na,na,na,na,color=cADX,style=line.style_arrow_right,width=2)
var adxline3_2=line.new(na,na,na,na,color=cADX,style=line.style_arrow_right,width=2)
var adxline4_2=line.new(na,na,na,na,color=cADX,style=line.style_arrow_right,width=2)
var adxline5_2=line.new(na,na,na,na,color=cADX,style=line.style_arrow_right,width=2)
var adxline6_2=line.new(na,na,na,na,color=cADX,style=line.style_arrow_right,width=2)
var adxline7_2=line.new(na,na,na,na,color=cADX,style=line.style_arrow_right,width=2)
var adxline8_2=line.new(na,na,na,na,color=cADX,style=line.style_arrow_right,width=2)

var diline1_2=line.new(na,na,na,na,color=cDI,style=line.style_arrow_right,width=2)
var diline2_2=line.new(na,na,na,na,color=cDI,style=line.style_arrow_right,width=2)
var diline3_2=line.new(na,na,na,na,color=cDI,style=line.style_arrow_right,width=2)
var diline4_2=line.new(na,na,na,na,color=cDI,style=line.style_arrow_right,width=2)
var diline5_2=line.new(na,na,na,na,color=cDI,style=line.style_arrow_right,width=2)
var diline6_2=line.new(na,na,na,na,color=cDI,style=line.style_arrow_right,width=2)
var diline7_2=line.new(na,na,na,na,color=cDI,style=line.style_arrow_right,width=2)
var diline8_2=line.new(na,na,na,na,color=cDI,style=line.style_arrow_right,width=2)

var _diline1_2=line.new(na,na,na,na,color=c_DI,style=line.style_arrow_right,width=2)
var _diline2_2=line.new(na,na,na,na,color=c_DI,style=line.style_arrow_right,width=2)
var _diline3_2=line.new(na,na,na,na,color=c_DI,style=line.style_arrow_right,width=2)
var _diline4_2=line.new(na,na,na,na,color=c_DI,style=line.style_arrow_right,width=2)
var _diline5_2=line.new(na,na,na,na,color=c_DI,style=line.style_arrow_right,width=2)
var _diline6_2=line.new(na,na,na,na,color=c_DI,style=line.style_arrow_right,width=2)
var _diline7_2=line.new(na,na,na,na,color=c_DI,style=line.style_arrow_right,width=2)
var _diline8_2=line.new(na,na,na,na,color=c_DI,style=line.style_arrow_right,width=2)

if b_DMI
    range2.set_text(symbol_htf2+"DMI")
    f_line_set_xyz(adxline1_2,box.get_right(range2)-1,f_map2box(a_adx14_2.lastx(),range2),f_map2box(a_adx9_2.lastx(),range2))
    f_line_set_xyz(adxline2_2,box.get_right(range2)-2,f_map2box(a_adx14_2.lastx(1),range2),f_map2box(a_adx9_2.lastx(1),range2))
    f_line_set_xyz(adxline3_2,box.get_right(range2)-3,f_map2box(a_adx14_2.lastx(2),range2),f_map2box(a_adx9_2.lastx(2),range2))
    f_line_set_xyz(adxline4_2,box.get_right(range2)-4,f_map2box(a_adx14_2.lastx(3),range2),f_map2box(a_adx9_2.lastx(3),range2))
    f_line_set_xyz(adxline5_2,box.get_right(range2)-5,f_map2box(a_adx14_2.lastx(4),range2),f_map2box(a_adx9_2.lastx(4),range2))
    f_line_set_xyz(adxline6_2,box.get_right(range2)-6,f_map2box(a_adx14_2.lastx(5),range2),f_map2box(a_adx9_2.lastx(5),range2))
    f_line_set_xyz(adxline7_2,box.get_right(range2)-7,f_map2box(a_adx14_2.lastx(6),range2),f_map2box(a_adx9_2.lastx(6),range2))
    f_line_set_xyz(adxline8_2,box.get_right(range2)-8,f_map2box(a_adx14_2.lastx(7),range2),f_map2box(a_adx9_2.lastx(7),range2))

    f_line_set_xyz(diline1_2,box.get_right(range2)-1,f_map2box(a_di14_2.lastx(),range2),f_map2box(a_di9_2.lastx(),range2))
    f_line_set_xyz(diline2_2,box.get_right(range2)-2,f_map2box(a_di14_2.lastx(1),range2),f_map2box(a_di9_2.lastx(1),range2))
    f_line_set_xyz(diline3_2,box.get_right(range2)-3,f_map2box(a_di14_2.lastx(2),range2),f_map2box(a_di9_2.lastx(2),range2))
    f_line_set_xyz(diline4_2,box.get_right(range2)-4,f_map2box(a_di14_2.lastx(3),range2),f_map2box(a_di9_2.lastx(3),range2))
    f_line_set_xyz(diline5_2,box.get_right(range2)-5,f_map2box(a_di14_2.lastx(4),range2),f_map2box(a_di9_2.lastx(4),range2))
    f_line_set_xyz(diline6_2,box.get_right(range2)-6,f_map2box(a_di14_2.lastx(5),range2),f_map2box(a_di9_2.lastx(5),range2))
    f_line_set_xyz(diline7_2,box.get_right(range2)-7,f_map2box(a_di14_2.lastx(6),range2),f_map2box(a_di9_2.lastx(6),range2))
    f_line_set_xyz(diline8_2,box.get_right(range2)-8,f_map2box(a_di14_2.lastx(7),range2),f_map2box(a_di9_2.lastx(7),range2))

    f_line_set_xyz(_diline1_2,box.get_right(range2)-1,f_map2box(a__di14_2.lastx(),range2),f_map2box(a__di9_2.lastx(),range2))
    f_line_set_xyz(_diline2_2,box.get_right(range2)-2,f_map2box(a__di14_2.lastx(1),range2),f_map2box(a__di9_2.lastx(1),range2))
    f_line_set_xyz(_diline3_2,box.get_right(range2)-3,f_map2box(a__di14_2.lastx(2),range2),f_map2box(a__di9_2.lastx(2),range2))
    f_line_set_xyz(_diline4_2,box.get_right(range2)-4,f_map2box(a__di14_2.lastx(3),range2),f_map2box(a__di9_2.lastx(3),range2))
    f_line_set_xyz(_diline5_2,box.get_right(range2)-5,f_map2box(a__di14_2.lastx(4),range2),f_map2box(a__di9_2.lastx(4),range2))
    f_line_set_xyz(_diline6_2,box.get_right(range2)-6,f_map2box(a__di14_2.lastx(5),range2),f_map2box(a__di9_2.lastx(5),range2))
    f_line_set_xyz(_diline7_2,box.get_right(range2)-7,f_map2box(a__di14_2.lastx(6),range2),f_map2box(a__di9_2.lastx(6),range2))
    f_line_set_xyz(_diline8_2,box.get_right(range2)-8,f_map2box(a__di14_2.lastx(7),range2),f_map2box(a__di9_2.lastx(7),range2))

[di9_3,_di9_3,adx9_3]=H.htf_dmi(m3,b_new_bar3,9)
[di14_3,_di14_3,adx14_3]=H.htf_dmi(m3,b_new_bar3,14)

var a_adx9_3=array.new_float(0,na)
var a_adx14_3=array.new_float(0,na)
var a_di9_3=array.new_float(0,na)
var a_di14_3=array.new_float(0,na)
var a__di9_3=array.new_float(0,na)
var a__di14_3=array.new_float(0,na)

a_adx9_3.htf_push(b_new_bar3,adx9_3)
a_adx14_3.htf_push(b_new_bar3,adx14_3)
a_di9_3.htf_push(b_new_bar3,di9_3)
a_di14_3.htf_push(b_new_bar3,di14_3)
a__di9_3.htf_push(b_new_bar3,_di9_3)
a__di14_3.htf_push(b_new_bar3,_di14_3)

var adxline1_3=line.new(na,na,na,na,color=cADX,style=line.style_arrow_right,width=3)
var adxline2_3=line.new(na,na,na,na,color=cADX,style=line.style_arrow_right,width=3)
var adxline3_3=line.new(na,na,na,na,color=cADX,style=line.style_arrow_right,width=3)
var adxline4_3=line.new(na,na,na,na,color=cADX,style=line.style_arrow_right,width=3)
var adxline5_3=line.new(na,na,na,na,color=cADX,style=line.style_arrow_right,width=3)
var adxline6_3=line.new(na,na,na,na,color=cADX,style=line.style_arrow_right,width=3)
var adxline7_3=line.new(na,na,na,na,color=cADX,style=line.style_arrow_right,width=3)
var adxline8_3=line.new(na,na,na,na,color=cADX,style=line.style_arrow_right,width=3)

var diline1_3=line.new(na,na,na,na,color=cDI,style=line.style_arrow_right,width=3)
var diline2_3=line.new(na,na,na,na,color=cDI,style=line.style_arrow_right,width=3)
var diline3_3=line.new(na,na,na,na,color=cDI,style=line.style_arrow_right,width=3)
var diline4_3=line.new(na,na,na,na,color=cDI,style=line.style_arrow_right,width=3)
var diline5_3=line.new(na,na,na,na,color=cDI,style=line.style_arrow_right,width=3)
var diline6_3=line.new(na,na,na,na,color=cDI,style=line.style_arrow_right,width=3)
var diline7_3=line.new(na,na,na,na,color=cDI,style=line.style_arrow_right,width=3)
var diline8_3=line.new(na,na,na,na,color=cDI,style=line.style_arrow_right,width=3)

var _diline1_3=line.new(na,na,na,na,color=c_DI,style=line.style_arrow_right,width=3)
var _diline2_3=line.new(na,na,na,na,color=c_DI,style=line.style_arrow_right,width=3)
var _diline3_3=line.new(na,na,na,na,color=c_DI,style=line.style_arrow_right,width=3)
var _diline4_3=line.new(na,na,na,na,color=c_DI,style=line.style_arrow_right,width=3)
var _diline5_3=line.new(na,na,na,na,color=c_DI,style=line.style_arrow_right,width=3)
var _diline6_3=line.new(na,na,na,na,color=c_DI,style=line.style_arrow_right,width=3)
var _diline7_3=line.new(na,na,na,na,color=c_DI,style=line.style_arrow_right,width=3)
var _diline8_3=line.new(na,na,na,na,color=c_DI,style=line.style_arrow_right,width=3)

if b_DMI
    range3.set_text(symbol_htf3+"DMI")
    f_line_set_xyz(adxline1_3,box.get_right(range3)-1,f_map2box(a_adx14_3.lastx(),range3),f_map2box(a_adx9_3.lastx(),range3))
    f_line_set_xyz(adxline2_3,box.get_right(range3)-2,f_map2box(a_adx14_3.lastx(1),range3),f_map2box(a_adx9_3.lastx(1),range3))
    f_line_set_xyz(adxline3_3,box.get_right(range3)-3,f_map2box(a_adx14_3.lastx(2),range3),f_map2box(a_adx9_3.lastx(2),range3))
    f_line_set_xyz(adxline4_3,box.get_right(range3)-4,f_map2box(a_adx14_3.lastx(3),range3),f_map2box(a_adx9_3.lastx(3),range3))
    f_line_set_xyz(adxline5_3,box.get_right(range3)-5,f_map2box(a_adx14_3.lastx(4),range3),f_map2box(a_adx9_3.lastx(4),range3))
    f_line_set_xyz(adxline6_3,box.get_right(range3)-6,f_map2box(a_adx14_3.lastx(5),range3),f_map2box(a_adx9_3.lastx(5),range3))
    f_line_set_xyz(adxline7_3,box.get_right(range3)-7,f_map2box(a_adx14_3.lastx(6),range3),f_map2box(a_adx9_3.lastx(6),range3))
    f_line_set_xyz(adxline8_3,box.get_right(range3)-8,f_map2box(a_adx14_3.lastx(7),range3),f_map2box(a_adx9_3.lastx(7),range3))

    f_line_set_xyz(diline1_3,box.get_right(range3)-1,f_map2box(a_di14_3.lastx(),range3),f_map2box(a_di9_3.lastx(),range3))
    f_line_set_xyz(diline2_3,box.get_right(range3)-2,f_map2box(a_di14_3.lastx(1),range3),f_map2box(a_di9_3.lastx(1),range3))
    f_line_set_xyz(diline3_3,box.get_right(range3)-3,f_map2box(a_di14_3.lastx(2),range3),f_map2box(a_di9_3.lastx(2),range3))
    f_line_set_xyz(diline4_3,box.get_right(range3)-4,f_map2box(a_di14_3.lastx(3),range3),f_map2box(a_di9_3.lastx(3),range3))
    f_line_set_xyz(diline5_3,box.get_right(range3)-5,f_map2box(a_di14_3.lastx(4),range3),f_map2box(a_di9_3.lastx(4),range3))
    f_line_set_xyz(diline6_3,box.get_right(range3)-6,f_map2box(a_di14_3.lastx(5),range3),f_map2box(a_di9_3.lastx(5),range3))
    f_line_set_xyz(diline7_3,box.get_right(range3)-7,f_map2box(a_di14_3.lastx(6),range3),f_map2box(a_di9_3.lastx(6),range3))
    f_line_set_xyz(diline8_3,box.get_right(range3)-8,f_map2box(a_di14_3.lastx(7),range3),f_map2box(a_di9_3.lastx(7),range3))

    f_line_set_xyz(_diline1_3,box.get_right(range3)-1,f_map2box(a__di14_3.lastx(),range3),f_map2box(a__di9_3.lastx(),range3))
    f_line_set_xyz(_diline2_3,box.get_right(range3)-2,f_map2box(a__di14_3.lastx(1),range3),f_map2box(a__di9_3.lastx(1),range3))
    f_line_set_xyz(_diline3_3,box.get_right(range3)-3,f_map2box(a__di14_3.lastx(2),range3),f_map2box(a__di9_3.lastx(2),range3))
    f_line_set_xyz(_diline4_3,box.get_right(range3)-4,f_map2box(a__di14_3.lastx(3),range3),f_map2box(a__di9_3.lastx(3),range3))
    f_line_set_xyz(_diline5_3,box.get_right(range3)-5,f_map2box(a__di14_3.lastx(4),range3),f_map2box(a__di9_3.lastx(4),range3))
    f_line_set_xyz(_diline6_3,box.get_right(range3)-6,f_map2box(a__di14_3.lastx(5),range3),f_map2box(a__di9_3.lastx(5),range3))
    f_line_set_xyz(_diline7_3,box.get_right(range3)-7,f_map2box(a__di14_3.lastx(6),range3),f_map2box(a__di9_3.lastx(6),range3))
    f_line_set_xyz(_diline8_3,box.get_right(range3)-8,f_map2box(a__di14_3.lastx(7),range3),f_map2box(a__di9_3.lastx(7),range3))

[di9_4,_di9_4,adx9_4]=H.htf_dmi(m4,b_new_bar4,9)
[di14_4,_di14_4,adx14_4]=H.htf_dmi(m4,b_new_bar4,14)

var a_adx9_4=array.new_float(0,na)
var a_adx14_4=array.new_float(0,na)
var a_di9_4=array.new_float(0,na)
var a_di14_4=array.new_float(0,na)
var a__di9_4=array.new_float(0,na)
var a__di14_4=array.new_float(0,na)

a_adx9_4.htf_push(b_new_bar4,adx9_4)
a_adx14_4.htf_push(b_new_bar4,adx14_4)
a_di9_4.htf_push(b_new_bar4,di9_4)
a_di14_4.htf_push(b_new_bar4,di14_4)
a__di9_4.htf_push(b_new_bar4,_di9_4)
a__di14_4.htf_push(b_new_bar4,_di14_4)

var adxline1_4=line.new(na,na,na,na,color=cADX,style=line.style_arrow_right,width=4)
var adxline2_4=line.new(na,na,na,na,color=cADX,style=line.style_arrow_right,width=4)
var adxline3_4=line.new(na,na,na,na,color=cADX,style=line.style_arrow_right,width=4)
var adxline4_4=line.new(na,na,na,na,color=cADX,style=line.style_arrow_right,width=4)
var adxline5_4=line.new(na,na,na,na,color=cADX,style=line.style_arrow_right,width=4)
var adxline6_4=line.new(na,na,na,na,color=cADX,style=line.style_arrow_right,width=4)
var adxline7_4=line.new(na,na,na,na,color=cADX,style=line.style_arrow_right,width=4)
var adxline8_4=line.new(na,na,na,na,color=cADX,style=line.style_arrow_right,width=4)

var diline1_4=line.new(na,na,na,na,color=cDI,style=line.style_arrow_right,width=4)
var diline2_4=line.new(na,na,na,na,color=cDI,style=line.style_arrow_right,width=4)
var diline3_4=line.new(na,na,na,na,color=cDI,style=line.style_arrow_right,width=4)
var diline4_4=line.new(na,na,na,na,color=cDI,style=line.style_arrow_right,width=4)
var diline5_4=line.new(na,na,na,na,color=cDI,style=line.style_arrow_right,width=4)
var diline6_4=line.new(na,na,na,na,color=cDI,style=line.style_arrow_right,width=4)
var diline7_4=line.new(na,na,na,na,color=cDI,style=line.style_arrow_right,width=4)
var diline8_4=line.new(na,na,na,na,color=cDI,style=line.style_arrow_right,width=4)

var _diline1_4=line.new(na,na,na,na,color=c_DI,style=line.style_arrow_right,width=4)
var _diline2_4=line.new(na,na,na,na,color=c_DI,style=line.style_arrow_right,width=4)
var _diline3_4=line.new(na,na,na,na,color=c_DI,style=line.style_arrow_right,width=4)
var _diline4_4=line.new(na,na,na,na,color=c_DI,style=line.style_arrow_right,width=4)
var _diline5_4=line.new(na,na,na,na,color=c_DI,style=line.style_arrow_right,width=4)
var _diline6_4=line.new(na,na,na,na,color=c_DI,style=line.style_arrow_right,width=4)
var _diline7_4=line.new(na,na,na,na,color=c_DI,style=line.style_arrow_right,width=4)
var _diline8_4=line.new(na,na,na,na,color=c_DI,style=line.style_arrow_right,width=4)

if b_DMI
    range4.set_text(symbol_htf4+"DMI")
    f_line_set_xyz(adxline1_4,box.get_right(range4)-1,f_map2box(a_adx14_4.lastx(),range4),f_map2box(a_adx9_4.lastx(),range4))
    f_line_set_xyz(adxline2_4,box.get_right(range4)-2,f_map2box(a_adx14_4.lastx(1),range4),f_map2box(a_adx9_4.lastx(1),range4))
    f_line_set_xyz(adxline3_4,box.get_right(range4)-3,f_map2box(a_adx14_4.lastx(2),range4),f_map2box(a_adx9_4.lastx(2),range4))
    f_line_set_xyz(adxline4_4,box.get_right(range4)-4,f_map2box(a_adx14_4.lastx(3),range4),f_map2box(a_adx9_4.lastx(3),range4))
    f_line_set_xyz(adxline5_4,box.get_right(range4)-5,f_map2box(a_adx14_4.lastx(4),range4),f_map2box(a_adx9_4.lastx(4),range4))
    f_line_set_xyz(adxline6_4,box.get_right(range4)-6,f_map2box(a_adx14_4.lastx(5),range4),f_map2box(a_adx9_4.lastx(5),range4))
    f_line_set_xyz(adxline7_4,box.get_right(range4)-7,f_map2box(a_adx14_4.lastx(6),range4),f_map2box(a_adx9_4.lastx(6),range4))
    f_line_set_xyz(adxline8_4,box.get_right(range4)-8,f_map2box(a_adx14_4.lastx(7),range4),f_map2box(a_adx9_4.lastx(7),range4))

    f_line_set_xyz(diline1_4,box.get_right(range4)-1,f_map2box(a_di14_4.lastx(),range4),f_map2box(a_di9_4.lastx(),range4))
    f_line_set_xyz(diline2_4,box.get_right(range4)-2,f_map2box(a_di14_4.lastx(1),range4),f_map2box(a_di9_4.lastx(1),range4))
    f_line_set_xyz(diline3_4,box.get_right(range4)-3,f_map2box(a_di14_4.lastx(2),range4),f_map2box(a_di9_4.lastx(2),range4))
    f_line_set_xyz(diline4_4,box.get_right(range4)-4,f_map2box(a_di14_4.lastx(3),range4),f_map2box(a_di9_4.lastx(3),range4))
    f_line_set_xyz(diline5_4,box.get_right(range4)-5,f_map2box(a_di14_4.lastx(4),range4),f_map2box(a_di9_4.lastx(4),range4))
    f_line_set_xyz(diline6_4,box.get_right(range4)-6,f_map2box(a_di14_4.lastx(5),range4),f_map2box(a_di9_4.lastx(5),range4))
    f_line_set_xyz(diline7_4,box.get_right(range4)-7,f_map2box(a_di14_4.lastx(6),range4),f_map2box(a_di9_4.lastx(6),range4))
    f_line_set_xyz(diline8_4,box.get_right(range4)-8,f_map2box(a_di14_4.lastx(7),range4),f_map2box(a_di9_4.lastx(7),range4))

    f_line_set_xyz(_diline1_4,box.get_right(range4)-1,f_map2box(a__di14_4.lastx(),range4),f_map2box(a__di9_4.lastx(),range4))
    f_line_set_xyz(_diline2_4,box.get_right(range4)-2,f_map2box(a__di14_4.lastx(1),range4),f_map2box(a__di9_4.lastx(1),range4))
    f_line_set_xyz(_diline3_4,box.get_right(range4)-3,f_map2box(a__di14_4.lastx(2),range4),f_map2box(a__di9_4.lastx(2),range4))
    f_line_set_xyz(_diline4_4,box.get_right(range4)-4,f_map2box(a__di14_4.lastx(3),range4),f_map2box(a__di9_4.lastx(3),range4))
    f_line_set_xyz(_diline5_4,box.get_right(range4)-5,f_map2box(a__di14_4.lastx(4),range4),f_map2box(a__di9_4.lastx(4),range4))
    f_line_set_xyz(_diline6_4,box.get_right(range4)-6,f_map2box(a__di14_4.lastx(5),range4),f_map2box(a__di9_4.lastx(5),range4))
    f_line_set_xyz(_diline7_4,box.get_right(range4)-7,f_map2box(a__di14_4.lastx(6),range4),f_map2box(a__di9_4.lastx(6),range4))
    f_line_set_xyz(_diline8_4,box.get_right(range4)-8,f_map2box(a__di14_4.lastx(7),range4),f_map2box(a__di9_4.lastx(7),range4))
//*****
//end of DMI
//*****

