Fixing AI-generated code

 

This is an experimental topic where you can legally ask for help with AI-generated code. If you create a separate topic asking for help with AI-generated code, such a topic may be deleted.

The purpose of creating this topic is to maintain order on the forum.

 
Use the CODE button (Alt-S) when inserting code.

A moderator corrected the formatting this time. Please format code properly in future; posts with improperly formatted code may be removed.

EA compile error: undeclared identifier idx and some operator expected at line 16

Message: Hello everyone, I’m building a modular EA with multiple safeguard stages (Stage 2: Spread filter, Stage 3: Volatility check, Stage 5: Multi‑trade management).

When I compile, I keep getting these errors:

  • undeclared identifier idx (line 16)

  • 'idx' - some operator expected (line 16)

I’ve tried both loop forms:

for(int idx = 0; idx < totalTrades; idx++)

and

int idx;
for(idx = 0; idx < totalTrades; idx++)

but the errors persist.

Here’s the relevant Stage 5 code block:

bool Stage5_MultiTradeOK()
  {
   int totalTrades = PositionsTotal();
   double totalLots = 0.0;
   int symbolTrades = 0;
   int idx;
   for(idx = 0; idx < totalTrades; idx++)
     {
      if(PositionSelectByIndex(idx))
        {
         string sym = PositionGetString(POSITION_SYMBOL);
         if(sym == _Symbol)
            symbolTrades++;
         totalLots += PositionGetDouble(POSITION_VOLUME);
        }
     }
   AuditLog("Stage5", "Multi-trade check passed");
   return(true);
  }

I suspect the issue is upstream (Stage 2 or Stage 3 not closing properly, or a malformed AuditLog line), but I can’t spot it.

👉 Could someone please review and point out why the compiler still throws these errors, even though idx is declared?

Thanks in advance!

 
221062 #:
Those errors are caused by the fact that the PositionSelectByIndex() function does not exist - it is an AI hallucination.
 
this thread will be full of AI hallucinations :-)
 
Conor Mcnamara #:
this thread will be full of AI hallucinations :-)
Apparently, that's the idea of this thread--to contain the acid trip.
 
Ryan L Johnson #:
Apparently, that's the idea of this thread--to contain the acid trip.
A thread where 30 second fixable problems become 5 hour problems cause AI is the hot shit now. 😎
 
Conor Mcnamara #:
A thread where 30 second fixable problems become 5 hour problems cause AI is the hot shit now. 😎
Eeeuw... acid trip in a dog park. 😷