Indicator Functions with Factor and  HeikinAshi
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © dturkuler
//Indicator Version 1.02
//ADD:  23 new indicators added. Most of them are TR builtin indicators (see description in TV builtin Indicators). Newly added indicators are listed below
//ADD:  pvth    =   'pivothigh(src,BarsLeft,BarsRight=2)'      //Previous pivot high. src=src, BarsLeft=len, BarsRight=p1=2
//ADD:  pvtl    =   'pivotlow(src,BarsLeft,BarsRight=2)'       //Previous pivot low. src=src, BarsLeft=len, BarsRight=p1=2
//ADD:  rangs   =   'ranges(src,upper=len, lower=-5)',         //ranges of the source. return -1 source<lower, return 1 source>upper otherwise return 0
//ADD:  aroon   =   'aroon(len,dir=0)',                        //aroon indicator. Aroon's major function is to identify new trends as they happen.p1 = dir: 0=mid (default), 1=upper, 2=lower
//ADD:  adx     =   'adx(dilen=len, adxlen=14)'                //adx. The Average Directional Index (ADX) is a used to determine the strength of a trend. len=>dilen, p1=adxlen (default=14), p2=adxtype 0:ADX, 1:+DI, 2:-DI (def:0)
//ADD:  awsom   =   'awesome(fast=len=5,slow=34,type=0)'       //Awesome Oscilator (AO) is an indicator used to measure market momentum. defaults : fast=len= 5, p1=slow=34, p2=type: 0=Awesome, 1=difference
//ADD:  cmf     =   'cmf(len=20)'                              //Chaikin Money Flow Indicator used to measure Money Flow Volume over a set period of time. Default use is len=20
//ADD:  eom     =   'eom(len=14,div=10000)',                   //Ease of Movement.It is designed to measure the relationship between price and volume.p1 = div: 10000= (default)
//ADD:  efi     =   'efi(len)'                                 //Elder's Force Index (EFI) measures the power behind a price movement using price and volume.
//ADD:  fit     =   'fn_fisher(len)'                           //Fisher Transform is a technical indicator that converts price to Gaussian normal distribution and signals when prices move significantly by referencing recent price data
//ADD:  hvo     =   'fn_histvol(len)',                         //Historical volatility is a statistical measure used to analyze the general dispersion of security or market index returns for a specified period of time.
//ADD:  dpo     =   'dpo(len)',                                //Detrended Price Oscilator is used to remove trend from price.   
//ADD:  kli     =   'klinger(type=len)',                       //Klinger oscillator aims to identify money flow’s long-term trend. type=len: 0:Oscilator 1:signal
//ADD:  msi     =   'msi(len=10)',                             //Mass Index (def=10) is used to examine the differences between high and low stock prices over a specific period of time
//ADD:  mgi     =   'mcginley(src, len)'                       //McGinley Dynamic adjusts for market speed shifts, which sets it apart from other moving averages, in addition to providing clear moving average lines
//ADD:  sar     =   'sar(start=len, inc=0.02, max=0.02)'       //Parabolic SAR (parabolic stop and reverse) is a method to find potential reversals in the market price direction of traded goods.start=len, inc=p1, max=p2. ex: sar(0.02, 0.02, 0.02)    
//ADD:  rvi     =   'rvi(src,len)',                            //The Relative Volatility Index (RVI) is calculated much like the RSI, although it uses high and low price standard deviation instead of the RSI’s method of absolute change in price.
//ADD:  ulos    =   'ultimateOsc(len)'                         //Ultimate Oscillator indicator (UO) indicator is a technical analysis tool used to measure momentum across three varying timeframes
//ADD:  vstop   =   'volstop(src,len,atrfactor=2)'             //Volatility Stop is a technical indicator that is used by traders to help place effective stop-losses. atrfactor=p1
//ADD:  vwap    =   'vwap(src_)',                              //Volume Weighted Average Price (VWAP) is  used to measure the average price weighted by volume     
//ADD:  cti     =   'cti(src,len)',                            //Ehler s Correlation Trend Indicator by @midtownsk8rguy.
//ADD:  stc     =   'stc(src,len,fast=23,slow=50)',            //Schaff Trend Cycle (STC) detects up and down trends long before the MACD. Code imported from @lazybear's (thanks) Schaff Trend Cycle script.
//ADD:  org     =   'Original Value',                          //Return input source value as output
//UPD:  Indicator factor inputs displays with factor descriptions 
//UPD:  Indicator Parameter inputs displays with parameter descriptions 
//UPD:  Indicator source inputs displays indicators descriptions 
//UPD:  volume added on IND2 source input
//UPD:  IND1 is added IND2's source list (IND1, open, close...). Now it is possible to use IND1 as source and modify it with any indicator in IND2. ex: IND1=ema(close,14) and IND2=dema(IND1,50) means IND2=dema(ema(close,14), 50)
//UPD:  indicators descriptions updated
//UPD:  contants and inputs (ind_src) updated with new indicators
//@version=5

