MQL5 Expert Advisor Problem

 

I'm trying to make a expert advisor via mql5 but I'm taking these errors anyone can help ?

trade.Buy(lotSize, Symbol(), ask, ask - StopLoss * Point, ask + TakeProfit * Point); 

')' - open parenthesis expected SMC_Swing_Trader.mq5


trade.Sell(lotSize, Symbol(), bid, bid - StopLoss * Point, bid + TakeProfit * Point);

',' - open parenthesis expected SMC_Swing_Trader.mq5 84 66

')' - open parenthesis expected SMC_Swing_Trader.mq5 84 92


if (PositionSelect(i))

implicit conversion from 'number' to 'string' SMC_Swing_Trader.mq5 97 28


double newStopLoss = currentPrice - TrailingStop * Point;

';' - open parenthesis expected SMC_Swing_Trader.mq5 106 73

double newStopLoss = currentPrice + TrailingStop * Point;

';' - open parenthesis expected SMC_Swing_Trader.mq5 114 73

#include <Trade\Trade.mqh>

// User Inputs
input double Lots = 0.1;
input double StopLoss = 30;
input double TakeProfit = 50;
input int ATRPeriod = 14;
input double RiskPercentage = 1.0;
input int StartHour = 10;
input int EndHour = 23;
input bool UseTrailingStop = true;
input double TrailingStop = 20;

CTrade trade;

// Calculate Lot Size
double CalculateLotSize()
{
    double accountBalance = AccountInfoDouble(ACCOUNT_BALANCE);
    double riskAmount = accountBalance * RiskPercentage / 100.0;
    double tickValue = SymbolInfoDouble(Symbol(), SYMBOL_TRADE_TICK_VALUE);
    double tickSize = SymbolInfoDouble(Symbol(), SYMBOL_TRADE_TICK_SIZE);

    if (tickValue <= 0 || tickSize <= 0)
        return Lots;

    double lotSize = riskAmount / (tickValue * StopLoss * tickSize);
    return NormalizeDouble(lotSize, 2);
}

// Check Trading Hours
bool IsTradingTime()
{
    datetime currentTime = TimeLocal();
    MqlDateTime timeStruct;
    TimeToStruct(currentTime, timeStruct);
    int hour = timeStruct.hour;

    return (hour >= StartHour && hour <= EndHour);
}

// Get ATR Value
double GetATR()
{
    return iATR(Symbol(), PERIOD_CURRENT, ATRPeriod);
}

// Check for Buy and Sell Conditions
bool ConditionsForBuy()
{
    return GetATR() > 20;
}

bool ConditionsForSell()
{
    return GetATR() < 10;
}

// Check for Trades
void CheckForTrades()
{
    if (!IsTradingTime())
        return;

    double ask = SymbolInfoDouble(Symbol(), SYMBOL_ASK);
    double bid = SymbolInfoDouble(Symbol(), SYMBOL_BID);

    if (ask <= 0.0 || bid <= 0.0)
        return;

    static datetime lastTradeTime = 0;
    if (lastTradeTime == TimeCurrent())
        return;

    if (ConditionsForBuy())
    {
        double lotSize = CalculateLotSize();
        trade.Buy(lotSize, Symbol(), ask, ask - (StopLoss * Point), ask + (TakeProfit * Point)); // Fixed parentheses
        lastTradeTime = TimeCurrent();
    }
    else if (ConditionsForSell())
    {
        double lotSize = CalculateLotSize();
        trade.Sell(lotSize, Symbol(), bid, bid - (StopLoss * Point), bid + (TakeProfit * Point)); // Fixed parentheses
        lastTradeTime = TimeCurrent();
    }
}

// Apply Trailing Stop
void ApplyTrailingStop()
{
    if (!UseTrailingStop)
        return;

    for (int i = PositionsTotal() - 1; i >= 0; i--)
    {
        if (PositionSelect(i))
        {
            ulong ticket = PositionGetInteger(POSITION_TICKET);
            double stopLoss = PositionGetDouble(POSITION_SL);
            double currentPrice = SymbolInfoDouble(Symbol(),
                PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_BUY ? SYMBOL_BID : SYMBOL_ASK);

            if (PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_BUY)
            {
                double newStopLoss = currentPrice - (TrailingStop * Point);
                if (newStopLoss > stopLoss)
                {
                    trade.PositionModify(ticket, newStopLoss, PositionGetDouble(POSITION_TP));
                }
            }
            else if (PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_SELL)
            {
                double newStopLoss = currentPrice + (TrailingStop * Point);
                if (newStopLoss < stopLoss)
                {
                    trade.PositionModify(ticket, newStopLoss, PositionGetDouble(POSITION_TP));
                }
            }
        }
    }
}

// OnInit Function
int OnInit()
{
    return INIT_SUCCEEDED;
}

// OnTick Function
void OnTick()
{
    CheckForTrades();
    ApplyTrailingStop();
}





 
When you post code please use the CODE button (Alt-S) !  
 
Mehmet Bekir:

I'm trying to make a expert advisor via mql5 but I'm taking these errors anyone can help ?

';' - open parenthesis expected SMC_Swing_Trader.mq5 114 73



add brackets after Point like so Point()
same on every line with that error.


code button.

 
Mehmet Bekir #: this is the whole code

Your code seems to be the result of generating it with ChatGPT (or other A.I.) as it has mixed MQL4 and MQL5 code.

If that is the case, then we will not help you, because it generates horrible code. Consider the Freelance section for such requests.

Trading applications for MetaTrader 5 to order
Trading applications for MetaTrader 5 to order
  • 2024.12.23
  • www.mql5.com
The largest freelance service with MQL5 application developers
 
Your topic has been moved to the section: Expert Advisors and Automated Trading
Please consider which section is most appropriate — https://www.mql5.com/en/forum/172166/page6#comment_49114893
 
Michael Charles Schefe #:

add brackets after Point like so Point()
same on every line with that error.


code button.

implicit conversion from 'number' to 'string' SMC_Swing_Trader.mq5 97 28
  for (int i = PositionsTotal() - 1; i >= 0; i--)
    {
        if (PositionSelect(i))


 
Mehmet Bekir #:
implicit conversion from 'number' to 'string' SMC_Swing_Trader.mq5 97 28


search the website. we do not spoon feed newbies here.

and just like the moderator said, I agree, looks like you have mixed mt4 and mt5 code together. I agree with moderator, I think that you did NOT create this code yourself.