MZ Adaptive Ichimoku Cloud (Volume, Volatility, Chikou Filter) 
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © MightyZinger

//@version=5

indicator('MZ Adaptive Ichimoku Cloud (Volume, Volatility, Chikou Filter) (MZ AIC)', shorttitle='MZ AIC', overlay=true)

import MightyZinger/RVSI/1 as mz
import MightyZinger/Chikou/3 as filter
import MightyZinger/Adaptive_Length/5 as length


uha  =input(true, title="Use Heikin Ashi Candles for Volume Oscillator Calculations")

// Use only Heikinashi Candles for all calculations
haclose = uha ? ohlc4 : close

f_ha_open() =>
    haopen   = float(na)
    haopen := na(haopen[1]) ? (open + close) / 2 : (nz(haopen[1]) + nz(haclose[1])) / 2
    haopen

haopen = uha ? f_ha_open() : open

vol = volume

/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
/////                     Source Options                       //////
/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////

// ─── Different Sources Options List ───► [
string SRC_Tv = 'Use traditional TradingView Sources '
string SRC_Wc = '(open+close+3(high+low))/8'
string SRC_Wo = 'close+high+low-2*open'
string SRC_Wu = '(close+5(high+low)-7(open))/4'
string SRC_Wi = '(open+close+5(high+low))/12'
string SRC_Exi = 'close>open ? high : low'
string SRC_Exj = 'Heiken-ashi(close>open) ? high : low'
string src_grp = 'Source Parameters'

// ●───────── Inputs ─────────● {
diff_src = input.string(SRC_Exi, '→ Different Sources Options', options=[SRC_Tv, SRC_Wc, SRC_Wo, SRC_Wu, SRC_Wi, SRC_Exi, SRC_Exj], group=src_grp)
i_sourceSetup = input.source(close, 'Tradingview Source Setup', group=src_grp)
i_Sym = input.bool(true, 'Apply Symmetrically Weighted Moving Average at the price source (May Result Repainting)', group=src_grp)

h_open  = f_ha_open()

// Get Source 
src_o = diff_src == SRC_Wc ? (open+close+3*(high+low))/8 :
     diff_src == SRC_Wo ? close+high+low-2*open :
     diff_src == SRC_Wu ? (close+5*(high+low)-7*(open))/4 :
     diff_src == SRC_Wi ? (open+close+5*(high+low))/12 : 
     diff_src == SRC_Exi ? (close > open ? high : low) :
     diff_src == SRC_Exj ? (ohlc4 > h_open ? high : low) :
     i_sourceSetup
     
src_f = i_Sym ? ta.swma(src_o) : src_o  // Symmetrically Weighted Moving Average?

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

// Ichimoku cloud display ON/OFF selections {
ich_group='☁️ Ichimoku Cloud ☁️'

ichimoku_onf = input.bool(true, 'Ichimoku On/Off', group = ich_group)
tenkanof = input.bool(true, 'Tenkan Sen', group = ich_group)
kijunof = input.bool(true, 'Kijun Sen', group = ich_group)
chikouof = input.bool(true, 'Chikou Span', group = ich_group)
senkouAof = input.bool(false, 'Senkou Span A', group = ich_group)
senkouBof = input.bool(false, 'Senkou Span B', group = ich_group)
cloudof = input.bool(true, 'Kumo Fill', group = ich_group)
//}

// Dynamic Length Range Inputs {
k_min_len = input.int(title='Kijun Min Length', defval=20, inline='i1', group = ich_group)
k_max_len = input.int(title='Kijun Max Length', defval=60, inline='i1', group = ich_group)

t_min_len = input.int(title='Tenkan Min Length', defval=9, inline='i2', group = ich_group)
t_max_len = input.int(title='Tenkan Max Length', defval=30, inline='i2', group = ich_group)

sn_offset = input.int(title='Senkou-Span Offset', defval=26, group = ich_group)
sn_min_len = input.int(title='Senkou-Span Min Length', defval=50, inline='i3', group = ich_group)
sn_max_len = input.int(title='Senkou-Span Max Length', defval=120, inline='i3', group = ich_group)

