Code shows error when trying to compile please help

 

It keeps on telling me about parenthesis when I try to compile please help

';' - unexpected end of program gold3.mq5 317 41

'{' - unbalanced parentheses gold3.mq5 146 1


#include <Trade\Trade.mqh>
input int MagicNumber=10001;
input double Lots =0.05;
input double StopLoss=45;
input double TakeProfit=135;
input int TrailingStop=65;
//+------------------------------------------------------------------+
//    expert start function
//+------------------------------------------------------------------+

 ENUM_MA_METHOD MethodMigrate(int method)
  {
   switch(method)
     {
      case 0: return(MODE_SMA);
      case 1: return(MODE_EMA);
      case 2: return(MODE_SMMA);
      case 3: return(MODE_LWMA);
      default: return(MODE_SMA);
     }
  }
  
ENUM_STO_PRICE StoFieldMigrate(int field)
  {
   switch(field)
     {
      case 0: return(STO_LOWHIGH);
      case 1: return(STO_CLOSECLOSE);
      default: return(STO_LOWHIGH);
     }
  }
ENUM_APPLIED_PRICE PriceMigrate(int price)
  {
   switch(price)
     {
      case 1: return(PRICE_CLOSE);
      case 2: return(PRICE_OPEN);
      case 3: return(PRICE_HIGH);
      case 4: return(PRICE_LOW);
      case 5: return(PRICE_MEDIAN);
      case 6: return(PRICE_TYPICAL);
      case 7: return(PRICE_WEIGHTED);
      default: return(PRICE_CLOSE);
     }
  }

ENUM_TIMEFRAMES TFMigrate(int tf)
  {
   switch(tf)
     {
      case 0: return(PERIOD_CURRENT);
      case 1: return(PERIOD_M1);
      case 5: return(PERIOD_M5);
      case 15: return(PERIOD_M15);
      case 30: return(PERIOD_M30);
      case 60: return(PERIOD_H1);
      case 240: return(PERIOD_H4);
      case 1440: return(PERIOD_D1);
      case 10080: return(PERIOD_W1);
      case 43200: return(PERIOD_MN1);
      
      case 2: return(PERIOD_M2);
      case 3: return(PERIOD_M3);
      case 4: return(PERIOD_M4);      
      case 6: return(PERIOD_M6);
      case 10: return(PERIOD_M10);
      case 12: return(PERIOD_M12);
      case 16385: return(PERIOD_H1);
      case 16386: return(PERIOD_H2);
      case 16387: return(PERIOD_H3);
      case 16388: return(PERIOD_H4);
      case 16390: return(PERIOD_H6);
      case 16392: return(PERIOD_H8);
      case 16396: return(PERIOD_H12);
      case 16408: return(PERIOD_D1);
      case 32769: return(PERIOD_W1);
      case 49153: return(PERIOD_MN1);      
      default: return(PERIOD_CURRENT);
     }
  }
  
#define MODE_MAIN 0  
#define MODE_SIGNAL 1
#define MODE_PLUSDI 1
#define MODE_MINUSDI 2
#define MODE_OPEN 0
#define MODE_LOW 1
#define MODE_HIGH 2
#define MODE_CLOSE 3
#define MODE_VOLUME 4 
#define MODE_REAL_VOLUME 5


#define OP_BUY 0           //Buy 
#define OP_SELL 1          //Sell 
#define OP_BUYLIMIT 2      //Pending order of BUY LIMIT type 
#define OP_SELLLIMIT 3     //Pending order of SELL LIMIT type 
#define OP_BUYSTOP 4       //Pending order of BUY STOP type 
#define OP_SELLSTOP 5      //Pending order of SELL STOP type 
//---
#define MODE_TRADES 0
#define MODE_HISTORY 1
#define SELECT_BY_POS 0
#define SELECT_BY_TICKET 1
//---
#define DOUBLE_VALUE 0
#define FLOAT_VALUE 1
#define LONG_VALUE INT_VALUE
//---
#define CHART_BAR 0
#define CHART_CANDLE 1
//---
#define MODE_ASCEND 0
#define MODE_DESCEND 1
//---

