How to code a script to call multiple indicators for multiple time periods

 

Hi,

I'd like to ask a question about a MQL4 programming paradigm.

I want to execute 3 indicators on a collection of charts in real time, and allow the processing to continue while the markets are open 24/5.

The collection is made up of 200 different symbols I am watching. However, I want to run the indicators

on several time intervals, such as 1-minute, 5M, 15M and 30M.

To keep bandwidth usage as low as possible, ideally the code should download the 1-minute chart data and then using a period converter (along the lines of this one: Period Converter Optimized - MQL4 Code Base) create the charts for the other time intervals offline so as not to have to download them.

I am trying to work out the most efficient way to do this.

I don't know whether this would work in a script or indicator, but let's assume it's a script for the purpose of explanation.

Here are the execution steps I had in mind:

1. Read in the list of symbols to process from a text file (as the AllMarketData script does).

2. Read the time intervals to monitor, from the script settings.

3. Read the indicators to run on each chart (these should be easily changeable).

Repeat for all symbols, every minute

4. Download 1-minute chart data for symbol.

5. Create charts for each interval set in (2), for this symbol

6. Run indicators, as set in (3) on each chart.

Until Action to Terminate.

What I need help with is to understand if my approach is reasonable. For example, how do others approach such a problem?

The script would run once, but would initiate indicators for processing on each chart. Would they stop when the script stops, or what action to terminate would be neededto stop them running? Would they run 25/5 if started once from the script?

Is it necessary to have the 1-minute chart open for every symbol that I want to monitor, or can this be done without having the relevant charts open in Metatrader 4?

At the moment I don't need an EA, as no automated trading will be executed, I only need the monitoring by the indicators.

I would greatly appreciate any help or ideas!

Regards,

Timo.

 
timotrade:
Hi,

I'd like to ask a question about a MQL4 programming paradigm.

I want to execute 3 indicators on a collection of charts in real time, and allow the processing to continue while the markets are open 24/5.

The collection is made up of 200 different symbols I am watching. However, I want to run the indicators

on several time intervals, such as 1-minute, 5M, 15M and 30M.

To keep bandwidth usage as low as possible, ideally the code should download the 1-minute chart data and then using a period converter (along the lines of this one: Period Converter Optimized - MQL4 Code Base) create the charts for the other time intervals offline so as not to have to download them.

I am trying to work out the most efficient way to do this.

I don't know whether this would work in a script or indicator, but let's assume it's a script for the purpose of explanation.

Here are the execution steps I had in mind:

1. Read in the list of symbols to process from a text file (as the AllMarketData script does).

2. Read the time intervals to monitor, from the script settings.

3. Read the indicators to run on each chart (these should be easily changeable).

Repeat for all symbols, every minute

4. Download 1-minute chart data for symbol.

5. Create charts for each interval set in (2), for this symbol

6. Run indicators, as set in (3) on each chart.

Until Action to Terminate.

What I need help with is to understand if my approach is reasonable. For example, how do others approach such a problem?

The script would run once, but would initiate indicators for processing on each chart. Would they stop when the script stops, or what action to terminate would be neededto stop them running? Would they run 25/5 if started once from the script?

Is it necessary to have the 1-minute chart open for every symbol that I want to monitor, or can this be done without having the relevant charts open in Metatrader 4?

At the moment I don't need an EA, as no automated trading will be executed, I only need the monitoring by the indicators.

I would greatly appreciate any help or ideas!

Regards,

Timo.

Timo

You can start by taking a look at this thread : https://www.mql5.com/en/forum/173108 (if you are planning to use custom indicators).

For calling built in indicators you even do not need icustom() calls : simply specify the desired symbol and the time frame the parameters of the function and you can call it for as much symbols and/or time frames as you wish

To get the list of symbols available by your broker you can use something like in this simple indicator : https://www.mql5.com/en/forum/173060/page102________________________

PS : it is not a good idea to convert 1 minute data to other time frames. It will take too much processing time compared to using native desired time frame data. But using 200 symbols / time frames from n MQL code is close to impossible mission (mql is not known for its speed of execution and eficiency) Better to forget the target of 200

 

Hi Mladen,

Many thanks for the reply and information, in particular the link to the symbols indicator which is really useful.

I intend to use iCustom() to call the indicators.

The stumbling block for me is the overall design. For example, I now assume I should write an indicator that calls the other three indicators in a loop, and attach the main indicator to a chart.

However, here is the design issue:

If inside the Main indicator A, I want to do this:

For each symbol sym

iCustom(sym,PERIOD_M5,my_indicator_1,5,1,0)

