input extremeuptrend =no;
input conso = .02;
input outo = .01;
input coc = close;
input linRegLength = 21;
input smLength = 3;
input displace2 = 0;
input Num_Dev_Dn = -2.0;
input Num_Dev_Up = 2.0;
def value = Average(Inertia(coc[-displace2], linRegLength), smLength);
def error = Average(sterr(coc[-displace2], linRegLength), smLength);
def MiddleLine = value;
def LowerBand = value + Num_Dev_Dn * error;
def UpperBand = value + Num_Dev_Up * error;
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 ROClength = 10;
def lengthm = 10;
assert(ROCLength > 0, "'roc length' must be positive: " + ROCLength);
def diff = high - low;
def avg = Average(diff, lengthm);
def CV = if avg[roclength] == 0 then 100 else (avg - avg[roclength]) / avg[roclength] * 100;
def negLine = -25;
# End Code RSI_Laguerre Self Adjusting with Fractal Energy
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 zeroline = 0;
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 zero = if IsNaN(c) then Double.NaN else 0;
def ob = if IsNaN(c) then Double.NaN else Round(length2 * .7);
def ob2 = if IsNaN(c) then Double.NaN else Round(length2* .3);
def ob3 = if IsNaN(c10) then Double.NaN else Round(length2 * .7);
def os = if IsNaN(c) then Double.NaN else -Round(length2 * .2);
input BuyorSell = {default Buy, Sell};
input ShowTodayOnly = yes;
input ShowEntryExitBands = yes;
input ShowBubbles = yes;
input BuyEntry = 3;
input SellEntry = 3;
input BuyExit = 20;
input SellExit = 20;
input ATRLength = 50;
input TargetATRMult = 1;
input DisplayLines = yes;
input PriceDigit = 2;
def today = !ShowTodayOnly or GetDay() == GetLastDay() and SecondsFromTime(0930) >= 0;
# High
def H1 = Highest(high, SellExit);
def H2 = fold i3 = 1 to SellExit
with ip = 0.0
do if GetValue(high, i3) == H1 or GetValue(high, i3) < ip
then ip
else GetValue(high, i3);
def H3 = fold i1 = 1 to SellExit
with ip1 = 0.0
do if GetValue(high, i1) == H1 or GetValue(high, i1) == H2 or GetValue(high, i1) < ip1
then ip1
else GetValue(high, i1);
def HH = (H2 + H3) / 2.0;
# Low
def L1 = Lowest(low, BuyExit);
def L2 = fold i4 = 1 to BuyExit
with ip2 = 10000000.0
do if GetValue(low, i4) == L1 or GetValue(low, i4) > ip2
then ip2
else GetValue(low, i4);
def L3 = Lowest(if low == L1 or low == L2 then 1000000 else low, BuyExit);
def LL = (L2 + L2) / 2.0;
def QB = Highest(high, BuyEntry);
def QS = Lowest(low, SellEntry);
plot b = QS[1];
plot x = QB[1];
def y = LL[1];
def nottolate = ((main[7] - main) < 15);
plot midline = (qs[1]+qb[1])/2;
def ATRVal = ATR(length = ATRLength, averageType = AverageType.SIMPLE);
def mATR = Highest(ATRVal, ATRLength);
def badhammer = (((high-close) < ((close + open)/2) - low)) and (open > qb[1]);
plot differencechange = ((main-signal) < 1) and ((main - signal) > -1) and (main < ob3);
plot comboupstrongstrongstrong = (high > qb[1]) and (c[1] < qb[2]) and (((high - qb[1])/100) < outo) and (((qb[1] - Avgexp)/100) < conso) and (low < midline[1]);
plot comboupstrongstrong = (high > 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 = (high > 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 (high > open) and (low < middleline) and (high > open);
plot midcrossgapup = (((open < midline) and ((high > midline)) or ((close[1] < midline[2])) and (high > midline[1]))) and (high > open) and (differencechange) and (close[1] < qb[2]) and (high > upperpr);
plot combodown = (qs[1] > qs[2]) and (low < qs[1]) and (c[1] > qs[2]) and (((qs[1] - open)/100) < outo) and (((Avgexp - qs[1])/100) < conso);
plot midcrossgapdown = (((open > midline) and ((low < midline)) or ((low[1] > midline[2])) and (open < midline[1]))) and (low < open) and (close[1] > qs[2]) and (low < lowerpr);
plot sellputs = (lowerpr < QS);