How to put the indicator code into a loop to check all market watch symbols?

Hi everybody,
I have an indicator code which is able to identify the buy signal.
I’m trying to put it’s code into a for loop to check all market watch symbols accordingly and print the symbols which are at the buy signal status.

I used ChatGPT 4 to get the following and it is untested but it may give you a start:
//======start ChatGPT4
To achieve this, you will have to modify your current code slightly to work with different symbols. Once your indicator is adjusted to take a symbol as an input, you can use a for loop to iterate over all symbols in the Market Watch window and apply your indicator to each symbol.

Here is a basic example of how you can modify your current code to iterate over all the symbols in the Market Watch window:

mql4Copy code

#include <Trade\SymbolInfo.mqh> // include this to work with symbols
CSymbolInfo symbol_info; 

void OnStart()
    int total_symbols = SymbolsTotal(true); // get total number of symbols in the Market Watch
    for(int i = 0; i < total_symbols; i++)
        string symbol_name = SymbolName(i, true); // get the name of the symbol at the current index
        if(CheckBuySignal(symbol_name)) // check if the buy signal is true for this symbol
            Print(symbol_name + " has a buy signal.");

bool CheckBuySignal(string symbol)
    // Implement your indicator logic here
    // For instance, you could have an RSI-based logic as follows:
    double rsi = iRSI(symbol, PERIOD_H1, 14, PRICE_CLOSE, 0); // Calculation of RSI for given symbol
    if (rsi < 30) // RSI<30 often considered as a buy signal (oversold condition)
        return true;
    return false;

Please replace the CheckBuySignal() function with your indicator code. The function should take a symbol as an argument and return true if a buy signal is present and false otherwise.

This code assumes that a buy signal can be determined by a single call to the CheckBuySignal() function, without considering the past states. If your indicator requires considering past states, the code would be a bit more complex.

Remember to allow DLL imports and also, consider that too many frequent or complex operations might lead to slowing down or overloading of the MT4 client due to resource usage.

I strongly suggest that you test this code on a demo account first before deploying it on a live trading account. It’s important to make sure the indicator signals are accurate and reliable.