#define MODE_TIME 5
#define MODE_BID 9
#define MODE_ASK 10
#define MODE_POINT 11
#define MODE_DIGITS 12
#define MODE_SPREAD 13
#define MODE_STOPLEVEL 14
#define MODE_LOTSIZE 15
#define MODE_TICKVALUE 16
#define MODE_TICKSIZE 17
#define MODE_SWAPLONG 18
#define MODE_SWAPSHORT 19
#define MODE_STARTING 20
#define MODE_EXPIRATION 21
#define MODE_TRADEALLOWED 22
#define MODE_MINLOT 23
#define MODE_LOTSTEP 24
#define MODE_MAXLOT 25
#define MODE_SWAPTYPE 26
#define MODE_PROFITCALCMODE 27
#define MODE_MARGINCALCMODE 28
#define MODE_MARGININIT 29
#define MODE_MARGINMAINTENANCE 30
#define MODE_MARGINHEDGED 31
#define MODE_MARGINREQUIRED 32
#define MODE_FREEZELEVEL 33
//---
#define EMPTY -1
void OnTick()
{
CTrade trade;
trade.SetExpertMagicNumber(MagicNumber);
double Ask=SymbolInfoDouble(_Symbol,SYMBOL_ASK);
double Bid=SymbolInfoDouble(_Symbol,SYMBOL_BID);

  double MyPoint=_Point;
  if(_Digits==3 || _Digits==5) MyPoint=_Point*10;
  double TheStopLoss=0;
  double TheTakeProfit=0;
  if( TotalOrdersCount()==0 ) 
 
     
      if (RSI < 30)
    {
        // Wait for confirmation of oversold condition
        while (RSI < 30)
        {
            RSI = iRSI(Symbol(), PERIOD_M5, RSIPeriod, PRICE_CLOSE, 0);
        }
        
        // Open a long position
        ticket = OrderSend(Symbol(), OP_BUY, 0.01, Ask, 0, Bid - StopLoss * _Point, Bid + TakeProfit * _Point, "Scalping EA", 0, 0, Green);
        
        if (ticket <= 0)
        {
            Print("Error opening long position: ", GetLastError());
        }

     
  }
  
   int posTotal=PositionsTotal();
   for(int posIndex=posTotal-1;posIndex>=0;posIndex--)
     {
      ulong ticket=PositionGetTicket(posIndex);
      if(PositionSelectByTicket(ticket) && PositionGetInteger(POSITION_MAGIC)==MagicNumber) 
      {
     if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_BUY)
        {
         if(TrailingStop>0)  
              {                 
               if(SymbolInfoDouble(_Symbol,SYMBOL_BID)-PositionGetDouble(POSITION_PRICE_OPEN)>MyPoint*TrailingStop)
                 {
                  if(PositionGetDouble(POSITION_SL)<SymbolInfoDouble(_Symbol,SYMBOL_BID)-MyPoint*TrailingStop)
                    {
                    trade.PositionModify(ticket,SymbolInfoDouble(_Symbol,SYMBOL_BID)-MyPoint*TrailingStop,PositionGetDouble(POSITION_TP));
                     return;
                    }
                 }
              }
        
      
       if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_SELL)
        {
          if(TrailingStop>0)  
              {                 
               if(PositionGetDouble(POSITION_PRICE_OPEN)-SymbolInfoDouble(_Symbol,SYMBOL_ASK)>MyPoint*TrailingStop)
                 {
                  if(PositionGetDouble(POSITION_SL)>SymbolInfoDouble(_Symbol,SYMBOL_ASK)+MyPoint*TrailingStop)
                    {
                    trade.PositionModify(ticket,SymbolInfoDouble(_Symbol,SYMBOL_ASK)+MyPoint*TrailingStop,PositionGetDouble(POSITION_TP));
                     return;
                    }
                 }
              }
        }
      }
     }  
    return;
}

int TotalOrdersCount()
{
  int result=0;
  int posTotal=PositionsTotal();
  for(int posIndex=posTotal-1; posIndex>=0; posIndex--)
  {
    ulong ticket=PositionGetTicket(posIndex);
    if(PositionSelect(ticket) && PositionGetInteger(POSITION_MAGIC)==MagicNumber)
      result++;
  }  
  return (result);
}

int Hour()
{
   MqlDateTime tm;
   TimeToStruct(TimeCurrent(), tm);
   return(tm.hour);
}

int Minute()
{
   MqlDateTime tm;
   TimeToStruct(TimeCurrent(), tm);
   return(tm.min);
}

double CopyBufferMQL5(int handle, int index, int shift)
{
   double buf[];
   switch(index)
   {
      case 0: if(CopyBuffer(handle, 0, shift, 1, buf) > 0)
                 return(buf[0]);
              break;
      case 1: if(CopyBuffer(handle, 1, shift, 1, buf) > 0)
                 return(buf[0]);
              break;
      case 2: if(CopyBuffer(handle, 2, shift, 1, buf) > 0)
                 return(buf[0]);
              break;
      case 3: if(CopyBuffer(handle, 3, shift, 1, buf) > 0)
                 return(buf[0]);
              break;
      case 4: if(CopyBuffer(handle, 4, shift, 1, buf) > 0)
                 return(buf[0]);
              break;
      default: break;
   }
   return(EMPTY_VALUE);
}

double iACMQL5(string symbol, ENUM_TIMEFRAMES tf, int shift)
{
   int handle = iAC(symbol, tf);
   if(handle < 0)
      return(-1);
   else
      return(CopyBufferMQL5(handle, 0, shift));
}

double iADMQL5(string symbol, ENUM_TIMEFRAMES tf, int shift)
{
   int handle = iAD(symbol, tf, VOLUME_TICK);
   if(handle < 0)
      return(-1);
   else
      return(CopyBufferMQL5(handle, 0, shift));
}

double iAlligatorMQL5(string symbol, ENUM_TIMEFRAMES tf, int jaw_period, int jaw_shift, int teeth_period, int teeth_shift, int lips_period, int lips_shift, ENUM_MA_METHOD method, ENUM_APPLIED_PRICE price, int mode, int shift)
{
   int handle = iAlligator(symbol, tf, jaw_period, jaw_shift, teeth_period, teeth_shift, lips_period, lips_shift, method, price);
   if(handle < 0)
      return(-1);
   else
      return(CopyBufferMQL5(handle, mode-1, shift));
}

double iADXMQL5(string symbol, ENUM_TIMEFRAMES tf, int period, ENUM_APPLIED_PRICE price, int mode, int shift)
{
   int handle = iADX(symbol, tf, period);
   if(handle < 0)
      return(-1);
   else
      return(CopyBufferMQL5(handle, mode, shift));
}

double iAOMQL5(string symbol, ENUM_TIMEFRAMES tf, int shift)
{
   int handle = iAO(symbol, tf);
   if(handle < 0)
      return(-1);
   else
      return(CopyBufferMQL5(handle, 0, shift));
}

double iATRMQL5(string symbol, ENUM_TIMEFRAMES tf, int period, int shift)
{
   int handle = iATR(symbol, tf, period);
  
 

Go to the opening { and control your code where is should be closed but the } is missing. If you click on the error message the cursor is immediately moved to the 'lonesome' {.

But maybe it is the last three lines?

 
  1. double iAOMQL5(string symbol, ENUM_TIMEFRAMES tf, int shift)
    {
       int handle = iAO(symbol, tf);
       if(handle < 0)
          return(-1);
       else
          return(CopyBufferMQL5(handle, 0, shift));

    Perhaps you should read the manual, especially the examples.
       How To Ask Questions The Smart Way. (2004)
          How To Interpret Answers.
             RTFM and STFW: How To Tell You've Seriously Screwed Up.

    They all (including iCustom) return a handle (an int). You get that in OnInit. In OnTick/OnCalculate (after the indicator has updated its buffers), you use the handle, shift and count to get the data.
              Technical Indicators - Reference on algorithmic/automated trading language for MetaTrader 5
              Timeseries and Indicators Access / CopyBuffer - Reference on algorithmic/automated trading language for MetaTrader 5
              How to start with MQL5 - General - MQL5 programming forum - Page 3 #22 (2020)
              How to start with MQL5 - MetaTrader 5 - General - MQL5 programming forum - Page 7 #61 (2020)
              MQL5 for Newbies: Guide to Using Technical Indicators in Expert Advisors - MQL5 Articles (2010)
              How to call indicators in MQL5 - MQL5 Articles (2010)

  2.         ticket = OrderSend(Symbol(), OP_BUY, 0.01, Ask, 0, Bid - StopLoss * _Point, Bid + TakeProfit * _Point, "Scalping EA", 0, 0, Green);
    

    That is MQL4 code.

  3. Stop using ChatGPT.
              Help needed to debug and fix an AI EA - Trading Systems - MQL5 programming forum (2023)

    ChatGPT (the worst), “Bots Builder”, “EA builder”, “EA Builder Pro”, EATree, “Etasoft forex generator”, “Forex Strategy Builder”, ForexEAdvisor (aka. ForexEAdvisor STRATEGY BUILDER, and Online Forex Expert Advisor Generator), ForexRobotAcademy.com, forexsb, “FX EA Builder”, fxDreema, Forex Generator, FxPro, Molanis, Octa-FX Meta Editor, Strategy Builder FX, Strategy Quant, “Visual Trader Studio”, “MQL5 Wizard”, etc., are all the same. You will get something quick, but then you will spend a much longer time trying to get it right, than if you learned the language up front, and then just wrote it.

    Since you haven't learned MQL4/5, therefor there is no common language for us to communicate. If we tell you what you need, you can't code it. If we give you the code, you don't know how to integrate it into yours.

    We are willing to HELP you when you post your attempt (using Code button) and state the nature of your problem, but we are not going to debug your hundreds of lines of code. You are essentially going to be on your own.

    ChatGPT
    1. Even it says do not use it for coding.*
    2. Mixing MT4 and MT5 code together.
    3. Creating multiple OnCalculate/OnTick functions.
    4. OnCalculate returning a double.
    5. Filling buffers with zero in OnInit (they have no size yet). Setting buffer elements to zero but not setting Empty Value to correspond.
    6. Calling undefined functions.
    7. Sometimes, not using strict (MT4 code).
    8. Code that will not compile.
    9. Creating code outside of functions.*
    10. Creating incomplete code.*
    11. Initialization of Global variables with non-constants.*
    12. Assigning a MT5 handle to a double or missing the buffer and bar indexes in a MT4 call.*
    13. Useing MT4 Trade Functions without first selecting an order.*
    14. Uses NULL in OrderSend.*
    bot builder Creating two OnInit() functions.*
    EA builder
    1. Counting up while closing multiple orders.
    2. Not useing time in new bar detection.
    3. Not adjusting for 4/5 digit brokers, TP/SL and slippage.*
    4. Not checking return codes.
    EATree Uses objects on chart to save values — not persistent storage (files or GV+Flush.) No recovery (crash/power failure.)
    ForexEAdvisor
    1. Non-updateing global variables.
    2. Compilation errors.
    3. Not checking return codes.*
    4. Not reporting errors.
    FX EA Builder
    1. Not checking return codes.
    2. Loosing open tickets on terminal restart. No recovery (crash/power failure.)
    3. Not adjusting stops for the spread .*
    4. Using OrdersTotal directly.

 

Thanks for your comments, there is some truth there.

I have used the ea builder to build and it works fine on my mt5 platform apart from showing errors in the journal when trying set SL or TP.


Now I tried to use chatGPT to convert 2 versions of this code into 1.

I noticed in the code functions were mixed with code written in MQL4. I am not an expert in this, I have a bit of experience

in PHP and HTML.

 I understand what say about calling functions that are undefined. Since time is of the essence to me

I would quickly either:

-Hire a developer from here to append the two EAs I created or I could

as well just post the reasonable looking versions from the EA builder.

I would be trying to achieve the following precisely:

-Merge the formulas in 1 ea with conditional logic to scan markets or loop over various currencies pairs

and only open a trade if conditions are met per currency pair.

-For some reason my broker deriv does not understand my SL and TP levels based on journal reports, nevertheless is set 

well and this EA makes consistent profits. I can imagine the problem is with the trailing stop, so the developer would

have to look via team viewer or anydesk why what the issue is.

-The EA is able to profit in a backtest dating from the 1996. The backtest show that the right trailing stop is being triggered. 

However on the live test on demo, there is some work to be done.



William Roeder #:
  1. Perhaps you should read the manual, especially the examples.
       How To Ask Questions The Smart Way. (2004)
          How To Interpret Answers.
             RTFM and STFW: How To Tell You've Seriously Screwed Up.

    They all (including iCustom) return a handle (an int). You get that in OnInit. In OnTick/OnCalculate (after the indicator has updated its buffers), you use the handle, shift and count to get the data.
              Technical Indicators - Reference on algorithmic/automated trading language for MetaTrader 5
              Timeseries and Indicators Access / CopyBuffer - Reference on algorithmic/automated trading language for MetaTrader 5
              How to start with MQL5 - General - MQL5 programming forum - Page 3 #22 (2020)
              How to start with MQL5 - MetaTrader 5 - General - MQL5 programming forum - Page 7 #61 (2020)
              MQL5 for Newbies: Guide to Using Technical Indicators in Expert Advisors - MQL5 Articles (2010)
              How to call indicators in MQL5 - MQL5 Articles (2010)

  2. That is MQL4 code.

  3. Stop using ChatGPT.
              Help needed to debug and fix an AI EA - Trading Systems - MQL5 programming forum (2023)

    ChatGPT (the worst), “Bots Builder”, “EA builder”, “EA Builder Pro”, EATree, “Etasoft forex generator”, “Forex Strategy Builder”, ForexEAdvisor (aka. ForexEAdvisor STRATEGY BUILDER, and Online Forex Expert Advisor Generator), ForexRobotAcademy.com, forexsb, “FX EA Builder”, fxDreema, Forex Generator, FxPro, Molanis, Octa-FX Meta Editor, Strategy Builder FX, Strategy Quant, “Visual Trader Studio”, “MQL5 Wizard”, etc., are all the same. You will get something quick, but then you will spend a much longer time trying to get it right, than if you learned the language up front, and then just wrote it.

    Since you haven't learned MQL4/5, therefor there is no common language for us to communicate. If we tell you what you need, you can't code it. If we give you the code, you don't know how to integrate it into yours.

    We are willing to HELP you when you post your attempt (using Code button) and state the nature of your problem, but we are not going to debug your hundreds of lines of code. You are essentially going to be on your own.

    ChatGPT
    1. Even it says do not use it for coding.*
    2. Mixing MT4 and MT5 code together.
    3. Creating multiple OnCalculate/OnTick functions.
    4. OnCalculate returning a double.
    5. Filling buffers with zero in OnInit (they have no size yet). Setting buffer elements to zero but not setting Empty Value to correspond.
    6. Calling undefined functions.
    7. Sometimes, not using strict (MT4 code).
    8. Code that will not compile.
    9. Creating code outside of functions.*
    10. Creating incomplete code.*
    11. Initialization of Global variables with non-constants.*
    12. Assigning a MT5 handle to a double or missing the buffer and bar indexes in a MT4 call.*
    13. Useing MT4 Trade Functions without first selecting an order.*
    14. Uses NULL in OrderSend.*
    bot builder Creating two OnInit() functions.*
    EA builder
    1. Counting up while closing multiple orders.
    2. Not useing time in new bar detection.
    3. Not adjusting for 4/5 digit brokers, TP/SL and slippage.*
    4. Not checking return codes.
    EATree Uses objects on chart to save values — not persistent storage (files or GV+Flush.) No recovery (crash/power failure.)
    ForexEAdvisor
    1. Non-updateing global variables.
    2. Compilation errors.
    3. Not checking return codes.*
    4. Not reporting errors.
    FX EA Builder
    1. Not checking return codes.
    2. Loosing open tickets on terminal restart. No recovery (crash/power failure.)
    3. Not adjusting stops for the spread .*
    4. Using OrdersTotal directly.

 
Henry Jove #: Now I tried to use chatGPT to convert 2 versions of this code into 1.

What part of “3. Stop using ChatGPT” was unclear and why?

What part of “Since you haven't learned MQL4/5, therefor there is no common language for us to communicate,” was unclear.
 
William Roeder #:

What part of “3. Stop using ChatGPT” was unclear and why?

What part of “Since you haven't learned MQL4/5, therefor there is no common language for us to communicate,” was unclear.

I am referring to what I did in the past. Not in the present. 

 
Henry Jove #:

I am referring to what I did in the past. Not in the present. 

I have learned MQL5 and I have fixed the issue. It's not rocket science !