I hope this will help to get you started.
It draws 2 lines on a chart and draws purple shading between them when close is between them.
It does have an alert function, but i can't verify it works after hours.
I used a chart setting of 2Y 1D, and used these stocks for testing. their last bar is between the lines.
SBUX , EMR , PM
you can define the data to be generated from a different time frame than what is on the chart. this is called 2nd aggregation. you can have a chart of hour bars and do calculations on data from a larger time, a 2nd aggregation.
you can define only one 2nd agg time in a formula, so create a formula for each data that will use 2nd agg. then combine those variables in another formula.
this uses 2nd agg for both emas, by defining the 2nd agg time as a parameter of the price function, close.
this study can be used on a chart of 1 minute up to a day chart, assuming there is 150 weeks of data to be found.
Ruby:
# close < daily ema150 AND close > weekly ema150
#----------------------------
input aggd = AggregationPeriod.DAY;
input lengthday = 150;
def ExpAvgday = ExpAverage( close( period = aggd), lengthday );
input aggw = AggregationPeriod.week;
input lengthweek = 150;
def ExpAvgweek = ExpAverage( close( period = aggw), lengthweek );
#----------------------------
# true when close is between both lines
def both_cond = (close < ExpAvgday) and (close > ExpAvgweek);
#----------------------------
# display a label when both conditions are true
addlabel(both_cond, "close < daily ema150 AND close > weekly ema150", color.yellow);
# draw a cloud between the 2 emas when condition is true.
addcloud( (if both_cond then ExpAvgday else double.nan), ExpAvgweek, color.magenta, color.magenta);
input show_ema_lines = yes;
plot zd = if show_ema_lines then ExpAvgday else double.nan;
zd.setdefaultcolor(color.cyan);
plot zw = if show_ema_lines then ExpAvgweek else double.nan;
zw.setdefaultcolor(color.yellow);
Alert(both_cond, "between levels", alert.once, Sound.ding);
#
study , output is line(s) , from numbers.
https://tlc.thinkorswim.com/center/reference/Tech-Indicators/studies-library/M-N/MovAvgExponential
function , output is 1 number
can specify what type of average
https://tlc.thinkorswim.com/center/reference/thinkScript/Functions/Tech-Analysis/MovingAverage
function
just exponential average
https://tlc.thinkorswim.com/center/reference/thinkScript/Functions/Tech-Analysis/ExpAverage
https://tlc.thinkorswim.com/center/reference/thinkScript/Functions
https://tlc.thinkorswim.com/center/reference/thinkScript/Functions/Fundamentals
https://tlc.thinkorswim.com/center/...tants/AggregationPeriod/AggregationPeriod-DAY
alert info
https://readtheprospectus.wordpress...ng-alerts-using-thinkscript-in-think-or-swim/