declare upper;
input BBlength = 20;
input BBNum_Dev = 2.0;
def price = close(PriceType = "BID");
input count = 4;
plot ma5 = ExpAverage(price, 5);
def ma9 = ExpAverage(price, 9);
plot pcUpper = PriceChannel(0, 20).UpperBand;
plot pcLower = PriceChannel(0, 20).LowerBand;
plot BB_Upper = reference BollingerBands(price = price, length = BBlength, Num_Dev_Dn = -BBNum_Dev, Num_Dev_Up = BBNum_Dev, averageType = AverageType.EXPONENTIAL).UpperBand;
plot BB_Lower = reference BollingerBands(price = price, length = BBlength, Num_Dev_Dn = -BBNum_Dev, Num_Dev_Up = BBNum_Dev, averageType = AverageType.EXPONENTIAL).Lowerband;
plot BB_Midline = reference BollingerBands(price = price, length = BBlength, Num_Dev_Dn = -BBNum_Dev, Num_Dev_Up = BBNum_Dev, averageType = AverageType.EXPONENTIAL).MidLine;
def countup = If (price < BB_Lower, countup[1] + 1, 0);
plot cline = countup == count;
def countdn = If (price > BB_Upper, countdn[1] + 1, 0);
plot cdline = countdn == count;
cline.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
cdline.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
Alert(cline or cdline, "Signal", Alert.ONCE, Sound.Ding);
#===================================================
plot condDn_pcma = open < ma9 && price > BB_Upper && price > pcUpper;
plot condUp_pcma = open > ma9 && price < BB_Lower && price < pcLower;
condUp_pcma.SetPaintingStrategy(PaintingStrategy.BOOLEAN_POINTS);
condDn_pcma.SetPaintingStrategy(PaintingStrategy.BOOLEAN_POINTS);
condDn_pcma.SetLineWeight(5);
condUp_pcma.SetLineWeight(5);
#/////////////////////////////////////////////////////////
plot condDn2 = condDn_pcma[1] && price > BB_Upper && price > pcUpper;
plot condUp2 = condUp_pcma[1] && price < BB_Lower && price < pcLower;
condUp2.SetPaintingStrategy(PaintingStrategy.BOOLEAN_POINTS);
condDn2.SetPaintingStrategy(PaintingStrategy.BOOLEAN_POINTS);
condDn2.SetLineWeight(5);
condUp2.SetLineWeight(5);
Alert(condDn2 or condUp2 , "Signal", Alert.ONCE, Sound.Ding);
4 вешайте на график и тестируйте, лично я не особо пробовал, может у кого что и выйдет.