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!
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
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.