c_min_len = input.int(title='Chikou Min Length', defval=26, inline='i4', group = ich_group)
c_max_len = input.int(title='Chikou Max Length', defval=50, inline='i4', group = ich_group)
//}

//Adapting Percentage{
k_AadaptPerc = input.float(96.85, minval=0, maxval=100, title='Kijun Dynamic Length Adapting Percentage:', group = ich_group) / 100.0
t_AadaptPerc = input.float(96.85, minval=0, maxval=100, title='Tenkan Dynamic Length Adapting Percentage:', group = ich_group) / 100.0
sn_AadaptPerc = input.float(96.85, minval=0, maxval=100, title='Senkou Dynamic Length Adapting Percentage:', group = ich_group) / 100.0
c_AadaptPerc = input.float(96.85, minval=0, maxval=100, title='Chikou Dynamic Length Adapting Percentage:', group = ich_group) / 100.0
//}

// Chikou Fiter length and color inputs{
string c_grp = 'Chikou Filter Parameters'
c_len = input.int(25, title='Chikou Filter Period', group=c_grp)
c_bull_col = input.color(color.green, 'Chikou Bull Color  ', group = c_grp, inline='c_col')
c_bear_col = input.color(color.red, 'Chikou Bear Color  ', group = c_grp, inline='c_col')
c_rvsl_col = input.color(color.yellow, 'Chikou Consollidation/Reversal Color  ', group = c_grp, inline='c_col')
//}


// Dynamic Adaption Parameters Checks{
grp2 = 'Adapt Kijun Dynamic Length Based on '
grp3 = 'Adapt Tenkan Dynamic Length Based on '
grp4 = 'Show Trade Signals Based on'
grp5 = 'Adapt Chikou Dynamic Length Based on '
grp6 = 'Adapt Senkou Dynamic Length Based on '

// Adaptive Length Checks
ch1 = 'Volume'
ch2 = 'Cross(Tenkan,Kijun)'
ch3 = 'Volatility'
ch4 = 'Tenkan = Kijun'
ch5 = 'Chikou > Source'
ch6 = 'Chikou Momentum'
ch7 = 'Source > Kumo'
ch8 = 'Source > Tenkan'
ch9 = 'Chikou Backward Trend Filter'

k_volume_chk = input.bool(true, title=ch1, group=grp2, inline='k_chks')
k_volat_chk = input.bool(true, title=ch3, group=grp2, inline='k_chks')
k_chik_chk =  input.bool(true, title=ch9, group=grp2, inline='k_chks')

t_volume_chk = input.bool(true, title=ch1, group=grp3, inline='ten_chks')
t_volat_chk = input.bool(true, title=ch3, group=grp3, inline='ten_chks')
t_chik_chk =  input.bool(true, title=ch9, group=grp3, inline='ten_chks')

sn_volume_chk = input.bool(true, title=ch1, group=grp6, inline='sn_chks')
sn_volat_chk = input.bool(true, title=ch3, group=grp6, inline='sn_chks')
sn_chik_chk =  input.bool(true, title=ch9, group=grp6, inline='sn_chks')

c_volume_chk = input.bool(true, title=ch1, group=grp5, inline='c_chks')
c_volat_chk = input.bool(true, title=ch3, group=grp5, inline='c_chks')
c_chik_chk =  input.bool(true, title=ch9, group=grp5, inline='c_chks')

s_volume_chk = input.bool(true, title=ch1, group=grp4, inline='sell_chks')
s_cross_chk = input.bool(false, title=ch2, group=grp4, inline='sell_chks')
s_volat_chk = input.bool(true, title=ch3, group=grp4, inline='sell_chks')
s_eq_chk = input.bool(false, title=ch4, group=grp4, inline='sell_chks')
s_chikou_chk = input.bool(false, title=ch5, group=grp4, inline='sell_chks')
s_cs_mom_chk = input.bool(false, title=ch6, group=grp4, inline='sell_chks')
s_senkou_chk = input.bool(true, title=ch7, group=grp4, inline='sell_chks')
s_tenk_chk = input.bool(true, title=ch8, group=grp4, inline='sell_chks')
s_c_fltr_chk = input.bool(true, title=ch9, group=grp4, inline='sell_chks')
//}