indicator("Indicators w HeikinAshi and Factor [DTU]")
import dturkuler/lib_Indicators_v2_DTU/2 as dtu // library includes indicators, snippets from tradingview library and some other open sources scripts

//_______________INDICATORS CONSTANTS 
// Indicator constants are defined with descriptions to better display in inputs dropdowns
// To use them to call library function, It should be splitted with ".-" separator by using fn_split(indicator_constant,".-"). splitted first part will be used on library function part
// ex: "cma(src,len)"
ovrly      = '▼▼▼ OVERLAY ▼▼▼.-------------------------(Not used as indicator, info Only)Just used to separate input options of overlayable indicators ',
org        = 'Original Value.--------------------------Return input source value as output',
hide       = 'DONT DISPLAY.----------------------------Dont display/calculate the indicator. (For my framework usage)',
alma       = 'alma(src,len,offset=0.85,sigma=6).-------Arnaud Legoux Moving Average ',
ama        = 'ama(src,len,fast=14,slow=100).-----------Adjusted Moving Average',
acdst      = 'accdist().-------------------------------Accumulation/distribution index. ',
cma        = 'cma(src,len).----------------------------Corrective Moving average    ',
dema       = 'dema(src,len).---------------------------Double EMA  (Same as EMA with 2 factor)',
ema        = 'ema(src,len).----------------------------Exponential Moving Average ',
gmma       = 'gmma(src,len).---------------------------Geometric Mean Moving Average',
hghst      = 'highest(src,len).------------------------Highest value for a given number of bars back.   ',
hl2ma      = 'hl2ma(src,len).--------------------------higest lowest moving average',
hma        = 'hma(src,len).----------------------------Hull Moving Average.',
lgAdt      = 'lagAdapt(src,len,perclen=5,fperc=50).----Ehlers Adaptive Laguerre filter',
lgAdV      = 'lagAdaptV(src,len,perclen=5,fperc=50).---Ehlers Adaptive Laguerre filter variation',
lguer      = 'laguerre(src,len).-----------------------Ehlers Laguerre filter',
lsrcp      = 'lesrcp(src,len).-------------------------lowest exponential esrcpanding moving line',
lexp       = 'lexp(src,len).---------------------------lowest exponential expanding moving line ',
linrg      = 'linreg(src,len,loffset=1).---------------Linear regression',
lowst      = 'lowest(src,len).-------------------------Lovest value for a given number of bars back.',
mgi        = 'mcginley(src, len).-----------------------McGinley Dynamic adjusts for market speed shifts, which sets it apart from other moving averages, in addition to providing clear moving average lines',
pcnl       = 'percntl(src,len).------------------------percentile nearest rank. Calculates percentile using method of Nearest Rank.',
pcnli      = 'percntli(src,len).-----------------------percentile linear interpolation. Calculates percentile using method of linear interpolation between the two nearest ranks.',
prev       = 'previous(src,len).-----------------------Previous n (len) value of the source   ',
pvth       = 'pivothigh(src,BarsLeft=len,BarsRight=2).-Previous pivot high. src=src, BarsLeft=len, BarsRight=p1=2',
pvtl       = 'pivotlow(src,BarsLeft=len,BarsRight=2).--Previous pivot low. src=src, BarsLeft=len, BarsRight=p1=2',
rema       = 'rema(src,len).---------------------------Range EMA (REMA)   ',
rma        = 'rma(src,len).----------------------------Moving average used in RSI. It is the exponentially weighted moving average with alpha = 1 / length.',
sar        = 'sar(start=len, inc=0.02, max=0.02).------Parabolic SAR (parabolic stop and reverse) is a method to find potential reversals in the market price direction of traded goods.start=len, inc=p1, max=p2. ex: sar(0.02, 0.02, 0.02)    ',
sma        = 'sma(src,len).----------------------------Smoothed Moving Average',
smma       = 'smma(src,len).---------------------------Smoothed Moving Average',
supr2      = 'super2(src,len).-------------------------Ehlers super smoother, 2 pole ',
supr3      = 'super3(src,len).-------------------------Ehlers super smoother, 3 pole',
strnd      = 'supertrend(src,len,period=3).------------Supertrend indicator',
swma       = 'swma(src,len).---------------------------Sine-Weighted Moving Average',
tema       = 'tema(src,len).---------------------------Triple EMA  (Same as EMA with 3 factor)',
tma        = 'tma(src,len).----------------------------Triangular Moving Average',
vida       = 'vida(src,len).---------------------------Variable Index Dynamic Average   ',
vwma       = 'vwma(src,len).---------------------------Volume Weigted Moving Average',
vstop      = 'volstop(src,len,atrfactor=2).------------Volatility Stop is a technical indicator that is used by traders to help place effective stop-losses. atrfactor=p1',
wma        = 'wma(src,len).----------------------------Weigted Moving Average ',
vwap       = 'vwap(src_).------------------------------Volume Weighted Average Price (VWAP) is  used to measure the average price weighted by volume     ',
nvrly      = '▼▼▼ NON OVERLAY ▼▼.----------------------(Not used as indicator, info Only)Just used to separate input options of non overlayable indicators ',
adx        = 'adx(dilen=len, adxlen=14, adxtype=0).----adx. The Average Directional Index (ADX) is a used to determine the strength of a trend. len=>dilen, p1=adxlen (default=14), p2=adxtype 0:ADX, 1:+DI, 2:-DI (def:0)',
angle      = 'angle(src,len).--------------------------angle of the series   (Use its Input as another indicator output)',
aroon      = 'aroon(len,dir=0).------------------------aroon indicator. Aroons major function is to identify new trends as they happen.p1 = dir: 0=mid (default), 1=upper, 2=lower',
atr        = 'atr(src,len).----------------------------average true range. RMA of true range.                ',
awsom      = 'awesome(fast=len=5,slow=34,type=0).------Awesome Oscilator is an indicator used to measure market momentum. defaults : fast=len= 5, p1=slow=34, p2=type: 0=Awesome, 1=difference',
bbr        = 'bbr(src,len,mult=1).---------------------bollinger %%',
bbw        = 'bbw(src,len,mult=2).---------------------Bollinger Bands Width. The Bollinger Band Width is the difference between the upper and the lower Bollinger Bands divided by the middle band.',
cci        = 'cci(src,len).----------------------------commodity channel index',
cctbb      = 'cctbbo(src,len).-------------------------CCT Bollinger Band Oscilator',
chng       = 'change(src,len).-------------------------A.K.A. Momentum. Difference between current value and previous, source - source[length]. is most commonly referred to as a rate and measures the acceleration of the price and/or volume of a security',
cmf        = 'cmf(len=20).-----------------------------Chaikin Money Flow Indicator used to measure Money Flow Volume over a set period of time. Default use is len=20',
cmo        = 'cmo(src,len).----------------------------Chande Momentum Oscillator. Calculates the difference between the sum of recent gains and the sum of recent losses and then divides the result by the sum of all price movement over the same period.',
cog        = 'cog(src,len).----------------------------The cog (center of gravity) is an indicator based on statistics and the Fibonacci golden ratio.',
cpcrv      = 'copcurve(src,len).-----------------------Coppock Curve.  was originally developed by Edwin Sedge Coppock (Barrons Magazine, October 1962).',
corrl      = 'correl(src,len).-------------------------Correlation coefficient. Describes the degree to which two series tend to deviate from their ta.sma values.',
count      = 'count(src,len).--------------------------green avg - red avg',
cti        = 'cti(src,len).----------------------------Ehler s Correlation Trend Indicator by ',
dev        = 'dev(src,len).----------------------------ta.dev()  Measure of difference between the series and its ta.sma',
dpo        = 'dpo(len).--------------------------------Detrended Price OScilator is used to remove trend from price.   ',
efi        = 'efi(len).--------------------------------Elders Force Index (EFI) measures the power behind a price movement using price and volume.',
eom        = 'eom(len=14,div=10000).-------------------Ease of Movement.It is designed to measure the relationship between price and volume.p1 = div: 10000= (default)',
fall       = 'falling(src,len).------------------------ta.falling() Test if the `source` series is now falling for `length` bars long. (Use its Input as another indicator output)',
fit        = 'fisher(len).-----------------------------Fisher Transform is a technical indicator that converts price to Gaussian normal distribution and signals when prices move significantly by referencing recent price data',
hvo        = 'histvol(len).----------------------------Historical volatility is a statistical measure used to analyze the general dispersion of security or market index returns for a specified period of time.',
kcr        = 'kcr(src,len,mult=2).---------------------Keltner Channels Range  ',
kcw        = 'kcw(src,len,mult=2).---------------------ta.kcw(). Keltner Channels Width. The Keltner Channels Width is the difference between the upper and the lower Keltner Channels divided by the middle channel.',
kli        = 'klinger(type=len).-----------------------Klinger oscillator aims to identify money flow’s long-term trend. type=len: 0:Oscilator 1:signal',
macd       = 'macd(src,len).---------------------------MACD (Moving Average Convergence/Divergence)',
mfi        = 'mfi(src,len).----------------------------Money Flow Index s a tool used for measuring buying and selling pressure',
msi        = 'msi(len=10).-----------------------------Mass Index (def=10) is used to examine the differences between high and low stock prices over a specific period of time',
nvi        = 'nvi().-----------------------------------Negative Volume Index',
obv        = 'obv().-----------------------------------On Balance Volume',
pvi        = 'pvi().-----------------------------------Positive Volume Index ',
pvt        = 'pvt().-----------------------------------Price Volume Trend',
rangs      = 'ranges(src,upper=len, lower=-5).---------ranges of the source. src=src, upper=len, v1:lower=upper .  returns: -1 source<lower,  1 source>=upper otherwise 0',
rise       = 'rising(src,len).-------------------------ta.rising() Test if the `source` series is now rising for `length` bars long. (Use its Input as another indicator output)',
roc        = 'roc(src,len).----------------------------Rate of Change',
rsi        = 'rsi(src,len).----------------------------Relative strength Index',
rvi        = 'rvi(src,len).----------------------------The Relative Volatility Index (RVI) is calculated much like the RSI, although it uses high and low price standard deviation instead of the RSI’s method of absolute change in price.',
smosc      = 'smi_osc(src,len,fast=5, slow=34).--------smi Oscillator',
smsig      = 'smi_sig(src,len,fast=5, slow=34).--------smi Signal',
stc        = 'stc(src,len,fast=23,slow=50).------------Schaff Trend Cycle (STC) detects up and down trends long before the MACD. Code imported from ',
stdev      = 'stdev(src,len).--------------------------Standart deviation',
trix       = 'trix(src,len) .--------------------------the rate of change of a triple exponentially smoothed moving average.',
tsi        = 'tsi(src,len).----------------------------The True Strength Index indicator is a momentum oscillator designed to detect, confirm or visualize the strength of a trend.',
ulos       = 'ultimateOsc(len.-------------------------Ultimate Oscillator indicator (UO) indicator is a technical analysis tool used to measure momentum across three varying timeframes',
vari       = 'variance(src,len).-----------------------ta.variance(). Variance is the expectation of the squared deviation of a series from its mean (ta.sma), and it informally measures how far a set of numbers are spread out from their mean.',
wilpc      = 'willprc(src,len).------------------------Williams %R',
wad        = 'wad().-----------------------------------Williams Accumulation/Distribution.',
wvad       = 'wvad().----------------------------------Williams Variable Accumulation/Distribution.',

