Hi,
I'm trying to come up with an indicator that will change the background color when a moving average crosses another, then changing back to default once the cross is made. For example @10:05, 5min 20SMA crosses above 50SMA, and the background turns green. Then @10:10, the background goes back to the default color. This is what I have so far, can't figure out how to do the second part of the indicator, where the color goes back to default. Please help!! Thank you.
input aggregationPeriod = AggregationPeriod.DAY;
input FirstMA = 20;
input SecondMA = 50;
input averageType = AverageType.SIMPLE;
def c = close(period = aggregationPeriod);
def ma1 = MovingAverage(averageType, c, FirstMA);
def ma2 = MovingAverage(averageType, c, SecondMA);
def Up = ma1 > ma2;
def Down = ma1 < ma2;
AssignBackgroundColor(if Up then (color.green) else if Down then (color.red) else Color.CURRENT);
DefineGlobalColor("Up", Color.LIME);
DefineGlobalColor("Down", Color.DARK_RED);
DefineGlobalColor("default", Color.CURRENT);
I'm trying to come up with an indicator that will change the background color when a moving average crosses another, then changing back to default once the cross is made. For example @10:05, 5min 20SMA crosses above 50SMA, and the background turns green. Then @10:10, the background goes back to the default color. This is what I have so far, can't figure out how to do the second part of the indicator, where the color goes back to default. Please help!! Thank you.
input aggregationPeriod = AggregationPeriod.DAY;
input FirstMA = 20;
input SecondMA = 50;
input averageType = AverageType.SIMPLE;
def c = close(period = aggregationPeriod);
def ma1 = MovingAverage(averageType, c, FirstMA);
def ma2 = MovingAverage(averageType, c, SecondMA);
def Up = ma1 > ma2;
def Down = ma1 < ma2;
AssignBackgroundColor(if Up then (color.green) else if Down then (color.red) else Color.CURRENT);
DefineGlobalColor("Up", Color.LIME);
DefineGlobalColor("Down", Color.DARK_RED);
DefineGlobalColor("default", Color.CURRENT);