/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
// Charting and Plotting display parameters{
show_color_bar = input.bool(title='Color Bars', defval=true, group='Plot Parameters')
showSignals = input.bool(true, title='Show Trade Signals', group='Plot Parameters')

bar_grp = 'Bars Coloring'
bar_bull = input.color(color.rgb(38, 208, 124, 0), 'src > tenkanSen and src > kijunSen', group = bar_grp)
bar_bear = input.color(color.rgb(225, 6, 0, 0), 'src < tenkanSen and src < kijunSen', group = bar_grp)
bar_bot_rev = input.color(color.rgb(255, 114, 118, 0), 'src > tenkanSen and src < kijunSen', group = bar_grp)
bar_top_rev = input.color(color.rgb(31, 32, 34, 0), 'src < tenkanSen and src > kijunSen', group = bar_grp)
//}

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

// Volume and other Inputs{
// Volume Oscillator Types Input

osc1 = 'TFS Volume Oscillator'
osc2 = 'On Balance Volume'
osc3 = 'Klinger Volume Oscillator'
osc4 = 'Cumulative Volume Oscillator'
osc5 = 'Volume Zone Oscillator'
k_osctype = input.string(title='Volume Oscillator Type for Kijun', group='RVSI Parameters', defval=osc2, options=[osc1, osc2, osc3, osc4, osc5])
t_osctype = input.string(title='Volume Oscillator Type for Tenkan', group='RVSI Parameters', defval=osc2, options=[osc1, osc2, osc3, osc4, osc5])
sn_osctype = input.string(title='Volume Oscillator Type for Senkou', group='RVSI Parameters', defval=osc2, options=[osc1, osc2, osc3, osc4, osc5])
c_osctype = input.string(title='Volume Oscillator Type for Chikou', group='RVSI Parameters', defval=osc2, options=[osc1, osc2, osc3, osc4, osc5])
s_osctype = input.string(title='Volume Oscillator Type for Sell Confirmation', group='RVSI Parameters', defval=osc2, options=[osc1, osc2, osc3, osc4, osc5])


rvsiLen = input.int(14, minval=1,title="RVSI Length", group="RVSI Parameters")

vBrk = input.int(50, minval=1,title="RVSI Break point", group="RVSI Parameters")

atrFlength = input.int(14, title="ATR Fast Length", group="Volatility Parameters")
atrSlength = input.int(46, title="ATR Slow Length", group="Volatility Parameters")
//}

/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
/////                   Kijun Function                         //////
/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////

// Kijun V2 Function {
kidiv = input.int(defval=1, maxval=4, title='Kijun MOD Divider')

// Kijun v2 Main function
kijunv2(src, len) =>
    var float result = 0.0
    kijun = math.avg(ta.lowest(len), ta.highest(len))  //, (open + close)/2)
    conversionLine = math.avg(ta.lowest(len / kidiv), ta.highest(len / kidiv))
    delta = (kijun + conversionLine) / 2
    result := delta
    result
//}

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

/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
/////        Relative Volume Strength Index  (MZ RVSI)         //////
/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////

// TFS Volume Oscillator
tfs_volLen = input.int(30, minval=1,title="Volume Length", group="TFS Volume Oscillator")
// Volume Zone Oscillator
vzo_Len = input.int(21, "VZO Length", minval=1, group="Volume Zone Oscillator Parameters")
//  Volume Oscillator function
kvo_FastX = input.int(34, minval=1,title="Volume Fast Length", group="KVO Parameters")
kvo_SlowX = input.int(55, minval=1,title="Volume Slow Length", group="KVO Parameters")

