Here is the code to generate alerts and plot arrows on the chart when Heikin-Ashi changes color.
def haClose = ohlc4;
def haOpen = if haOpen[1] == 0 then haClose[1] else (haOpen[1] + haClose[1]) / 2;
def haHigh = Max(high, Max(haClose, haOpen));
def haLow = Min(low, Min(haClose, haOpen));
def haColor = haClose > haOpen;
plot trendUp = haColor and !haColor[1];
trendUp.SetDefaultColor(Color.CYAN);
trendUp.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
plot trendDown = !haColor and haColor[1];
trendDown.SetDefaultColor(Color.MAGENTA);
trendDown.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
Alert(trendUp, "Trend Up", Alert.BAR, Sound.RING);
Alert(trendDown, "Trend Down", Alert.BAR, Sound.RING);
Screenshot below shows this plotted on a daily chart. Change the chart to whatever time frame you want.
Thank you! How would I apply this method on scan or email alerts? Thank you for your help in advance.
In order to modify this code to serve as a Study Filter in a Scan.
Replace the following lines:
plot trendUp = haColor and !haColor[1];
trendUp.SetDefaultColor(Color.CYAN);
trendUp.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
plot trendDown = !haColor and haColor[1];
trendDown.SetDefaultColor(Color.MAGENTA);
trendDown.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
Alert(trendUp, “Trend Up”, Alert.BAR, Sound.RING);
Alert(trendDown, “Trend Down”, Alert.BAR, Sound.RING);
With these lines:
def trendUp = haColor and !haColor[1];
def trendDown = !haColor and haColor[1];
plot scan = trendUp;
#plot scan = trendDown;