Hello,
I'm trying to learn coding but I can't quite get this code to give me the proper alerts. The colors are working fine.
Thanks in advance.
Below is code to color bars based on the hull ma direction and code to color the chart background based on the heiken candle color.
I want the alarm ring to sound every time the hull ma direction and the heiken color background color match up. Example - Assume the hull is bullish but the heiken is bearish, then as soon as the heiken background color of light green (bullish) changes as well, the bell should sound.
Conversely, if the heiken background color is bullish and then the hull changes to bullish (violet), the bell would also sound. Same true on the inverse bearish scenarios.
The alert should only go off once when there is a match not repeat at the start of each new bar in a trend. However, the alert should not disable entirely so that it would sound once again the trend is over and a new alert condition is formed.
My Code:
input price = close;
input length = 9;
input displace = 0;
plot HMA = MovingAverage(AverageType.HULL, price, length)[-displace];
HMA.DefineColor("Up", GetColor(1));
HMA.DefineColor("Down", GetColor(0));
HMA.AssignValueColor(if HMA > HMA[1] then HMA.Color("Up") else HMA.Color("Down"));
def bullish = HMA > HMA[1];
def bearish = HMA < HMA[1];
AssignPriceColor(if bullish then Color.vIOLET else Color.RED);
def hmaAscending = HMA > HMA[1];
def hmaDescending = HMA < HMA[1];
def haClose = ohlc4;
def haOpen = (haOpen[1] + haClose[1]) / 2;
def haTrendUp = if haClose >= haOpen then 1 else 0;
def haTrendDn = if haClose < haOpen then 1 else 0;
def haSignal =
if haTrendUp == 1 and haTrendUp[1] == 1 then 1
else if haTrendDn == 1 and haTrendDn[1] == 1 then -1
else 0
;
AssignBackgroundColor(
if haSignal == 1 then Color.light_GREEN
else if haSignal == -1 then Color.PINK
else Color.WHITE
);
def bull = (haSignal == 1) and (hmaAscending and !hmaAscending[1]) or (hmaAscending) and (haSignal == 1 and !haSignal == 1[1]);
def bear = (haSignal == -1) and (hmaDescending and !hmaDescending[1]) or (haDescending) and (haSignal == -1 and !haSignal == -1[1]);
Alert (bull, text = Alert.BAR, sound = Sound.Ring);
Alert (bear, text = Alert.BAR, Sound = Sound.Ring);
I'm trying to learn coding but I can't quite get this code to give me the proper alerts. The colors are working fine.
Thanks in advance.
Below is code to color bars based on the hull ma direction and code to color the chart background based on the heiken candle color.
I want the alarm ring to sound every time the hull ma direction and the heiken color background color match up. Example - Assume the hull is bullish but the heiken is bearish, then as soon as the heiken background color of light green (bullish) changes as well, the bell should sound.
Conversely, if the heiken background color is bullish and then the hull changes to bullish (violet), the bell would also sound. Same true on the inverse bearish scenarios.
The alert should only go off once when there is a match not repeat at the start of each new bar in a trend. However, the alert should not disable entirely so that it would sound once again the trend is over and a new alert condition is formed.
My Code:
input price = close;
input length = 9;
input displace = 0;
plot HMA = MovingAverage(AverageType.HULL, price, length)[-displace];
HMA.DefineColor("Up", GetColor(1));
HMA.DefineColor("Down", GetColor(0));
HMA.AssignValueColor(if HMA > HMA[1] then HMA.Color("Up") else HMA.Color("Down"));
def bullish = HMA > HMA[1];
def bearish = HMA < HMA[1];
AssignPriceColor(if bullish then Color.vIOLET else Color.RED);
def hmaAscending = HMA > HMA[1];
def hmaDescending = HMA < HMA[1];
def haClose = ohlc4;
def haOpen = (haOpen[1] + haClose[1]) / 2;
def haTrendUp = if haClose >= haOpen then 1 else 0;
def haTrendDn = if haClose < haOpen then 1 else 0;
def haSignal =
if haTrendUp == 1 and haTrendUp[1] == 1 then 1
else if haTrendDn == 1 and haTrendDn[1] == 1 then -1
else 0
;
AssignBackgroundColor(
if haSignal == 1 then Color.light_GREEN
else if haSignal == -1 then Color.PINK
else Color.WHITE
);
def bull = (haSignal == 1) and (hmaAscending and !hmaAscending[1]) or (hmaAscending) and (haSignal == 1 and !haSignal == 1[1]);
def bear = (haSignal == -1) and (hmaDescending and !hmaDescending[1]) or (haDescending) and (haSignal == -1 and !haSignal == -1[1]);
Alert (bull, text = Alert.BAR, sound = Sound.Ring);
Alert (bear, text = Alert.BAR, Sound = Sound.Ring);