#
# Moving Average Bounce
#
# Coded per request on UseThinkScript
#
# V. 2020-03-23 V1
#
# by mashume
#
input fast_length = 10;
input slow_length = 50;
input price = CLOSE;
input MovingAverage = {default "EMA", "SMA", "WMA", "HMA"};
plot fast_MA;
switch (MovingAverage) {
case SMA:
fast_MA = simpleMovingAvg(price, length = fast_length);
case WMA:
fast_MA = wma(price, length = fast_length);
case HMA:
fast_MA = HullMovingAvg(price = price, length = fast_length);
default:
fast_MA = MovAvgExponential(price, length = fast_length);
}
plot slow_MA;
switch (MovingAverage) {
case SMA:
slow_MA = simpleMovingAvg(price, length = slow_length);
case WMA:
slow_MA = wma(price, length = slow_length);
case HMA:
slow_MA = HullMovingAvg(price = price, length = slow_length);
default:
slow_MA = MovAvgExponential(price, length = slow_length);
}
def phase1 = if low < slow_MA and low[1] > slow_MA[1] then -1 else if high > slow_MA and high[1] < slow_MA[1] then 1 else double.NaN;
def phase2 = if close > fast_MA and close[1] < fast_MA[1] then 1 else if close < fast_MA and close[1] > fast_MA[1] then -1 else double.NaN;
# turn on these plots if you want to see where each of the phase conditions is true.
# Make them boolean dots or some such
# plot p1 = if phase1 == 1 then high else if phase1 == -1 then low else double.nan;
# plot p2 = if phase2 == 1 then high else if phase2 == -1 then low else double.nan;
plot buy = if (! isnan(phase1[1]) or! isnan( phase1[2]) or ! isnan( phase1[3])) and phase2 == 1 then LOW else Double.NaN;
buy.SetDefaultColor(Color.GREEN);
buy.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
plot sell = if (! isnan(phase1[1]) or! isnan( phase1[2]) or ! isnan( phase1[3])) and phase2 == -1 then HIGH else Double.NaN;
sell.SetDefaultColor(Color.RED);
sell.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);