# ToS ThinkScript Double High / Double Low Indicator by @Joshua August 28 2021
input AlertBuffer = 10;
input EnableAlerts = Yes;
def prev_high;
def prev_low;
def cur_day = GetLastDay() == GetDay();
def prev_day =
GetLastDay() - GetDay() == 1
and SecondsFromTime(0930) >= 0
and SecondsTillTime(1600) >= 0
;
if prev_day and !prev_day[1] {
prev_high = high;
prev_low = low;
} else if prev_day {
prev_high =
if high > prev_high[1]
then high
else prev_high[1]
;
prev_low =
if low < prev_low[1]
then low
else prev_low[1]
;
} else {
prev_high = prev_high[1];
prev_low = prev_low[1];
}
def prev_range = prev_high - prev_low;
def double_high = prev_high + prev_range;
def double_low = prev_low - prev_range;
def buffer_size = prev_range * (AlertBuffer * 0.01);
def double_high_buffer = if cur_day then double_high - buffer_size else Double.NaN;
def double_low_buffer = if cur_day then double_low + buffer_size else Double.NaN;
def high_buffer = if cur_day then prev_high - buffer_size else Double.NaN;
def low_buffer = if cur_day then prev_low + buffer_size else Double.NaN;
plot DoubleHigh = if cur_day then double_high else Double.NaN;
plot DoubleLow = if cur_day then double_low else Double.NaN;
plot PrevLow = if cur_day then prev_low else Double.NaN;
plot PrevHigh = if cur_day then prev_high else Double.NaN;
PrevLow.SetDefaultColor(Color.CYAN);
PrevHigh.SetDefaultColor(Color.CYAN);
DoubleHigh.SetDefaultColor(Color.CYAN);
DoubleLow.SetDefaultColor(Color.CYAN);
AddCloud(PrevHigh, PrevLow, Color.LIGHT_GREEN);
AddCloud(double_low_buffer, double_low, Color.LIGHT_ORANGE);
AddCloud(double_high, double_high_buffer, Color.LIGHT_ORANGE);
AddCloud(PrevHigh, high_buffer, Color.LIGHT_ORANGE);
AddCloud(low_buffer, PrevLow, Color.LIGHT_ORANGE);
def alert_double_high_armed = Between(close, double_high_buffer, double_high);
def alert_double_low_armed = Between(close, double_low, double_low_buffer);
def alert_high_armed = Between(close,high_buffer,high);
def alert_low_armed = Between(close,low_buffer,low);
alert(
EnableAlerts and alert_double_high_armed and !alert_double_high_armed[1],
"Near Double High",
Alert.ONCE,
Sound.Ding
);
alert(
EnableAlerts and alert_double_low_armed and !alert_double_low_armed[1],
"Near Double Low",
Alert.ONCE,
Sound.Ding
);
alert(
EnableAlerts and alert_high_armed and !alert_high_armed[1],
"Near High",
Alert.ONCE,
Sound.Ding
);
alert(
EnableAlerts and alert_low_armed and !alert_low_armed[1],
"Near Low",
Alert.ONCE,
Sound.Ding
);