Where is the mistake in that simple code please ? (MQL5)

 

Hello all, 


I've made this simple indicator from the Heikin Ashi template of Metaquotes and added some code to plot 2 EMAs calculated from heikin ashi close price and to plot bullish and bearish cross over signals from the two EMAs. 


However when I modify the code (pasted below) to change appearance of the cross over signals, nothing happens. It is always the same symbol that plots and it is not matching the symbol numbers used (233 and 234).


I have no idea why even though it is a simple problem (I'm not good with code). Can somebody help me with this please ?


All the best,


//+------------------------------------------------------------------+
//|                                                  Heiken_Ashi.mq5 |
//|                             Copyright 2000-2024, MetaQuotes Ltd. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2000-2024, MetaQuotes Ltd."
#property link      "https://www.mql5.com"
//--- indicator settings
#property indicator_chart_window
#property indicator_buffers 9
#property indicator_plots   5
//--- Heiken Ashi properties
#property indicator_type1   DRAW_COLOR_CANDLES
#property indicator_color1  DodgerBlue, Red
#property indicator_label1  "Heiken Ashi"
//--- EMA properties
#property indicator_type2   DRAW_LINE
#property indicator_color2  Gold
#property indicator_label2  "EMA 1"
#property indicator_type3   DRAW_LINE
#property indicator_color3  Lime
#property indicator_label3  "EMA 2"
//--- Bullish signal properties
#property indicator_type4   DRAW_ARROW
#property indicator_color4  Lime
#property indicator_label4  "Bullish Signal"
#property indicator_style4  STYLE_SOLID
#property indicator_width4  1
//--- Bearish signal properties
#property indicator_type5   DRAW_ARROW
#property indicator_color5  Red
#property indicator_label5  "Bearish Signal"
#property indicator_style5  STYLE_SOLID
#property indicator_width5  1
//--- input parameters for EMAs
input int InpEMA1Period = 14; // Period for the first EMA
input int InpEMA2Period = 28; // Period for the second EMA
//--- input parameters for signal customization
input int BullishSignalSymbol = 233; // Default symbol code for bullish signal (up arrow)
input int BearishSignalSymbol = 234; // Default symbol code for bearish signal (down arrow)
input int SignalSize = 1; // Size of the signal arrows
//--- new input parameters for changing symbol numbers
input int BullishSignalNumber = 1; // Number of bullish symbols to plot
input int BearishSignalNumber = 1; // Number of bearish symbols to plot
//--- indicator buffers
double ExtOBuffer[];
double ExtHBuffer[];
double ExtLBuffer[];
double ExtCBuffer[];
double ExtColorBuffer[];
double ExtEMA1Buffer[]; // Buffer for the first EMA
double ExtEMA2Buffer[]; // Buffer for the second EMA
double BullishSignalBuffer[]; // Buffer for bullish signals
double BearishSignalBuffer[]; // Buffer for bearish signals
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
void OnInit() {
    //--- indicator buffers mapping
    SetIndexBuffer(0, ExtOBuffer, INDICATOR_DATA);
    SetIndexBuffer(1, ExtHBuffer, INDICATOR_DATA);
    SetIndexBuffer(2, ExtLBuffer, INDICATOR_DATA);
    SetIndexBuffer(3, ExtCBuffer, INDICATOR_DATA);
    SetIndexBuffer(4, ExtColorBuffer, INDICATOR_COLOR_INDEX);
    SetIndexBuffer(5, ExtEMA1Buffer, INDICATOR_DATA);
    SetIndexBuffer(6, ExtEMA2Buffer, INDICATOR_DATA);
    SetIndexBuffer(7, BullishSignalBuffer, INDICATOR_DATA);
    SetIndexBuffer(8, BearishSignalBuffer, INDICATOR_DATA);
    //--- set drawing properties for signals
    PlotIndexSetInteger(4, PLOT_ARROW, BullishSignalSymbol);
    PlotIndexSetInteger(5, PLOT_ARROW, BearishSignalSymbol);
    PlotIndexSetInteger(4, PLOT_ARROW_SHIFT, 0);
    PlotIndexSetInteger(5, PLOT_ARROW_SHIFT, 0);
    PlotIndexSetInteger(4, PLOT_LINE_WIDTH, SignalSize);
    PlotIndexSetInteger(5, PLOT_LINE_WIDTH, SignalSize);
    IndicatorSetString(INDICATOR_SHORTNAME, "Heiken Ashi + 2 EMAs + Signals");
}
//+------------------------------------------------------------------+
//| Heiken Ashi and EMA calculation plus signal detection            |
//+------------------------------------------------------------------+
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[]) 
                
                {
    int start = prev_calculated > 1 ? prev_calculated - 1 : 0;
    if(prev_calculated < 1) {
        start = 1; // Start from the first bar
        ExtOBuffer[0] = open[0];
        ExtHBuffer[0] = high[0];
        ExtLBuffer[0] = low[0];
        ExtCBuffer[0] = close[0];
    }
    // Main calculation loop
    for(int i = start; i < rates_total; i++) {
        // Calculate Heiken Ashi values
        double ha_open = (ExtOBuffer[i-1] + ExtCBuffer[i-1]) / 2.0;
        double ha_close = (open[i] + high[i] + low[i] + close[i]) / 4.0;
        double ha_high = MathMax(high[i], MathMax(ha_open, ha_close));
        double ha_low = MathMin(low[i], MathMin(ha_open, ha_close));
        ExtOBuffer[i] = ha_open;
        ExtHBuffer[i] = ha_high;
        ExtLBuffer[i] = ha_low;
        ExtCBuffer[i] = ha_close;
        if(ha_open < ha_close)
            ExtColorBuffer[i] = 0; // Bullish candle
        else
            ExtColorBuffer[i] = 1; // Bearish candle
        // Reset signals
        BullishSignalBuffer[i] = EMPTY_VALUE;
        BearishSignalBuffer[i] = EMPTY_VALUE;
    }
    // Calculate EMAs and detect crossovers for signals
    CalculateEMA(rates_total, InpEMA1Period, ExtCBuffer, ExtEMA1Buffer);
    CalculateEMA(rates_total, InpEMA2Period, ExtCBuffer, ExtEMA2Buffer);
    for(int i = 1; i < rates_total; i++) {
        // Detecting bullish crossover
        if(ExtEMA1Buffer[i] > ExtEMA2Buffer[i] && ExtEMA1Buffer[i-1] <= ExtEMA2Buffer[i-1]) {
            BullishSignalBuffer[i] = low[i] - (4 * _Point); // Place arrow below the low
        }
        // Detecting bearish crossover
        else if(ExtEMA1Buffer[i] < ExtEMA2Buffer[i] && ExtEMA1Buffer[i-1] >= ExtEMA2Buffer[i-1]) {
            BearishSignalBuffer[i] = high[i] + (4 * _Point); // Place arrow above the high
        }
    }
    return(rates_total);
}
//+------------------------------------------------------------------+
//| Exponential Moving Average calculation                           |
//+------------------------------------------------------------------+
void CalculateEMA(int rates_total, int period, const double &price[], double &ema[]) {
    double multiplier = 2.0 / (period + 1.0);
    for(int i = 0; i < rates_total; i++) {
        if(i == 0) {
            ema[i] = price[i]; // Simple initialization
        } else {
            ema[i] = (price[i] - ema[i-1]) * multiplier + ema[i-1];
        }
    }
}
//+------------------------------------------------------------------+