def ba = 100;
def smap2 =10;
def smapbar = 2000;
def smap3 =2;
def smap4 = 3;
input price = close;
input displace = 0;
input LinRegLength = 50;
input data_type = FundamentalType.CLOSE;
input length = 10;
input period = AggregationPeriod.DAY;
input use_chart_ap = NO;
input multiplier = 100;
input rounding = 2;
input no_nans = YES;
def hlc3 =(high+low+close)/3;
def ap_choice = if use_chart_ap then GetAggregationPeriod() else period;
def ap = If( ap_choice < AggregationPeriod.DAY && FundamentalType.IMP_VOLATILITY == data_type, AggregationPeriod.DAY, ap_choice );
def LinReg = Inertia(price[-displace], LinRegLength);
def cla= if no_nans && (IsNaN(Fundamental(data_type, period=hlc3)) or IsNaN(Fundamental(data_type, period=hlc3)[ba]))
then cla[1]
else Round(multiplier * (Fundamental(data_type, period=hlc3) / Fundamental(data_type, period=hlc3)[ba] - 1), rounding);
def LinReg1 = Inertia(cla[-displace], LinRegLength);
def b =average(linReg1, smap2);
def emaofbar = ExpAverage(hlc3 , ba);
def p1 = emaofbar[1] * ( (b*smap3/100)+1 );
def p2 = emaofbar[1] * (1-(b*smap3/100) );
def p = emaofbar[1];
def p4 = emaofbar[1] * ( (b*smap4/100)+1 );
def p5 = emaofbar[1] * (1-(b*smap4/100) );
plot x= p1;
plot x2 = p4;
plot y= emaofbar[1];
plot x3 = p2;
plot x5 = p5;
addcloud (x, x2);
addcloud (x3, x5);