//_______________PARAMETER VERSION CONSTANTS
v01="Use Defaults", v02="Use Extra Parameters P1, P2"

//_______________FACTOR VERSION CONSTANTS
f01="None", f02 = "Double", f03 = "Triple", f04 = "Quadruple"



//--------------------------}


//--------------------------
//--------FUNCTIONS--------- 
//--------------------------{
fn_split(simple string s_data,sep_=".-")=>
    a=str.pos(s_data,sep_)
    result=str.substring(s_data,0,a)
fn_paramVer(simple string pver_)=>
    int ver_=switch pver_
        v01 =>  1
        v02 =>  2
    ver_
    
fn_factorVer(simple string fver_)=>
    int ver_=switch fver_
        f01 =>  1
        f02 =>  2
        f03 =>  3
        f04 =>  4
    ver_
//--------------------------}

//--------------------------
//--------TEST--------------
//--------------------------{
 //Indicators that returned plot function values
float f_indicator1=0
float f_indicator2=0
float ext_data =      input.source(   defval=close,          title='External Indicator') 

//Function returns source values from given input
//Ex:  ind_data =input.string(defval="close", title='',options=["close", "open", "high", "low","hl2", "hlc3", "ohlc4","IND1"]) 
fn_get_source(string source_) => 
    result  =   switch source_
        "close" =>  close 
        "open"  =>  open 
        "high"  =>  high 
        "low"   =>  low 
        "hl2"   =>  hl2 
        "hlc3"  =>  hlc3 
        "ohlc4" =>  ohlc4
        "volume"   =>  volume        
        "EXT"   =>  ext_data        
        "IND1"  =>  f_indicator1  //ex:return calculated indicator or another source entry for using in new calculation
        "IND2"  =>  f_indicator2  //ex:return calculated indicator or another source entry for using in new calculation
        =>na
    result
