becker908
New member
I am an options day trader and one of the key indicators I use is a 9ema cross of 50ma on a five minute chart. I have ThinkScript that builds a cloud between the moving averages and sends an alert and draws a vertical line on the chart when the cross happens. I want the chart to flash - change background color - when the alert fires because I have a large screen with a dozen imbedded charts and I'd like to have a visual alert as well as the audible ring. The ThinkScript works like a charm except the AssignBackgroundColor command doesn't work on the upward cross. As I understand AssignBackgroundColor (and it works on the downward cross) it should fire and hold the new color for one bar cycle (five minutes in this case). Here's the code...
The highlighted two lines of script are the commands in question. I've also substituted "Crosses(fastAvg[1], slowAvg[1], CrossingDirection[**],"*",Alert.BAR, Sound.Ring)" for the "isCall" and "isPut" and that doesn't work either.
Thank you in advance for any help on this, it's driving me crazy.
#----- EMA/SMA CROSSOVERS MAX ONLY
#-----MRB 210530
# Purpose: Display Cloud for fast moving average (9 periods) vs slow moving average (50 periods) and provide alerts for moving average crosses. Alert with vertical lines, audible alerts, and screen flash one bar after fast MA crosses slow MA on 5min chart.
#----- Define Variables
def price = close;
def fastL = 9;
def slowL = 50;
plot fastAvg = MovingAverage(AverageType.EXPONENTIAL, close, fastL);
plot slowAvg = MovingAverage(AverageType.SIMPLE, close, slowL);
def isCall = Crosses(fastAvg[1], slowAvg[1], CrossingDirection.ABOVE); #<---9MA crosses 50MA forming GreenCloud, Call buy signal
def isPut = Crosses(fastAvg[1], slowAvg[1], CrossingDirection.BELOW); #<---9MA crosses 50MA forming RedCloud, Put buy signal
#----- Define Look&Feel for moving averages
slowAvg.SetPaintingStrategy(PaintingStrategy.LINE); #<---Define L/F for M50
slowAvg.SetLineWeight(4);
fastAvg.SetLineWeight(2);
slowAvg.DefineColor("Up", Color.LIME); #<---Trend UP = Green, trend DOWN = RED, trend FLAT = WHITE
slowAvg.DefineColor("Down", Color.RED);
slowAvg.DefineColor("Flat", Color.WHITE);
slowAvg.AssignValueColor(if slowAvg[1] > slowAvg[3] * 1.00008 then slowAvg.Color("Up") else if slowAvg[1] <
(slowAvg[3] * 0.99992) then slowAvg.Color("Down") else slowAvg.Color("Flat")); #<---Define color values for slow average based on trend
fastAvg.AssignValueColor(Color.CYAN); #Define look for fast average
AddCloud(fastAvg, slowAvg, Color.LIGHT_GREEN, Color.LIGHT_RED); #<---Define cloud
fastAvg.HideBubble();
slowAvg.HideBubble();
#----- Vertical Lines for MAX CALL / PUT Alerts display Alerts
AddVerticalLine(isCall, "", Color.GREEN, Curve.LONG_DASH); #<---Alerts for Call Buy
Alert(Crosses(fastAvg[1], slowAvg[1], CrossingDirection.ABOVE), "MAX CALL", Alert.BAR, Sound.Ring);
AssignBackgroundColor(if isCall then Color.LIGHT_GREEN else Color.BLACK); <--- THIS DOES NOT WORK
AddVerticalLine(isPut, "", Color.RED, Curve.LONG_DASH); #<---Alerts for Put Buy
Alert(Crosses(fastAvg[1], slowAvg[1], CrossingDirection.BELOW), "MAX PUT", Alert.BAR, Sound.Ring);
AssignBackgroundColor(if isPut then Color.LIGHT_RED else Color.BLACK); <--- THIS DOES WORK
#----- END CODE
The highlighted two lines of script are the commands in question. I've also substituted "Crosses(fastAvg[1], slowAvg[1], CrossingDirection[**],"*",Alert.BAR, Sound.Ring)" for the "isCall" and "isPut" and that doesn't work either.
Thank you in advance for any help on this, it's driving me crazy.
Last edited: