One of the errors that you may encounter while using MetaTrader 5 is Error 4302 - 'cannot load custom indicator'. This guide describes the reason which may cause such an error as well as possible ways to fix it.
What does Error 4302 mean?
As evident from the error message, Error 4302 happens when the MetaTrader 5 platform cannot load a custom indicator, though it does not tell us why this has happened. The description of the error on the MQL5 site states that 'Symbol is not selected in MarketWatch.' Usually, this error occurs when a script, an expert advisor, or an indicator tries to call the iCustom() function for the symbol that was not added to the Market Watch window.
Let us look at an example to better understand how this error can happen. In this example, we created a simple custom indicator, named TestIndicator using the default program code that MetaEditor puts when you create a new indicator. Then, we created a simple script that uses the iCustom() function to call the custom indicator and return its handle as a result.
void OnStart() { string symbol = "EURUSD"; // Replace with the symbol you removed ENUM_TIMEFRAMES timeframe = PERIOD_M1; // 1-minute timeframe // Attempt to call the custom indicator int handle = iCustom(symbol, timeframe, "TestIndicator"); if (handle == INVALID_HANDLE) { int error_code = GetLastError(); Print("Error Code: ", error_code); } else { Print("Custom indicator handle for ", symbol, " is ", handle); } }
As you can see, the script calls the indicator specifically for the EUR/USD symbol. If the symbol is present in the Market Watch window, the script runs without a hitch, returning the indicator's handle.
However, if we remove EUR/USD from the Market Watch window, Error 4302 will be displayed in the Experts tab of the MetaTrader 5 terminal. Additionally, the script is set up to show the error code if it is unable to return a proper handle, and it confirms that the error code, in this case, is 4302.
How to fix Error 4302?
Add the symbol to the Market Watch window
One of the most straightforward solutions for Error 4302 is to add the required symbol to the Market Watch window. The problem here is that you might not know what symbol you need to add. And reading the code to learn that can be difficult, especially if you are unfamiliar with programming.
Change the symbol in the code
Another solution is to change the symbol for which the script, the EA, or the indicator calls the iCustom() function. Obviously, this solution is even more difficult than the previous one, particularly for traders who lack programming skills.
Do not specify the symbol in the iCustom() function
For those who are coding their own EAs and indicators or for those who are willing to dive into the code of the EA or indicator that is not working the best solution is not to specify the symbol in the iCustom() function. Instead, use the NULL
or Symbol()
parameter in the place where the function asks for the symbol. This will call the function for the currently selected symbol.
Conclusion
Error 4302 occurs when a script, an expert advisor, or an indicator calls the iCustom() function for a symbol that is not currently added to the Market Watch window.
The best way to avoid the error is to avoid calling the function for a specific symbol when writing a program code. If you encountered the error using the existing indicator or EA, you can fix the error by adding the required symbol to the Market Watch window or by modifying the EA's code. Or you can simply choose a better-written EA.