Help - issue in the code

 

I need help in this case: ERROR: '-' - open parenthesis expected  73: 43

{
   // Calcular médias móveis
   int limit = MathMin(rates_total, (Bars - prev_calculated));
   if (limit <= 0)
      return (0);

   for (int i = prev_calculated; i < limit; i++)
   {
      EMA9Buffer[i] = iMA(_Symbol, 0, EMA9_Period, 0, EMA_Method, i);
      EMA21Buffer[i] = iMA(_Symbol, 0, EMA21_Period, 0, EMA_Method, i);
      EMA50Buffer[i] = iMA(_Symbol, 0, EMA50_Period, 0, EMA_Method, i);
      EMA200Buffer[i] = iMA(_Symbol, 0, EMA200_Period, 0, EMA_Method, i);
   } 

Improperly formatted code edited.

 
Your topic has been moved to the section: Technical Indicators
Please consider which section is most appropriate — https://www.mql5.com/en/forum/172166/page6#comment_49114893
 

Please always use the CODE button (Alt-S) when inserting code.

Code button in editor

 

Unlike in MQL4, in MQL5 there is no predefined variable called "Bars". There is however a function called "Bars()".

Also, unlike MQL4, in MQL5, the indicator functions like iMA() return handles and not the data directly, and you have to use CopyBuffer() instead to get the data

Is this ChatGPT generated code?

ChatGPT (or other A.I.) generates horrible code, mixing MQL4 and MQL5. So, if it is the case, then please use the Freelance section for such requests — https://www.mql5.com/en/job

Documentation on MQL5: Timeseries and Indicators Access / Bars
Documentation on MQL5: Timeseries and Indicators Access / Bars
  • www.mql5.com
Bars - Timeseries and Indicators Access - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
 int limit = MathMin(rates_total, (Bars(Symbol(), Period()) - prev_calculated));

or else

 int limit = MathMin(rates_total, (rates_total - prev_calculated));


Fernando Carreiro #:
ChatGPT (or other A.I.) generates horrible code, mixing MQL4 and MQL5.

I had a test, and this is true. It's strange

 
phade #:

or else

int limit = MathMin(rates_total, (rates_total - prev_calculated));

This could be simplified more:

int limit = rates_total - prev_calculated;

But that doesn't make sense because what follows is this:

if (limit <= 0)
   return (0); // The next time OnCalculate is called, prev_calculated will be 0

Actually, nothing good should be expected from the generated code😄