//--------------------------} 
 
  
//----------------------------------------------------------------------------------------------------------------------------------------
//INDICATOR 1-----------------------------------------------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------------------------------------------------------
s_grp_indicator1="════════════ INDICATOR 1 ════════════"
s_ind1_src=        input.string(   defval=ema,           title='IND1:',        options=[hide, org, ovrly, 
                                                                                     alma, ama  , acdst, cma,  dema, ema, gmma, hghst, hl2ma, hma, lgAdt, lgAdV, lguer, lsrcp, lexp, linrg, lowst, 
                                                                                     mgi,pcnl, pcnli, prev , pvth, pvtl, rema, rma, sar, sma, smma, supr2, supr3, strnd, swma, tema, tma, vida, vwma, vstop, wma, vwap, 
                                                                                     nvrly, 
                                                                                     adx, angle, aroon, atr, awsom, bbr, bbw, cci, cctbb, chng, cmf, cmo, cog, cpcrv, corrl, count, cti, dev, dpo, efi, eom, 
                                                                                     fall, fit, hvo, kcr, kcw, kli, macd, mfi, msi, nvi, obv, pvi, pvt, rangs, rise, roc, rsi, rvi, smosc, smsig, stc, stdev, trix, 
                                                                                     tsi, vari, wilpc, wad, wvad] 
                                                                          ,   group=s_grp_indicator1, inline="ind1")
