Problem 'close' - constant variable cannot be passed as reference

 

Someone can fix this code please?. I cant find run it.. show error  'close' - constant variable cannot be passed as reference

Thanks 


//+------------------------------------------------------------------+

//|                                                     patornes.mq4 |
//|                        Adaptado de Pine Script a MetaTrader 4           |
//+------------------------------------------------------------------+
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Lime
#property indicator_color2 Red

// Definición de buffers para las flechas de compra y venta
double BuyBuffer[];
double SellBuffer[];

// Parámetros de entrada
input int len = 10;         // Longitud del Patrón
input int lookback = 100;   // Rango de Búsqueda
input double similarityThreshold = 0.95;  // Umbral de Similitud

// Función para inicializar los indicadores
int OnInit() {
    SetIndexBuffer(0, BuyBuffer);
    SetIndexBuffer(1, SellBuffer);
    PlotIndexSetInteger(0, PLOT_ARROW, 233); // Flecha hacia arriba
    PlotIndexSetInteger(1, PLOT_ARROW, 234); // Flecha hacia abajo
    return(INIT_SUCCEEDED);
}

// Función para encontrar el patrón en los precios
double FindPattern(double src[], int start, int length, double pattern[]) {
    for (int i = 0; i < length; i++) {
        pattern[i] = src[start - i];
    }
}

// Función principal de cálculo
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[]) {

    // Asegurarse de tener suficientes barras
    if (rates_total < lookback + len) return(0);

    double currentPattern[];
    ArrayResize(currentPattern, len);

    double pastPattern[];
    ArrayResize(pastPattern, len);

    // Variables para la similitud y la posición del patrón
    double similarity;
    int similarPatternStart = -1;

    // Buscar el patrón actual
    FindPattern(close, 0, len, currentPattern);

    // Buscar patrones similares en el pasado
    for (int i = len; i <= lookback; i++) {
        FindPattern(close, i, len, pastPattern);
        similarity = 0.0;

        for (int j = 0; j < len; j++) {
            similarity += MathAbs((currentPattern[j] - pastPattern[j]) / pastPattern[j]);
        }

        similarity /= len;
        if (similarity < (1 - similarityThreshold)) {
            similarPatternStart = i;
            break;
        }
    }

    // Generar señales de compra y venta
    if (similarPatternStart != -1) {
        if (close[0] < close[similarPatternStart]) {
            BuyBuffer[0] = Low[0] - Point * 10; // Flecha de compra debajo del precio actual
            SellBuffer[0] = EMPTY_VALUE;       // No mostrar venta
        } else if (close[0] > close[similarPatternStart]) {
            SellBuffer[0] = High[0] + Point * 10; // Flecha de venta encima del precio actual
            BuyBuffer[0] = EMPTY_VALUE;           // No mostrar compra
        }
    } else {
        // Sin señales
        BuyBuffer[0] = EMPTY_VALUE;
        SellBuffer[0] = EMPTY_VALUE;
    }

    return(rates_total);
}

 

Add the const specifier to the function parameter where you pass the close[] array

void FindPattern(const double &close[])
  {
   
  }

[EDIT]

 
Vladislav Boyko #:

Add the const specifier to the function parameter where you pass the close[] array

I Cant fix it......can you help please...

 
  1. //|                                                     patornes.mq4 |

    Why did you post your MT4 question in the MT5 General section (a miscellaneous catch-all category) instead of the MQL4 section, (bottom of the Root page)?
              General rules and best pratices of the Forum. - General - MQL5 programming forum? (2017)
    Next time, post in the correct place. I have moved this thread.

  2. Gustavo Adolfo Ortega Osorio: ?. I cant find run it.. show error  'close' - constant variable cannot be passed as reference
    int OnCalculate(…, const double &close[],…)
        FindPattern(close, 0, len, currentPattern);
    
    You passed it, which you do not show. Your function does not take a const array.