//  Cumulative Volume Oscillator
cvo(vol_src, rvsiLen, _open, _high, _low, _close) =>
    float result = 0
    ema1len = input.int(defval = 8, title = "EMA 1 Length", minval = 1, group="Cumulative Volume Oscillator Parameters")
    ema2len = input.int(defval = 21, title = "EMA 1 Length", minval = 1, group="Cumulative Volume Oscillator Parameters")
    obvl = "On Balance Volume"
    cvdo = "Cumulative Volume Delta"
    pvlt = "Price Volume Trend"
    cvtype = input.string(defval = pvlt, options = [obvl, cvdo, pvlt], group="Cumulative Volume Oscillator Parameters")
    
    _obv = mz.rvsi_cvo_obv(ema1len, ema2len, rvsiLen)
    _pvt = mz.rvsi_cvo_pvt(ema1len, ema2len, rvsiLen)
    _cvd = mz.rvsi_cvo_cvd(vol_src, ema1len, ema2len, rvsiLen, _open, _high, _low, _close)
    
    result := cvtype == obvl ? _obv : cvtype == cvdo ? _cvd : _pvt
    result


vol_osc(type, vol_src, _rvsiLen, _open, _high, _low, _close) =>
    float _rvsi = 0
    
    if type=="TFS Volume Oscillator"
        _rvsi := mz.rvsi_tfs(vol_src, tfs_volLen, _rvsiLen, _open, _close)
        
    if type=="On Balance Volume"
        _rvsi := mz.rvsi_obv(vol_src, _close, _rvsiLen)
        
    if type=="Klinger Volume Oscillator"
        _rvsi := mz.rvsi_kvo(vol_src, _close, kvo_FastX, kvo_SlowX, _rvsiLen)
        
    if type=="Cumulative Volume Oscillator"
        _rvsi := cvo(vol_src, _rvsiLen, _open, _high, _low, _close)
        
    if type=="Volume Zone Oscillator"
        _rvsi := mz.rvsi_vzo(vol_src, _close, vzo_Len, _rvsiLen)
    _rvsi

/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
//RVSI calculations for Kijun, Tenkan, Senkou, Chikou and Trade Confirmations{

// RVSI for Kijun 
k_rvsi = vol_osc(k_osctype,vol,rvsiLen,haopen,high,low,haclose) 

// RVSI for Tenkan
t_rvsi = vol_osc(t_osctype,vol,rvsiLen,haopen,high,low,haclose) 

// RVSI for Senkou 
sn_rvsi = vol_osc(sn_osctype,vol,rvsiLen,haopen,high,low,haclose) 

// RVSI for Chikou
c_rvsi = vol_osc(c_osctype,vol,rvsiLen,haopen,high,low,haclose) 

// RVSI for Sell Confirmation
s_rvsi = vol_osc(s_osctype,vol,rvsiLen,haopen,high,low,haclose)

// Volume Breakout Condition for Kijun 
k_volBrkUp = k_rvsi > vBrk // and rvsiSlp >=  flat 
k_volBrkDn = k_rvsi < vBrk //or rvsiSlp <= -flat //

// Volume Breakout Condition for Tenkan
t_volBrkUp = t_rvsi > vBrk // and rvsiSlp >=  flat 
t_volBrkDn = t_rvsi < vBrk //or rvsiSlp <= -flat //

// Volume Breakout Condition for Senkou
sn_volBrkUp = sn_rvsi > vBrk // and rvsiSlp >=  flat 
sn_volBrkDn = sn_rvsi < vBrk //or rvsiSlp <= -flat //

// Volume Breakout Condition for Chikou
c_volBrkUp = c_rvsi > vBrk // and rvsiSlp >=  flat 
c_volBrkDn = c_rvsi < vBrk //or rvsiSlp <= -flat //

// Volume Breakout Condition for Sell Confirmation
s_volBrkUp = s_rvsi > vBrk // and rvsiSlp >=  flat 
s_volBrkDn = s_rvsi < vBrk //or rvsiSlp <= -flat //
//}

//Volatility Meter
highVolatility = ta.atr(atrFlength) > ta.atr(atrSlength)

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

// Calling Chikou filter function from library to obtaing dynamic color of Chikou-Span and also Trend 
[chikou_clr, c_filter_sig] = filter.chikou(src_f, c_len, high, low, c_bull_col, c_bear_col, c_rvsl_col)  