s_ind1_data =      input.string(   defval="close",        title='',           options=["close", "open", "high", "low","hl2", "hlc3", "ohlc4", "volume", "EXT"]  ,  group= s_grp_indicator1, inline="ind1") 
f_ind1_len   =     input.float(    defval=14,             title='Len',        group=s_grp_indicator1, inline="ind1")
s_ind1_ver =       input.string(   defval=v01,            title="Par",        group=s_grp_indicator1, inline="ind2", options=[v01,v02])
f_ind1_p1   =      input.float(    defval=0,              title='P1',         group=s_grp_indicator1, inline="ind2")
f_ind1_p2   =      input.float(    defval=0,              title='P2',         group=s_grp_indicator1, inline="ind2")
s_ind1_fact =      input.string(   defval=f01,            title='factor',     group=s_grp_indicator1, inline="ind4", options=[f01,f02,f03,f04])
s_ind1_log =       input.string(   defval="None",         title='Log',        group=s_grp_indicator1, inline="ind4", options=['None', 'Simple', 'Log10'])
s_ind1_pType =     input.string(   defval="Original",     title="PType",      group=s_grp_indicator1, inline="ind3", options=['Original', 'Stochastic', 'PercentRank','Org. Range (-1,1)'])
i_ind1_stlen =     input.int(      defval=50,             title='St/% val',   group=s_grp_indicator1, inline="ind3")
b_ind1_pSWMA=      input.bool(     defval=false,          title="Smooth",     group=s_grp_indicator1, inline="ind3")
c_ind1_color =     input(          defval=color.green,    title="",           group=s_grp_indicator1, inline="ind3")
b_plt1_candle =    input.bool(     defval=true,           title='Plot Candle',group=s_grp_indicator1, inline="plt")
b_plt1_ind =       input.bool(     defval=true,           title='Plot Ind',   group=s_grp_indicator1, inline="plt")
b_plt1_heikin =    input.bool(     defval=false,          title='HeikinAshi', group=s_grp_indicator1, inline="plt")
//f_ind1_p3   =    input.float(    defval=0,              title='P3',         group=s_grp_indicator1, inline="ind2")  //to be activated in the future

