This indicator is supposed to alert when the current Heiken Ashi candle is 50% larger than the previous candle.
My notifications look like I'm getting alerts from June 2022.
I should be getting an alert shown as an arrow at the candle when this happens. No arrows showing yet.
I only get a popup window and sound. The alert in the window should say which pair it refers to.
Here is the code:
#property copyright "Copyright 2023, Your Name"
#property link "https://www.example.com"
#property version "1.00"
#property strict
#property indicator_chart_window
input bool UsePopupAlert = true;
input bool UseSoundAlert = true;
input bool SendNotificationAlert = true;
input string SoundFileName = "alert.wav";
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
const int prev_calculated,
const datetime &time[],
const double &open[],
const double &high[],
const double &low[],
const double &close[],
const long &tick_volume[],
const long &volume[],
const int &spread[])
{
double haOpen[], haHigh[], haLow[], haClose[];
ArrayResize(haOpen, rates_total);
ArrayResize(haHigh, rates_total);
ArrayResize(haLow, rates_total);
ArrayResize(haClose, rates_total);
InitializeHeikenAshi(rates_total, open, high, low, close, haOpen, haHigh, haLow, haClose);
for (int j = rates_total - 1; j >= prev_calculated - 1 && j > rates_total - 11; j--) {
if (j == rates_total - 1) {
continue;
}
bool bullishCandle = haClose[j] > haOpen[j];
bool bearishCandle = haClose[j] < haOpen[j];
bool is50PercentLarger = MathAbs(haClose[j] - haOpen[j]) > 1.5 * MathAbs(haClose[j - 1] - haOpen[j - 1]);
if (bullishCandle && is50PercentLarger) {
ObjectCreate(0, "DodgerBlueArrow" + IntegerToString(j), OBJ_ARROW, 0, time[j], low[j] - (20 * Point));
ObjectSetInteger(0, "DodgerBlueArrow" + IntegerToString(j), OBJPROP_COLOR, DodgerBlue);
ObjectSetInteger(0, "DodgerBlueArrow" + IntegerToString(j), OBJPROP_ARROWCODE, 242);
ObjectSetInteger(0, "DodgerBlueArrow" + IntegerToString(j), OBJPROP_BACK, false);
if (UsePopupAlert) {
Alert("Bullish Heiken Ashi 50% larger alert at ", TimeToStr(time[j]));
}
if (UseSoundAlert) {
PlaySound(SoundFileName);
}
if (SendNotificationAlert) {
SendNotification("Bullish Heiken Ashi 50% larger alert at " + TimeToStr(time[j]));
}
}
if (bearishCandle && is50PercentLarger) {
ObjectCreate(0, "RedArrow" + IntegerToString(j), OBJ_ARROW, 0, time[j], high[j] + (20 * Point));
ObjectSetInteger(0, "RedArrow" + IntegerToString(j), OBJPROP_COLOR, Red);
ObjectSetInteger(0, "RedArrow" + IntegerToString(j), OBJPROP_ARROWCODE, 241);
ObjectSetInteger(0, "RedArrow" + IntegerToString(j), OBJPROP_BACK, false);
if (UsePopupAlert) {
Alert("Bearish Heiken Ashi 50% larger alert at ", TimeToStr(time[j]));
}
if (UseSoundAlert) {
PlaySound(SoundFileName);
}
if (SendNotificationAlert) {
SendNotification("Bearish Heiken Ashi 50% larger alert at " + TimeToStr(time[j]));
}
}
}
return(rates_total);
}
//+------------------------------------------------------------------+
void InitializeHeikenAshi(const int rates_total,
const double &open[],
const double &high[],
const double &low[],
const double &close[],
double &haOpen[],
double &haHigh[],
double &haLow[],
double &haClose[])
{
haOpen[0] = (open[0] + close[0]) / 2;
haHigh[0] = high[0];
haLow[0] = low[0];
haClose[0] = (open[0] + high[0] + low[0] + close[0]) / 4;
for (int i = 1; i < rates_total; i++) {
haOpen[i] = (haOpen[i - 1] + haClose[i - 1]) / 2;
haHigh[i] = MathMax(high[i], haOpen[i]);
haLow[i] = MathMin(low[i], haOpen[i]);
haClose[i] = (open[i] + high[i] + low[i] + close[i]) / 4;
}
}
//+------------------------------------------------------------------+
Funded trader
1