input conso = .02;
input outo = .01;
input coc = close;
input linRegLength = 21;
input smLength = 3;
input displace2 = 0;
def value = Average(Inertia(coc[-displace2], linRegLength), smLength);
def error = Average(sterr(coc[-displace2], linRegLength), smLength);
def MiddleLine = value;
def total = if close < open then (high + 2 * low + close) / 2 else if close > open then (2 * high + low + close) / 2 else (high + low + 2 * close) / 2;
def UpperPr = total[1] - low[1];
def LowerPr = total[1] - high[1];
def price = close;
def length4 = 10;
def displace = 0;
def AvgExp = ExpAverage(price[-displace], length4);
def length6 = 48.5;
def AvgExp2 = ExpAverage(price[-displace], length6);
def c = close;
def length2 = 30;
def calclength2 = 5;
def smoothlength2 = 3;
input agg = AggregationPeriod.DAY;
def o10 = open(period = agg);
def c10 = close(period = agg);
def data = fold i = 0 to length2
with s
do s + (if c10 > GetValue(o10, i)
then 1
else if c10 < GetValue(o10, i)
then - 1
else 0);
def EMA5 = ExpAverage(data, calclength2);
def Main = ExpAverage(EMA5, smoothLength2);
def Signal = ExpAverage(Main, smoothLength2);
def ob3 = if IsNaN(c10) then Double.NaN else Round(length2 * .7);
input BuyEntry = 3;
input SellEntry = 3;
plot QB = Highest(high, BuyEntry);
plot QS = Lowest(low, SellEntry);
plot midline = (qs[1]+qb[1])/2;
plot differencechange = ((main-signal) < 1) and ((main - signal) > -1) and (main < ob3);
plot comboupstrongstrongstrong = (close > qb[1]) and (c[1] < qb[2]) and (((open - qb[1])/100) < outo) and (((qb[1] - Avgexp)/100) < conso) and (close < midline[1]);
plot comboupstrongstrong = (close > qb[1]) and (c[1] < qb[2]) and (((open - qb[1])/100) < outo) and (((qb[1] - Avgexp)/100) < conso) and (open[1] or open[2] or open[3] < midline) and comboupstrongstrongstrong is false and (open < qb[1]) and (open[1] > Qs[2]) and (close[1] < midline[2]);
plot comboupstrong = (close > qb[1]) and (close[1] < qb[2]) and (((open - qb[1])/100) < outo) and (((qb[1] - Avgexp)/100) < conso) and comboupstrongstrongstrong is false and comboupstrongstrong is false and (close > open) and (low < middleline) and (close > open);
plot midcrossgapup = (((open < midline) and ((close > midline)) or ((close[1] < midline[2])) and (open > midline[1]))) and (close > open) and (differencechange) and (close[1] < qb[2]) and (close > upperpr);
plot combodown = (qs[1] > qs[2]) and (close < qs[1]) and (c[1] > qs[2]) and (((qs[1] - open)/100) < outo) and (((Avgexp - qs[1])/100) < conso);
plot midcrossgapdown = (((open > midline) and ((close < midline)) or ((close[1] > midline[2])) and (open < midline[1]))) and (close < open) and (close[1] > qs[2]) and (close < lowerpr);
plot sellputs = (lowerpr < QS);