oOut1=0.0, hOut1=0.0, lOut1=0.0, cOut1=0.0
palette1=color.green

//PLOT INDICATOR 1
if s_ind1_src!=hide and b_plt1_ind!=false 
    s_ind1_data_=fn_get_source(s_ind1_data)
    f_indicator1:=dtu.fn_factor(FuncType_=fn_split(s_ind1_src), src_data_=s_ind1_data_, length_=f_ind1_len, p1=f_ind1_p1, p2=f_ind1_p2,  version_=fn_paramVer(s_ind1_ver), fact_=fn_factorVer(s_ind1_fact), plotingType_=s_ind1_pType, stochlen_=i_ind1_stlen, plotSWMA_=b_ind1_pSWMA,  log_=s_ind1_log)

plot(s_ind1_src==hide or b_plt1_ind==false ?na:f_indicator1, color=c_ind1_color, title='indicator1', linewidth=2)

//PLOT FUNCTION CANDLES 1
if s_ind1_src!=hide and b_plt1_candle!=false 
    [oOut_, hOut_, lOut_, cOut_, palette_] = dtu.fn_plotCandles(FuncType_=fn_split(s_ind1_src),len_=f_ind1_len, p1=f_ind1_p1, p2=f_ind1_p2, version_=fn_paramVer(s_ind1_ver),fact_=fn_factorVer(s_ind1_fact), plotingType_=s_ind1_pType, stochlen_=i_ind1_stlen, plotSWMA_=b_ind1_pSWMA,  log_=s_ind1_log, plotheikin_=b_plt1_heikin )
    oOut1:=oOut_, hOut1:=hOut_, lOut1:=lOut_, cOut1:=cOut_
    palette1 := palette_ ? color.green : color.red


pc1_=s_ind1_src==hide or b_plt1_candle==false
plotcandle(pc1_?na:oOut1, pc1_?na:hOut1, pc1_?na:lOut1, pc1_?na:cOut1, color=palette1, title='Filter Candles 1')

//----------------------------------------------------------------------------------------------------------------------------------------
//INDICATOR 2-----------------------------------------------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------------------------------------------------------
s_grp_indicator2="════════════ INDICATOR 2 ════════════"
s_ind2_src=        input.string(   defval=ema,           title='IND2:',          options=[hide, org, ovrly, 
                                                                                     alma, ama  , acdst, cma,  dema, ema, gmma, hghst, hl2ma, hma, lgAdt, lgAdV, lguer, lsrcp, lexp, linrg, lowst, 
                                                                                     mgi,pcnl, pcnli, prev , pvth, pvtl, rema, rma, sar, sma, smma, supr2, supr3, strnd, swma, tema, tma, vida, vwma, vstop, wma, vwap, 
                                                                                     nvrly, 
                                                                                     adx, angle, aroon, atr, awsom, bbr, bbw, cci, cctbb, chng, cmf, cmo, cog, cpcrv, corrl, count, cti, dev, dpo, efi, eom, 
                                                                                     fall, fit, hvo, kcr, kcw, kli, macd, mfi, msi, nvi, obv, pvi, pvt, rangs, rise, roc, rsi, rvi, smosc, smsig, stc, stdev, trix, 
                                                                                     tsi, vari, wilpc, wad, wvad] 
                                                                         ,     group=s_grp_indicator2, inline="ind1")
