Hi, I try to create an EA with MQL5 th.... However, I get this [error:',' - open parenthesis expected.] , I don't know what the problem is , would you please help me to solve this error?

 

Hi, I try to create an EA with MQL5 that pulls values from another indicator to use as signals for buying and selling. However, I get this [error:',' - open parenthesis expected.] , I don't know what the problem is , would you please help me to solve this error?



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

//| Expert initialization function                                   |
//+------------------------------------------------------------------+
#include <Trade\Trade.mqh>
#include <Indicators\Indicators.mqh>

input string IndicatorName = "MQLTA-RSIWA";                // Indicator Short Name
input int RSIPeriod = 14;                                  // RSI Period
input ENUM_APPLIED_PRICE RSIAppliedPrice = PRICE_CLOSE;    // RSI Applied Price
input int TakeProfit = 300; // 300 points TP
input int StopLoss = 200;   // 200 points SL
input double LotSize = 0.1; // Lot size

CTrade trade;

// Handle for the RSI indicator
int RSI_Handle;

// Buffer for RSI values
double RSI_Buffer[];

// OnInit function to initialize the EA and indicator
int OnInit()
{
    // Create the handle for the RSI indicator
    RSI_Handle = iRSI(Symbol(), PERIOD_CURRENT, RSIPeriod, RSIAppliedPrice);
    if (RSI_Handle == INVALID_HANDLE)
    {
        Print("Failed to create RSI indicator handle! Error: ", GetLastError());
        return INIT_FAILED;
    }

    // Initialize the buffer
    ArraySetAsSeries(RSI_Buffer, true);
    
    return INIT_SUCCEEDED;
}

// OnDeinit function to clean up
void OnDeinit(const int reason)
{
    // Release the RSI indicator handle
    IndicatorRelease(RSI_Handle);
}

// OnTick function to check for trading signals and execute orders
void OnTick()
{
    // Create a structure to store price data
    MqlTick tick;

    // Get the current price data
    if(!SymbolInfoTick(Symbol(), tick))
    {
        Print("Failed to get current price data! Error: ", GetLastError());
        return;
    }

    // Check how many bars are available
    int bars = Bars;
    if(bars < RSIPeriod + 1)
        return;

    // Copy the latest RSI values (current and previous)
    if(CopyBuffer(RSI_Handle, 0, 0, 2, RSI_Buffer) < 2)
    {
        Print("Failed to copy RSI data! Error: ", GetLastError());
        return;
    }

    double current_RSI = RSI_Buffer[0];
    double previous_RSI = RSI_Buffer[1];
    
    // Print RSI values for debugging
    //Print("Current RSI: ", current_RSI, " Previous RSI: ", previous_RSI);

    // Buy Signal: RSI crosses above RSILowLimit (30)
    if(previous_RSI < 30 && current_RSI >= 30)
    {
        // Check if there are no open Buy positions
        if(!PositionExists(POSITION_TYPE_BUY))
        {
            // Open Buy order using the Ask price
            if(trade.Buy(LotSize, Symbol(), tick.ask, (tick.ask - StopLoss * _Point), (tick.ask + TakeProfit * _Point), "RSI Buy"))
            {
                Print("Buy order opened successfully.");
            }
            else
            {
                Print("Error opening Buy order: ", GetLastError());
            }
        }
    }

    // Sell Signal: RSI crosses below RSIHighLimit (70)
    if(previous_RSI > 70 && current_RSI <= 70)
    {
        // Check if there are no open Sell positions
        if(!PositionExists(POSITION_TYPE_SELL))
        {
            // Open Sell order using the Bid price
            if(trade.Sell(LotSize, Symbol(), tick.bid, (tick.bid + StopLoss * _Point), (tick.bid - TakeProfit * _Point), "RSI Sell"))
            {
                Print("Sell order opened successfully.");
            }
            else
            {
                Print("Error opening Sell order: ", GetLastError());
            }
        }
    }
}

// Function to check if there is an open position of a specific type
bool PositionExists(int type)
{
    bool exists = false;
    for(int i = PositionsTotal() - 1; i >= 0; i--)
    {
        ulong ticket = PositionGetTicket(i);
        if(PositionSelectByTicket(ticket))
        {
            if(PositionGetInteger(POSITION_TYPE) == type && PositionGetString(POSITION_SYMBOL) == Symbol())
            {
                exists = true;
                break;
            }
        }
    }
    return exists;
}



';' - open parenthesis expected 60 25

1 errors, 0 warnings 2 1


This is what is shown in line 60 = int bars = Bars;



Documentation on MQL5: Constants, Enumerations and Structures / Trade Constants / Position Properties
Documentation on MQL5: Constants, Enumerations and Structures / Trade Constants / Position Properties
  • www.mql5.com
Execution of trade operations results in the opening of a position, changing of its volume and/or direction, or its disappearance. Trade operations...
 
  // Check how many bars are available
    int bars = Bars;

that's the problem, this would only work in MQL4 unless you used cross platform code in MQL5


change to

  // Check how many bars are available
    int bars = Bars(_Symbol, _Period);
 
Conor Mcnamara #:
int bars = Bars(_Symbol, _Period);

Thank you for your assistance in this matter :]