I have a bunch of csv files saved in MQL5/Files and a function that reads (for now only) one csv into an array called `output_arr[]`. The function prototype is:
E.g. by providing `ticker="AAPL"` and `column="close"`, it will fill `output_arr[]` with all the close prices for Apple stock:
Now, my plan is to take output_arr[] (i.e. an array of doubles with close, open, high, low ... prices, or volume) and calculate the Relative Strength Index on that array. Apart from the RSI, I plan to repeat this process on some other indicators as well, both indicators found in the code base and indicators available online in .mq5 format.
I'm aware that in MQL4 there existed some of i...OnArray() functions and in MQL5 these were removed. I found the Migrating from MQL4 to MQL5 article which has empty cells for these i...OnArray() functions, but the Russian version of the same article actually contains something useful: these cells redirect to this article on Applying One Indicator to Another.
I also found some older forum posts, such as this one from 2017, asking a very similar question as mine. Both the article linked above, and a reply in the forum thread recommended using the OnCalculate() function:
"The parameter price can be specified in indicator's settings dialog as a custom array from other indicator." - quote by Stanislav Korotky on August 20, 2017.
However, if I understand everything correctly, this method is not exactly applicable to my needs, since I need an EA (and not a new indicator file) to do IO operations and calculate RSI values (breaking it down: (1) read csv and load it into an array, (2) calculate RSI on array, (3) save calculated RSI values to a new csv). I haven't found more specific articles or forum posts that would suit my need, and I'm right now a bit confused as to how even a simple EA calculating RSI on a single array could be implemented.
Could someone please point me in the right direction, either with a relevant article or a sample code?
Inserted Code
void ReadCsvData(double &output_arr[], string ticker, string column="close")
Inserted Code
int OnInit() { double output_arr[]; ReadCsvData(output_arr, "AAPL", "close"); // safety check: print first 10 values to Expert Log for(int i=0; i<10; i++) { Print(i," ", DoubleToString(output_arr[i],2)); } return(INIT_SUCCEEDED); }
I'm aware that in MQL4 there existed some of i...OnArray() functions and in MQL5 these were removed. I found the Migrating from MQL4 to MQL5 article which has empty cells for these i...OnArray() functions, but the Russian version of the same article actually contains something useful: these cells redirect to this article on Applying One Indicator to Another.
I also found some older forum posts, such as this one from 2017, asking a very similar question as mine. Both the article linked above, and a reply in the forum thread recommended using the OnCalculate() function:
Inserted Code
int OnCalculate(const int rates_total, // size of the price[] array const int prev_calculated, // bars handled on a previous call const int begin, // where the significant data start from const double& price[] // array to calculate );
"The parameter price can be specified in indicator's settings dialog as a custom array from other indicator." - quote by Stanislav Korotky on August 20, 2017.
However, if I understand everything correctly, this method is not exactly applicable to my needs, since I need an EA (and not a new indicator file) to do IO operations and calculate RSI values (breaking it down: (1) read csv and load it into an array, (2) calculate RSI on array, (3) save calculated RSI values to a new csv). I haven't found more specific articles or forum posts that would suit my need, and I'm right now a bit confused as to how even a simple EA calculating RSI on a single array could be implemented.
Could someone please point me in the right direction, either with a relevant article or a sample code?