//ind2_data =      input.source(   defval=close,           title='',           group=s_grp_indicator2, inline="ind1") 
s_ind2_data =      input.string(   defval="close",         title='',           options=["close", "open", "high", "low","hl2", "hlc3", "ohlc4", "vol", "EXT", "IND1"]  ,  group= s_grp_indicator2, inline="ind1") 
f_ind2_len   =     input.float(    defval=48,              title='Len',        group=s_grp_indicator2, inline="ind1")
s_ind2_ver =       input.string(   defval=v01,             title="Par",        group=s_grp_indicator2, inline="ind2", options=[v01,v02])
f_ind2_p1   =      input.float(    defval=0,               title='P1',         group=s_grp_indicator2, inline="ind2")
f_ind2_p2   =      input.float(    defval=0,               title='P2',         group=s_grp_indicator2, inline="ind2")
s_ind2_fact =      input.string(   defval=f01,             title='factor',     group=s_grp_indicator2, inline="ind4",  options=[f01,f02,f03,f04])
s_ind2_log =       input.string(   defval="None",          title='Log',        group=s_grp_indicator2, inline="ind4", options=['None', 'Simple', 'Log10'])
s_ind2_pType =     input.string(   defval="Original",      title="PType",      group=s_grp_indicator2, inline="ind3", options=['Original', 'Stochastic', 'PercentRank','Org. Range (-1,1)'])
i_ind2_stlen =     input.int(      defval=50,              title='St/% val',   group=s_grp_indicator2, inline="ind3")
b_ind2_pSWMA=      input.bool(     defval=false,           title="Smooth",     group=s_grp_indicator2, inline="ind3")
c_ind2_color =     input(          defval=color.red,       title="",           group=s_grp_indicator2, inline="ind3")
b_plt2_candle =    input.bool(     defval=true,            title='Plot Candle',group=s_grp_indicator2, inline="plt")
b_plt2_ind =       input.bool(     defval=true,            title='Plot Ind',   group=s_grp_indicator2, inline="plt")
b_plt2_heikin =    input.bool(     defval=false,           title='HeikinAshi', group=s_grp_indicator2, inline="plt")
//ind2_p3   =     input.float(    defval=0,               title='P3',        group=s_grp_indicator2, inline="ind2")  //to be activated in the future

oOut2=0.0, hOut2=0.0, lOut2=0.0, cOut2=0.0
palette2=color.green

//PLOT INDICATOR 2

if s_ind2_src!=hide and b_plt2_ind!=false 
    s_ind2_data_=fn_get_source(s_ind2_data)
    f_indicator2:=dtu.fn_factor(FuncType_=fn_split(s_ind2_src), src_data_=s_ind2_data_, length_=f_ind2_len, p1=f_ind2_p1, p2=f_ind2_p2, version_=fn_paramVer(s_ind2_ver), fact_=fn_factorVer(s_ind2_fact), plotingType_=s_ind2_pType, stochlen_=i_ind2_stlen, plotSWMA_=b_ind2_pSWMA,  log_=s_ind2_log)

plot(s_ind2_src==hide or b_plt2_ind==false ?na:f_indicator2, color=c_ind2_color, title='indicator2', linewidth=2)

//PLOT FUNCTION CANDLES 2
if s_ind2_src!=hide and b_plt2_candle!=false 
    [oOut_, hOut_, lOut_, cOut_, palette_] = dtu.fn_plotCandles(FuncType_=fn_split(s_ind2_src),len_=f_ind2_len, p1=f_ind2_p1, p2=f_ind2_p2, version_=fn_paramVer(s_ind2_ver),fact_=fn_factorVer(s_ind2_fact), plotingType_=s_ind2_pType, stochlen_=i_ind2_stlen, plotSWMA_=b_ind2_pSWMA,  log_=s_ind2_log, plotheikin_=b_plt2_heikin )
    oOut2:=oOut_, hOut2:=hOut_, lOut2:=lOut_, cOut2:=cOut_
    palette2 := palette_ ? color.green : color.red


pc2_=s_ind2_src==hide or b_plt2_candle==false
plotcandle(pc2_?na:oOut2, pc2_?na:hOut2, pc2_?na:lOut2, pc2_?na:cOut2, color=palette2, title='Filter Candles 2')
