Some functions returning zero

 

Is it true that functions like iRSI returns 0 (zero) if you haven’t yet open that symbol in the graph window or downloaded its historical data?

In the next simplified code theRsi returns 0 for some symbol/timeframe combinations.

Is there a way to avoid this?


string theSymbol = "";
int theTimeframe = 0;
double theRsi = 0.0;

string SYMBOLS[] = {"AUDCAD", "AUDCHF", "AUDJPY", "AUDNZD", "AUDUSD"};

ENUM_TIMEFRAMES TIMEFRAMES[] = {PERIOD_M15, PERIOD_M30, PERIOD_H1};
                                                                        
int TOTAL_SYMBOLS = ArraySize(SYMBOLS);
int TOTAL_TIMEFRAMES = ArraySize(TIMEFRAMES);

for (int posSymbol = 0; posSymbol < TOTAL_SYMBOLS; posSymbol++) {       
        theSymbol = SYMBOLS[posSymbol];         
        
        for (int posTimeframe = 0; posTimeframe < TOTAL_TIMEFRAMES; posTimeframe++) {   
                theTimeframe = TIMEFRAMES[posTimeframe];                                        
                                
                theRsi = iRSI(theSymbol, theTimeframe, 14, PRICE_CLOSE, 1);     
                Print(theRsi);
        }
}
 
They return zero because of 4066/4073.

On MT4: Unless the current chart is that specific pair/TF referenced, you must handle 4066/4073 errors.
          Download history in MQL4 EA - MQL4 and MetaTrader 4 - MQL4 programming forum

Reason: