'{' - function definition unexpected - I can really use some assistance in this, please!

 

Hi, I get an error: '{' - function definition unexpected

datetime currentDay = TimeCurrent();
   {
   if (currentDay != lastDay)
   
      // Update maximum drawdown if necessary
   } 

I have no clue what I am doing wrong, it's about the first bracket that the system just does not want to do. Please help. 

 

Your code is incomplete. Please show all relevant code when asking for help with your code.

Also please use the CODE button (Alt-S) when inserting code.

Code button in editor

 
 // Expert Advisor properties
#property strict

// Global variables
double maxDrawdown = 0;
double dailyDrawdown = 0;
datetime lastDay = 0;
int drawdownLabel;

// Expert Advisor initialization function
int OnInit()
{
   // Create drawdown label on chart
   drawdownLabel = ObjectCreate(0, "DrawdownLabel", OBJ_LABEL, 0, 0, 0);
   ObjectSetInteger(0, "DrawdownLabel", OBJPROP_CORNER, CORNER_LEFT_UPPER);
   ObjectSetInteger(0, "DrawdownLabel", OBJPROP_XDISTANCE, 10);
   ObjectSetInteger(0, "DrawdownLabel", OBJPROP_YDISTANCE, 20);
   ObjectSetInteger(0, "DrawdownLabel", OBJPROP_FONTSIZE, 10);
   ObjectSetString(0, "DrawdownLabel", OBJPROP_FONT, "Arial");
   ObjectSetInteger(0, "DrawdownLabel", OBJPROP_COLOR, clrRed);
   
   return(INIT_SUCCEEDED);
}

// Expert Advisor deinitialization function
void OnDeinit(const int reason)
{
   // Remove drawdown label from the chart
   ObjectDelete(0, "DrawdownLabel");
}

// Expert Advisor tick processing function
void OnTick()
{}


datetime currentDay = TimeCurrent();
   {
   if (currentDay != lastDay)
   
      // New day, update daily drawdown and display on chart

      // Calculate equity change for the current day
      double equityChange = AccountInfoDouble(ACCOUNT_EQUITY) - AccountInfoDouble(ACCOUNT_EQUITY_PREVIOUS);

      // Calculate daily drawdown
      dailyDrawdown = MathMax(dailyDrawdown + equityChange, 0);

      // Update maximum drawdown if necessary
   }

This is the whole code :)

 
rikt132 #: This is the whole code :)

The code has too many issues. Was this generated by ChatGPT? It seems like it!

 
Fernando Carreiro #:

The code has too many issues. Was this generated by ChatGPT? It seems like it!

I tried to do ChatGPT since I was looking for a simple drawdown code. However, I could not find it anywhere. The code should include that if on a day the max DD was -800 it shows somewhere that it was -800. And if in a next few days the max losses were -1600, it shows that it was -1600. It's actually the same as FTMO (Max dailydrawdown) to see if you almost reached your peak. Do you have any idea's on this? 
 
rikt132 #: I tried to do ChatGPT since I was looking for a simple drawdown code. However, I could not find it anywhere. The code should include that if on a day the max DD was -800 it shows somewhere that it was -800. And if in a next few days the max losses were -1600, it shows that it was -1600. It's actually the same as FTMO (Max dailydrawdown) to see if you almost reached your peak. Do you have any idea's on this? 

The code is a mess. Please stop using ChatGPT.

We cannot help you if you have no knowledge or understanding of how to code.

Either you take the time to learn to code (which will take a long time) or you hire someone to code it for you.

 
rikt132 #: I tried to do ChatGPT

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

If you don't learn MQL4/5, 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 your code.

 
Okay, thank you for your help and feedback!