Trendline indicator

 

Hello, im trying to make an indicator that extends trendlines to the current time on the chart, this is the code 


//+------------------------------------------------------------------+
//|                                             HorizontalTrendlines.mq4 |
//|                        Copyright 2024, Your Name                  |
//|                                       https://www.yourwebsite.com |
//+------------------------------------------------------------------+
#property copyright "Your Name"
#property link      "https://www.yourwebsite.com"
#property version   "1.00"
#property indicator_separate_window false
#property indicator_buffers 0

// Input parameters
input double LevelOffset = 0.0001; // Minimum price difference to consider a level
input int MaxBars = 1000;           // Maximum number of bars to scan

//+------------------------------------------------------------------+
//| Custom indicator initialization function                           |
//+------------------------------------------------------------------+
int OnInit()
{
    // Set the indicator to be redrawn on every tick
    EventSetMillisecondTimer(1000);
    return(INIT_SUCCEEDED);
}

//+------------------------------------------------------------------+
//| 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 double &spread[])
{
    // Clear previous trendlines
    ObjectsDeleteAll();

    // Scan the chart for horizontal levels
    for (int i = 1; i < MathMin(MaxBars, rates_total - 1); i++)
    {
        double price1 = close[i];
        double price2 = close[i + 1];

        // Check if the two prices are within the defined offset
        if (MathAbs(price1 - price2) < LevelOffset)
        {
            // Draw a horizontal line at the price level
            string lineName = "HorizontalLine_" + DoubleToString(price1, 5);
            if (ObjectFind(0, lineName) == -1) // Check if the object does not exist
            {
                ObjectCreate(0, lineName, OBJ_HLINE, 0, time[i], price1);
                ObjectSetInteger(0, lineName, OBJPROP_COLOR, clrBlue);
                ObjectSetInteger(0, lineName, OBJPROP_WIDTH, 2);
                ObjectSetInteger(0, lineName, OBJPROP_RAY_RIGHT, true); // Extend to the right
            }
        }
    }

    return(rates_total); // Return the number of processed bars
}
//+------------------------------------------------------------------+

i keep getting the error 


OnCalculate function declared with wrong type or/and parameters HorizontalTrendlines.mq4        29      5
OnCalculate function not found in custom indicator              1       1

anyone knows why?

 
OnCalculate function declared with wrong type or/and parameters HorizontalTrendlines.mq4        29      5

It told you exactly what line is the problem. Perhaps you should read the manual, or press F1 in the editor. Event Handling Functions - Functions - Language Basics - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
   How To Ask Questions The Smart Way. (2004)
      How To Interpret Answers.
         RTFM and STFW: How To Tell You've Seriously Screwed Up.

Your code
Documentation
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 double &spread[]
)
int OnCalculate (
    const int rates_total,      // size of input time series
    const int prev_calculated,  // bars handled in previous call
    const datetime& time[],     // Time
    const double& open[],       // Open
    const double& high[],       // High
    const double& low[],        // Low
    const double& close[],      // Close
    const long& tick_volume[],  // Tick Volume
    const long& volume[],       // Real Volume
    const int& spread[]         // Spread
   );