declare lower;
input AlongLength = 5;
input AshortLength = 3;
input BlongLength = 13;
input BshortLength = 8;
input ClongLength = 21;
input CshortLength =18;
input averageType = AverageType.EXPONENTIAL;
input Arrows = 0;
input Dotsize = 3;
Input APC =0;
def TSIFast = TrueStrengthIndex(averagetype,Alonglength,Ashortlength).Signal;
def TSIAvg = TrueStrengthIndex(averagetype,Blonglength,Bshortlength).Signal;
def TSISlow = TrueStrengthIndex(averagetype,Clonglength,Cshortlength).Signal;
Plot TSICombo = (TSIFast +2*TSIAvg + 3*TSISlow)/6;
Def Con1 = TSICombo>= 0;
Def Con2 = TSICombo < 0;
Def Con3 = TSICombo > TSICombo[1];
Def Con4 = TSICombo < TSICombo[1];
Def BullRise = If Con1 and Con3 then 1 else 0;
Def BullFall = if Con1 and Con4 then 1 else 0;
Def BearFall = if Con2 and Con4 then 1 else 0;
Def BearRise = if Con2 and Con3 then 1 else 0;
TSICombo.assignValueColor(If TSICombo >= TSICombo[1] then Color.Green else Color.Red);
TSICombo.setLineWeight(3);
AddCloud(TSICombo,0,Color.Green,Color.Red);
plot Hist = TSICombo;
Hist.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Hist.AssignValueColor(if BULLRISE ==1 then Color.GREEN else if BULLFALL ==1 then Color.Dark_GREEN else if BearRISE ==1 then Color.red else if Bearfall ==1 then Color.Dark_Red else Color.Gray);
Plot UZ = Average(TSICombo,34) + (1.3185*StDev(TSICombo,34));
UZ.SetPaintingStrategy(PaintingStrategy.Line);
UZ.SetLineWeight(2);
UZ.SetDefaultColor(Color.Yellow);
Plot LZ = Average(TSICombo,34) - (1.3185*StDev(TSICombo,34));
LZ.SetPaintingStrategy(PaintingStrategy.Line);
LZ.SetLineWeight(2);
LZ.SetDefaultColor(Color.Yellow);
#ARROWS
plot ArrowDown = if arrows and (TSICombo Crosses below TSICombo[1]) then TSICombo[1] else double.nan;
ArrowDown.setpaintingStrategy(paintingStrategy.Arrow_Down);
ArrowDown.setDefaultColor(color.Magenta);
ArrowDown.setLineWeight(dotsize);
plot ArrowUp = if arrows and (TSICombo crosses above TSICombo[1]) then TSICombo[1] else double.nan;
ArrowUp.setpaintingStrategy(paintingStrategy.Arrow_Up);
ArrowUp.setDefaultColor(color.Cyan);
ArrowUp.setLineWeight(dotsize);
plot ArrowDown2 = if arrows and (TSICombo Crosses below 0) then 0 else double.nan;
ArrowDown2.setpaintingStrategy(paintingStrategy.Arrow_Down);
ArrowDown2.setDefaultColor(color.Red);
ArrowDown2.setLineWeight(dotsize);
plot ArrowUp2 = if arrows and (TSICombo crosses above 0 ) then 0 else double.nan;
ArrowUp2.setpaintingStrategy(paintingStrategy.Arrow_Up);
ArrowUp2.setDefaultColor(color.Blue);
ArrowUp2.setLineWeight(dotsize);
plot ArrowDown3 = if arrows and (TSICombo Crosses below UZ) then UZ else double.nan;
ArrowDown3.setpaintingStrategy(paintingStrategy.Arrow_Down);
ArrowDown3.setDefaultColor(color.Yellow);
ArrowDown3.setLineWeight(dotsize);
plot ArrowUp3 = if arrows and (TSICombo crosses above LZ ) then LZ else double.nan;
ArrowUp3.setpaintingStrategy(paintingStrategy.Arrow_Up);
ArrowUp3.setDefaultColor(color.Yellow);
ArrowUp3.setLineWeight(dotsize);
AssignPriceColor( if APC ==1 and TSICombo>= TSICombo[1] then Color.Cyan else if APC == 1 and TSICombo < TSICombo[1] then Color.Magenta else If APC ==2 and TSICombo >=0 then Color.Green else If APC ==2 and TSICombo <0 then Color.Red else Color.Current);