#percentB_Exit
declare lower;
input averageType = AverageType.SIMPLE;
input price = close;
input displace = 0;
input length = 20;
input Num_Dev_Dn = -2.0;
input Num_Dev_up = 2.0;
input Num_Dev_Dn_half = -1.0;
input Num_Dev_up_half = 1.0;
input Hulllength = 9;
def HMA = MovingAverage(AverageType.HULL, price, Hulllength)[-displace];
#HMA.DefineColor("Up", GetColor(1));
#HMA.DefineColor("Down", GetColor(0));
#HMA.AssignValueColor(if HMA > HMA[1] then HMA.color("Up") else HMA.color("Down"));
def upperBand = BollingerBands(price, displace, length, Num_Dev_Dn, Num_Dev_up, averageType).UpperBand;
def lowerBand = BollingerBands(price, displace, length, Num_Dev_Dn, Num_Dev_up, averageType).LowerBand;
def upperBandhalf = BollingerBands(price, displace, length, Num_Dev_Dn_half, Num_Dev_up, averageType).UpperBand;
def lowerBandhalf = BollingerBands(price, displace, length, Num_Dev_Dn_half, Num_Dev_up, averageType).LowerBand;
def PercentB = (price - lowerBand) / (upperBand - lowerBand) * 100;
plot PercentB_half = (price - lowerBandhalf) / (upperBandhalf - lowerBandhalf) * 100;
plot ZeroLine = 0;
plot HalfLine = 50;
plot UnitLine = 100;
plot twenty5 = 25;
plot seventy5 = 75;
#PercentB.SetDefaultColor(GetColor(1));
#PercentB.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
#PercentB.SetLineWeight(1);
#ZeroLine.SetDefaultColor(GetColor(8));
#HalfLine.SetDefaultColor(GetColor(8));
#UnitLine.SetDefaultColor(GetColor(8));
plot reboundUp = (PercentB[1] <= ZeroLine) and (PercentB > ZeroLine) or (PercentB[1] <= HalfLine) and (PercentB > HalfLine) or (PercentB[1] <= twenty5) and (PercentB > twenty5) and (Price[1] <= HMA[1]) and (PercentB[1] <= HMA[1]);
#(PercentB[1] <= UnitLine) and (PercentB > UnitLine) or (PercentB[1] <= seventy) and (PercentB > seventy)
reboundUp.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
reboundUp.SetLineWeight(1);
reboundUp.SetDefaultColor(Color.GREEN);
plot reboundDown = (PercentB[1] >= HalfLine) and (PercentB < HalfLine) or (PercentB[1] >= UnitLine) and (PercentB < UnitLine) or (PercentB[1] >= seventy5) and (PercentB < seventy5) and (Price[1] >= HMA[1]) and (PercentB[1] >= HMA[1]);
#(PercentB[1] >= twenty5) and (PercentB < twenty5) or (PercentB[1] >= ZeroLine) and (PercentB < ZeroLine) or
reboundDown.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);