input price = close;
input stdevLength = 5;
input avgOfStdevLength = 10;
input DYMILength = 30;
input DYMILengthLowerLimit = 3;
input DYMILengthUpperLimit = 30;
assert(DYMILengthLowerLimit > 0, "'dymi length lower limit' must be positive: " + DYMILengthLowerLimit);
assert(DYMILength between DYMILengthLowerLimit and DYMILengthUpperLimit, "'dymi length' must be between lower and upper limit: " + DYMILength);
def std = stdev(price, stdevLength);
def ratio = std / Average(std, avgOfStdevLength);
def dynamicLength = Floor(DYMILength / ratio);
def limitedLength = if dynamicLength between DYMILengthLowerLimit and DYMILengthUpperLimit then dynamicLength else 0;
def sf = 2 / (limitedLength + 1);
def bn = Max(barNumber(), 0);
# 10^-5 precision for ema multiplier
def expIndex = if limitedLength == 0 then 1 else max(1, bn - ceil(-5 / lg(1 - sf)));
def fromIndex = if isNan(expIndex) then 1 else expIndex;
def chg = price - price[1];
def absChg = AbsValue(chg);
def netChgAvg = fold indexN = fromIndex to bn + 1 with accuN do sf * (if isnan(getValue(chg, bn - indexN)) then 0 else getValue(chg, bn - indexN)) + (1 - sf) * accuN;
def totChgAvg = fold indexT = fromIndex to bn + 1 with accuT do sf * (if isnan(getValue(absChg, bn - indexT)) then 0 else getValue(absChg, bn - indexT)) + (1 - sf) * accuT;
def RSI = if totChgAvg != 0 and limitedLength != 0 then 50 * (netChgAvg / totChgAvg + 1) else RSI[1];
def DYMI = RSI;
def OverBought = 90;
def OverSold = 10;
input cci_length = 7;
input cci_over_sold = -200;
input cci_over_bought = 200;
def price_cci = close + low + high;
def linDev_cci = lindev(price_cci, cci_length);
def CCI = if linDev_cci == 0 then 0 else (price_cci - Average(price_cci, cci_length)) / linDev_cci / 0.015;
Alert ((DYMI>=OverBought) and (CCI >=cci_over_bought), "OverBought", Alert.BAR, Sound.ring);
Alert ((DYMI<=OverSold) and (CCI <=cci_over_sold), "OverSold", Alert.BAR, Sound.ring);
plot DotDn = (DYMI>=OverBought) and (CCI >=cci_over_bought);
DotDn.setStyle(curve.POINTS);
DotDn.setPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
DotDn.setLineWeight(3);
DotDn.setDefaultColor(color.RED);
plot DotUp = (DYMI<=OverSold) and (CCI <=cci_over_sold);
Dotup.setStyle(curve.POINTS);
Dotup.setPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
Dotup.setLineWeight(3);
Dotup.setDefaultColor(color.GREEN);
alert(Dotup, "Scalper Buy Signal", Alert.BAR, Sound.ring);
alert(DotDn, "Scalper Sell Signal", Alert.BAR, Sound.ring);