// Function to form table between selection boolean parameters
f_para(chk_a, return_a)=>
	var result_p = bool(na)	
    // Initializing Return Parameter
    for i = 0 to array.size(chk_a)-1
        if array.get(chk_a, i) == true
            result_p := array.get(return_a, i)
            break
    // Checking other Return Parameters
	for i = 0 to array.size(chk_a)-1
		result_p := array.get(chk_a, i) ? array.get(return_a, i) and result_p : result_p	// Varifying Other Checks
	result_p

bool[] k_chk_array = array.from(k_volume_chk,
     k_volat_chk,
     k_chik_chk)
bool[] t_chk_array = array.from(t_volume_chk,
     t_volat_chk,
     t_chik_chk)
bool[] sn_chk_array = array.from(sn_volume_chk,
     sn_volat_chk,
     sn_chik_chk)
bool[] c_chk_array = array.from(c_volume_chk,
     c_volat_chk,
     c_chik_chk)

bool[] k_up_para_a = array.from(k_volBrkUp,
     highVolatility,
     c_filter_sig ==  1)
bool[] t_up_para_a = array.from(t_volBrkUp,
     highVolatility,
     c_filter_sig ==  1)
bool[] sn_up_para_a = array.from(sn_volBrkUp,
     highVolatility,
     c_filter_sig ==  1)
bool[] c_up_para_a = array.from(c_volBrkUp,
     highVolatility,
     c_filter_sig ==  1)

k_up_para = f_para(k_chk_array, k_up_para_a)
t_up_para = f_para(t_chk_array, t_up_para_a)
sn_up_para = f_para(sn_chk_array, sn_up_para_a)
c_up_para = f_para(c_chk_array, c_up_para_a)

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

// Calculating Dynamic Lengths
k_dyna = length.dynamic(k_up_para , k_AadaptPerc, k_min_len, k_max_len)
t_dyna = length.dynamic(t_up_para , t_AadaptPerc, t_min_len, t_max_len)
senko_dyna = length.dynamic(sn_up_para , sn_AadaptPerc, sn_min_len, sn_max_len)
c_dyna = length.dynamic(c_up_para , c_AadaptPerc, c_min_len, c_max_len)

// Calculating Kijun, Tenkan and Senkou
kijunSen = kijunv2(src_f, k_dyna)
tenkanSen = kijunv2(src_f, t_dyna)
senkouSpanA = math.avg(tenkanSen, kijunSen)
senkouSpanB = math.avg(ta.highest(high, senko_dyna), ta.lowest(low, senko_dyna))
chikouSpan = src_f

/////////////////////////////////////////////////////////////////////
// Plotting chikou-span on dynamic adaptive length based offset
plotchikouSpan = plot(ichimoku_onf ? chikouSpan : na, offset = -c_dyna, color=not chikouof ? na : chikou_clr, title='Chikou', linewidth=2)

// ---Color for Kumo Cloud
f_c_gradientRelative(_source, _min, _max, _c_bear, _c_bull) =>
    var float _center = _min + (_max - _min) / 2
    color _return = _source >= _center ? 
      color.from_gradient(_source, _center, _max, color.new(_c_bull, 100), color.new(_c_bull, 0)) : 
      color.from_gradient(_source, _min, _center, color.new(_c_bear, 0), color.new(_c_bear, 100))

sen_clr_src = (senkouSpanA - senkouSpanB) / src_f * 100
clrfill = senkouSpanA > senkouSpanB ? color.from_gradient(ta.rsi(math.avg(senkouSpanA , senkouSpanB), 14) , 0, 100, color.rgb(219,226,233), color.rgb(8,255,8)) :
     senkouSpanA < senkouSpanB ? color.from_gradient(ta.rsi(math.avg(senkouSpanA , senkouSpanB), 14) , 0, 100, color.rgb(229,225,230), color.rgb(210,39,48)) : color.rgb(229,225,230)

