declare lower ;
input showentry = yes;
input square = yes;
input showdboom = yes;
input showlongs = yes;
input showshorts = yes;
input LPPeriod = 6;
input K1 = 0;
def K2 = 0.3;
def esize = 60;
def ey = 50;
input trigno = 2;
input LPPeriod2 = 27;
input K12 = 0.8;
input K22 = 0.3;
def esize3 = 60;
def ey3 = 50;
input LPPeriod3 = 11;
input K13 = 0.9999;
def K33 = K13 * -1;
def esize2 = 60;
def ey2 = 50;
input n1 = 9;
input n2 = 6;
input n3 = 3;
input n4 = 21;
input n5 = 0;
def smalen = 2;
input lsmaline = 200;
def alpha1 = (Cos(.707 * 2 * Double.Pi / 100) + Sin(.707 * 2 * Double.Pi / 100) - 1) / Cos(.707 * 2 * Double.Pi / 100);
def HP = (1 - alpha1 / 2) * (1 - alpha1 / 2) * (close - 2 * close[1] + close[2]) + 2 * (1 - alpha1) * HP[1] - (1 - alpha1) * (1 - alpha1) * HP[2];
def a1 = Exp(-1.414 * Double.Pi / LPPeriod);
def b1 = 2 * a1 * Cos(1.414 * Double.Pi / LPPeriod);
def c2 = b1;
def c3 = -a1 * a1;
def c1 = 1 - c2 - c3;
def Filt = c1 * (HP + HP[1]) / 2 + c2 * Filt[1] + c3 * Filt[2];
def Peak = if AbsValue(Filt) > Peak[1] then AbsValue(Filt) else .991 * Peak[1];
def X = if Peak != 0 then Filt / Peak else X[1];
def Quotient1 = (X + K1) / (K1 * X + 1);
def Quotient2 = (X + K2) / (K2 * X + 1);
def alpha1222 = (Cos(.707 * 2 * Double.Pi / 100 ) + Sin( .707 * 2 * Double.Pi / 100 ) - 1 ) / Cos( .707 * 2 * Double.Pi / 100 );
def HP2 = ( 1 - alpha1222 / 2 ) * ( 1 - alpha1222 / 2 ) * ( close - 2 * close[1] + close[2] ) + 2 * ( 1 - alpha1222 ) * HP2[1] - ( 1 - alpha1222 ) * ( 1 - alpha1222 ) * HP2[2];
def a12 = Exp(-1.414 * Double.Pi / LPPeriod2);
def b12 = 2 * a12 * Cos( 1.414 * Double.Pi / LPPeriod2 );
def c22 = b12;
def c32 = -a12 * a12;
def c12 = 1 - c22 - c32;
def Filt2 = c12 * ( HP2 + HP2[1] ) / 2 + c22 * Filt2[1] + c32 * Filt2[2];
def Peak2 = if AbsValue(Filt2) > Peak2[1] then AbsValue(Filt2) else .991 * Peak2[1];
def X2 = if Peak2 != 0 then Filt2 / Peak2 else X2[1];
def Quotient3 = (X2 + K12) / (K12 * X2 + 1);
def Quotient4 = (X2 + K22) / (K22 * X2 + 1);
def alpha1333 = ( Cos( .707 * 2 * Double.Pi / 100 ) + Sin( .707 * 2 * Double.Pi / 100 ) - 1 ) / Cos( .707 * 2 * Double.Pi / 100 );
def HP3 = ( 1 - alpha1333 / 3 ) * ( 1 - alpha1333 / 2 ) * ( close - 2 * close[1] + close[2] ) + 2 * ( 1 - alpha1333 ) * HP3[1] - ( 1 - alpha1333 ) * ( 1 - alpha1333 ) * HP3[2];
def a13 = Exp( -1.414 * Double.Pi / LPPeriod3 );
def b13 = 2 * a13 * Cos( 1.414 * Double.Pi / LPPeriod3 );
def c33 = b13;
def c333 = -a13 * a13;
def c13 = 1 - c33 - c333;
def Filt3 = c13 * ( HP3 + HP3[1] ) / 2 + c33 * Filt3[1] + c333 * Filt3[2];
def Peak3 = if AbsValue(Filt3) > Peak3[1] then AbsValue(Filt3) else .991 * Peak3[1];
def X3 = if Peak3 != 0 then Filt3 / Peak3 else X3[1];
def Quotient5 = (X3 + K13) / (K13 * X3 + 1);
def Quotient6 = (X3 + K33) / (K33 * X3 + 1);
def line1 = -0.9;
def src0 = open;
def src1 = high;
def src2 = low;
def src3 = close;
def src4 = hl2;
def src5 = hlc3;
def src6 = ohlc4;
def src7 = TrueRange(high, close, low);
def vol = volume;
script tci {
input src = 0;
input n1 = 9;
input n2 = 6;
plot return = ExpAverage((src - ExpAverage(src, n1)) / (0.025 * ExpAverage(AbsValue(src - ExpAverage(src, n1)), n1)), n2) + 50;
}
script tradition {
input src = 0;
input n3 = 3;
plot return = (tci(src)+rsi(length = n3,price = src))/2;
}
def wt1 = tradition(src5);
def wt2 = SimpleMovingAvg(wt1,6);
def wt3 = linearRegCurve(n5,n4,wt1);
def wt4 = ExpAverage((wt1-wt2)*2+50,n3);
def trig = SimpleMovingAvg(wt3,smalen);
plot q3 = quotient3*esize+ey;
plot q4 = quotient4*esize+ey;
q3.SetDefaultColor(color.dark_red);
q4.SetDefaultColor(color.dark_red);
addcloud(q3,q4,color.dark_red,color.dark_red);
def q1 = Quotient1 * esize + ey;
def q2 = Quotient2 * esize + ey;
def trigger = simpleMovingAvg(q1, trigno);
def ext1 = if wt2 < 20 then trigger+9 else if wt2 > 80 then trigger-9 else Double.Nan;
def lsma = linearRegCurve(0,lsmaline,wt3);
plot q5 = Quotient5 * esize2 + ey2;
plot q6 = Quotient6 * esize2 + ey2;
def sma200 = simpleMovingAvg(close, 200);
def entry = quotient2 crosses below line1;
def exit = quotient1 crosses quotient2 and close > sma200 and quotient1 > 0.5;
def over = quotient5 crosses quotient6 and quotient5 > 0.5;
def over2 = quotient5 crosses above quotient6 and quotient5 >.5;
def over3 = quotient3 crosses quotient4 and quotient3 >0;
def enter = q1 crosses above trigger and q1 < lsma;
plot exitw = if showentry then if over or over3 then 0 else double.nan else double.nan;
exitw.SetPaintingStrategy(PaintingStrategy.POINTS);
exitw.AssignValueColor(if over then color.orange else color.red);
plot plot1 = q1;
plot plot3 = trigger;
plot plote = ext1;
plot1.setdefaultColor(color.cyan);
plot3.setDefaultColor(color.white);
plote.assignValueColor(if wt2<20 then color.green else if wt2>80 then color.red else color.current);
plote.setPaintingStrategy(PaintingStrategy.POINTS);
def warn = quotient3 crosses above -0.9;
def warn2 = quotient1 crosses above -0.9;
def warn3 = quotient1 crosses below 0.9;
def barx = barnumber();
def bar2 = if warn2 then barx else bar2[1];
def bar3 = if warn3 then barx else bar3[1];
def bare3 = if q1 crosses above 20 then barx else bare3[1];
def bare5 = if q1<=0 and q1 crosses below trigger then barx else bare5[1];
def bare6 = if q1<=20 and q1 crosses below trigger then barx else bare6[1];
def barse3 = if q1 crosses above 80 then barx else barse3[1];
def enter3 = quotient3 <= -0.9 and q1 crosses above trigger and barx-bar2 <=7 and q1 <=20 and barx-bare3 <=21;
def enter5 = barx-bare5 <= 5 and q1 crosses above trigger;
def enter6 = barx-bare6 <=11 and q1 crosses above trigger;
def enter7 = quotient3 <=-0.9 and q1 crosses above trigger;
def senter3 = quotient3 >= -0.9 and q1 crosses below trigger and barx-bar3 <=7 and q1 >=99 and barx-barse3<=21;
plot longgray = if showlongs and enter6 and q1 <= 60 then 100 else double.nan;
plot longyellow = if showlongs and enter7 then 100 else double.nan;
plot longblue = if showlongs and enter5 then 100 else double.nan;
plot longlime = if showlongs and enter3 then 100 else double.nan;
plot short = if showshorts and senter3 then 100 else double.nan;
longgray.setPaintingStrategy(paintingStrategy.ARROW_UP);
longyellow.setPaintingStrategy(paintingStrategy.ARROW_UP);
longblue.setPaintingStrategy(paintingStrategy.ARROW_UP);
longlime.setPaintingStrategy(paintingStrategy.ARROW_UP);
short.setPaintingStrategy(paintingStrategy.ARROW_DOWN);
longgray.setDefaultColor(color.light_gray);
longyellow.setDefaultColor(color.yellow);
longblue.setDefaultColor(color.blue);
longlime.setDefaultColor(color.lime);
short.setDefaultColor(color.red);
addchartbubble(over3,0,"Overbought");