iCustom(sym,PERIOD_M5,my_indicator_2,5,1,0)

iCustom(sym,PERIOD_M5,my_indicator_3,5,1,0)

end for

This seems to present 2 issues:

- if my_indicator_1 also contains a loop that keeps the indicator running indefinitely, will the call to my_indicator_2 and my_indicator_3 ever be made?

- if, on the other hand, the call to my_indicator_1 is designed to quit after one execution (like a script) and the calls to my_indicator_2 andmy_indicator_3 are made in quick succession, will all the bars need to be downloaded for each indicator call? Would it be better to find a way to keep all three indicators running indefinitely at the same time so only new bars are processed, using IndicatorCounted() ?

Thanks again,

Regards,

Timo.

 
timotrade:
Hi Mladen,

Thanks for the reply and information, in particular the link to the symbols indicator.

I intend to use iCustom() to call the indicators.

The stumbling block for me is the overall design. For example, I now assume I should write an indicator that calls the other three indicators in a loop, and attach the main indicator to a chart.

However, here is the design issue:

If inside the Main indicator A, I want to do this:

For each symbol sym

iCustom(sym,PERIOD_M5,my_indicator_1,5,1,0)

iCustom(sym,PERIOD_M5,my_indicator_1,5,1,0)

iCustom(sym,PERIOD_M5,my_indicator_1,5,1,0)

I think that another thread that might be of use to you is this one : https://www.mql5.com/en/forum/178256

The indicator from that thread does something very similar to what your are intending to do so you could use it as a kind of a template

 

Thanks Mladen, I'll check it out. I updated my previous post as I posted too early!

 
timotrade:
Hi Mladen,

Many thanks for the reply and information, in particular the link to the symbols indicator which is really useful.

I intend to use iCustom() to call the indicators.

The stumbling block for me is the overall design. For example, I now assume I should write an indicator that calls the other three indicators in a loop, and attach the main indicator to a chart.

However, here is the design issue:

If inside the Main indicator A, I want to do this:

For each symbol sym

iCustom(sym,PERIOD_M5,my_indicator_1,5,1,0)

iCustom(sym,PERIOD_M5,my_indicator_2,5,1,0)

iCustom(sym,PERIOD_M5,my_indicator_3,5,1,0)

end for

This seems to present 2 issues:

- if my_indicator_1 also contains a loop that keeps the indicator running indefinitely, will the call to my_indicator_2 and my_indicator_3 ever be made?

- if, on the other hand, the call to my_indicator_1 is designed to quit after one execution (like a script) and the calls tomy_indicator_2 andmy_indicator_3 are madein quick succession, will all the bars need to be downloaded for each indicator call? Would it be better to find a way to keep all three indicators running indefinitely at the same time so only new bars are processed, using IndicatorCounted() ?

Thanks again,

Regards,

Timo.

Timo

If your indicator contains a code that keep the indicator to loop indefinitely then your terminal will crash. So, if your indicator is running normally that is not an indefinite loop and you should not worry about it

 

Hi Mladen,

With the help of the indicators you mentioned I was able to out together the indicator I needed, thank you.

Basically, one indicator calls another indicator using iCustom, for each symbol that I wish to process.

The one issue that I could not solve is that the indicator called with iCustom uses a DLL library, and therefore I need to "Allow DLL Imports". Do you know how I could do this when calling it with iCustom? It works fine when I attach it manually to one chart at a time.

Under MT4 Tools -> Options -> Expert Advisors, I've checked "Allow DLL Imports" but it doesn't solve the issue.

If you could point me in the right direction, I would really appreciate it. Thanks alot in advance.

 
timotrade:
Hi Mladen,

With the help of the indicators you mentioned I was able to out together the indicator I needed, thank you.

Basically, one indicator calls another indicator using iCustom, for each symbol that I wish to process.

The one issue that I could not solve is that the indicator called with iCustom uses a DLL library, and therefore I need to "Allow DLL Imports". Do you know how I could do this when calling it with iCustom? It works fine when I attach it manually to one chart at a time.

Under MT4 Tools -> Options -> Expert Advisors, I've checked "Allow DLL Imports" but it doesn't solve the issue.

If you could point me in the right direction, I would really appreciate it. Thanks alot in advance.

timotrade

Simply enable dll imports in the calling indicator, script or EA

 

Thanks for your comment. As I had already followed your suggestion, it made me realize that I should be looking elsewhere for the source of the problem. As it turns out, the issue was with file permissions. Problem solved!

Thanks again for your help.

Reason: