Please consider which section is most appropriate — https://www.mql5.com/en/forum/172166/page6#comment_49114893
There is insufficient information to provide a useful answer. All we can say is that the OnInit() probably failed or returned an invalid return code.
Are you able to show the code for your OnInit() function?
There is insufficient information to provide a useful answer. All we can say is that the OnInit() probably failed or returned an invalid return code.
Are you able to show the code for your OnInit() function?
//+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { // Initialize testing status and initial trade flag g_initial_trade_placed = false; g_is_testing = IsTesting(); g_initialization_error = false; if(BB_Period <= 0 || BB_Deviation <= 0) { Print("Invalid Bollinger Bands parameters"); return INIT_PARAMETERS_INCORRECT; } // Initialize global variables with safety checks g_digits = (int)MarketInfo(Symbol(), MODE_DIGITS); if(g_digits == 0) g_digits = 5; // Safe default g_point = MarketInfo(Symbol(), MODE_POINT); if(g_point == 0) g_point = 0.0001; // Safe default g_min_lot = MarketInfo(Symbol(), MODE_MINLOT); if(g_min_lot == 0) g_min_lot = 0.01; // Safe default g_max_lot = MarketInfo(Symbol(), MODE_MAXLOT); if(g_max_lot == 0) g_max_lot = 100.0; // Safe default g_lot_step = MarketInfo(Symbol(), MODE_LOTSTEP); if(g_lot_step == 0) g_lot_step = 0.01; // Safe default // Validate lot size inputs if(Fixed_Lot_Size < g_min_lot || Fixed_Lot_Size > g_max_lot) { Print("Fixed lot size must be between ", g_min_lot, " and ", g_max_lot); return INIT_PARAMETERS_INCORRECT; } if(Max_Lot_Size < Fixed_Lot_Size || Max_Lot_Size > g_max_lot) { Print("Max lot size must be between fixed lot size and ", g_max_lot); return INIT_PARAMETERS_INCORRECT; } // Get broker's stop level with safety checks g_stops_level = (int)MarketInfo(Symbol(), MODE_STOPLEVEL); if(g_stops_level == 0) g_stops_level = (int)MarketInfo(Symbol(), MODE_FREEZELEVEL); if(g_stops_level == 0) g_stops_level = 10; // Default safety value if(Use_Fixed_SLTP) { if(Fixed_SL_Points < g_stops_level || Fixed_TP_Points < g_stops_level) { Print("Fixed SL/TP must be greater than broker's stop level (", g_stops_level, " points)"); return INIT_PARAMETERS_INCORRECT; } } // Validate minimum balance if(AccountBalance() < Min_Account_Balance) { Print("Account balance (", AccountBalance(), ") is below minimum required (", Min_Account_Balance, ")"); return INIT_PARAMETERS_INCORRECT; } Print("Bollinger Bands Grid Strategy initialized successfully"); return INIT_SUCCEEDED; }
You should not read any market or symbol information during the initialisation phase. It may fail.
Instead read it after the first tick has arrived. Don't make it part of your OnInit() handling. Initialisation should be strictly about preparing the initial conditions, and parameter validity, irrespective of contract specifications.
Also, make sure that the initial default values for the parameters are valid for all possible symbols (or least most of them).
You should not read any market or symbol information during the initialisation phase. It may fail.
Instead read it after the first tick has arrived. Don't make it part of your OnInit() handling. Initialisation should be strictly about preparing the initial conditions, and parameter validity, irrespective of contract specifications.
Also, make sure that the initial default values for the parameters are valid for all possible symbols (or least most of them).
Thanks a lot, ill implement your suggestions :)
You should not read any market or symbol information during the initialisation phase. It may fail.
Instead read it after the first tick has arrived. Don't make it part of your OnInit() handling. Initialisation should be strictly about preparing the initial conditions, and parameter validity, irrespective of contract specifications.
Also, make sure that the initial default values for the parameters are valid for all possible symbols (or least most of them).
Wow! It worked :)
Thanks a lot

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I hope this message finds you well. I am currently facing an issue with an expert advisor on MetaTrader 4, and I would greatly appreciate your assistance in resolving it.
The error I am encountering is "Initialization failed (32767)". I’ve checked the code and attempted a few common troubleshooting steps, but the issue persists.
Could you please guide me on how to identify the cause of this error and find a suitable solution? Any insights or suggestions would be highly appreciated.
Looking forward to your help!