// ---Ploting Senkou-span A & B and Kumo
plotkijunSen = plot(ichimoku_onf ? kijunSen : na, offset=00, color=not kijunof ? na : color.rgb(157, 34, 53, 0), title='Kijun-Sen', linewidth=2)
plottenkanSen = plot(ichimoku_onf ? tenkanSen : na, offset=00, color=not tenkanof ? na : color.rgb(170, 219, 30, 0), title='Tenkan-Sen', linewidth=2)
plotsenkouSpanA = plot(ichimoku_onf ? senkouSpanA : na, offset = sn_offset-1, color=not senkouAof ? na : color.yellow, title='Senkou-Span A', linewidth=1)
plotsenkouSpanB = plot(ichimoku_onf ? senkouSpanB : na, offset = sn_offset-1, color=not senkouBof ? na : color.red, title='Senkou-Span B', linewidth=2)
fill(plotsenkouSpanA, plotsenkouSpanB, color=not cloudof ? na : color.new(clrfill, 80))

// Funtion to define Bars coloring
colbar(src, tenkanSen, kijunSen) =>
    col_bar = color.new(na, 10)
    col_bar := src > tenkanSen and src > kijunSen?  bar_bull :
         src < tenkanSen and src < kijunSen ?  bar_bear :
         src > tenkanSen and src < kijunSen ?  bar_bot_rev :
         src < tenkanSen and src > kijunSen ?  bar_top_rev : na
    col_bar

color_bar = colbar(close, tenkanSen, kijunSen)
barcolor(show_color_bar ? color_bar : na)

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

// Trade signals confirmations decided based on input checks
cs_bull = ta.mom(src_f, c_dyna - 1) > 0
cs_bear = ta.mom(src_f, c_dyna - 1) < 0

ss_high = math.max(senkouSpanA[sn_offset - 1], senkouSpanB[sn_offset - 1])
ss_low = math.min(senkouSpanA[sn_offset - 1], senkouSpanB[sn_offset - 1])
price_above_kumo = src_f > ss_high
price_below_kumo = src_f < ss_high // ss_low


bool[] chk_array = array.from(s_volume_chk,
     s_volat_chk,
     s_cross_chk,
     s_cs_mom_chk,
     s_chikou_chk,
     s_senkou_chk,
     s_tenk_chk,
     s_c_fltr_chk)

bool[] up_para_array = array.from(s_volBrkUp,
     highVolatility,
     tenkanSen > kijunSen,
     cs_bull,
     chikouSpan > src_f[int(c_dyna)],
     price_above_kumo,
     tenkanSen,
     c_filter_sig ==  1)

bool[] dn_para_array = array.from(s_volBrkDn,
     highVolatility,
     tenkanSen < kijunSen,
     cs_bear,
     chikouSpan < src_f[int(c_dyna)],
     price_below_kumo,
     src_f < tenkanSen,
     c_filter_sig == -1)


c_fltr_up = f_para(chk_array, up_para_array)
c_fltr_dn = f_para(chk_array, dn_para_array)

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


eq_up = s_eq_chk ? tenkanSen == kijunSen and tenkanSen[1] < kijunSen[1] or c_fltr_up : c_fltr_up
eq_dn = s_eq_chk ? tenkanSen == kijunSen and tenkanSen[1] > kijunSen[1] or c_fltr_dn : c_fltr_dn

_up = eq_up
_dn = eq_dn

// Defining Buy/Sell Signals
buy = _up and not _up[1]
sell = _dn and not _dn[1]

var sig = 0
if buy and sig <= 0
    sig := 1
if sell and sig >= 0
    sig := -1

longsignal = sig == 1 and sig[1] != 1
shortsignal = sig == -1 and sig[1] != -1

atrPos = 0.85 * ta.atr(5)
// Plotting Signals for every confirmed condition
plotshape(showSignals and buy ? low - atrPos : na, style=shape.circle, color=color.new(#AADB1E, 0), location=location.absolute, size=size.tiny)
plotshape(showSignals and sell ? high + atrPos : na, style=shape.circle, color=color.new(#E10600, 0), location=location.absolute, size=size.tiny)
// Plotting Long term Buy/Sell signals
plotshape(showSignals and longsignal ? (low ) - atrPos : na, style=shape.triangleup, color=color.new(color.green, 0), location=location.absolute, text='Buy', size=size.small)
plotshape(showSignals and shortsignal ? (high ) + atrPos : na, style=shape.triangledown, color=color.new(color.red, 0), location=location.absolute, text='Sell', size=size.small)
