Download MetaTrader 5

Custom Indicators & Timeframes

To add comments, please log in or register
Geester
155
Geester  

Hi there,

I'd like to create an indicator that runs on a different timeframe to the chart on which it is applied. This is so I can compare certain results from a slower timeframe against those of the primary chart's timeframe.

The indicator I have in mind (an indicator version of an EA I have created) processes its results at the Close of the current bar. Therefore, the tick data coming into the indicator must be based on whatever timeframe I want to see. For example, my chart is M5 and I'd like to see results based on M15 in the indicator.

When you use OnTick (or I assume OnCalculate), you get tick data based on the "current" timeframe. It's this aspect that I find confusing. How do I get tick data from a different timeframe to a second (or subsequent) indicator on the same chart?

Many thanks indeed :)

Fernando Carreiro
3951
Fernando Carreiro  

Geester: I'd like to create an indicator that runs on a different timeframe to the chart on which it is applied. This is so I can compare certain results from a slower timeframe against those of the primary chart's timeframe.

The indicator I have in mind (an indicator version of an EA I have created) processes its results at the Close of the current bar. Therefore, the tick data coming into the indicator must be based on whatever timeframe I want to see. For example, my chart is M5 and I'd like to see results based on M15 in the indicator.

When you use OnTick (or I assume OnCalculate), you get tick data based on the "current" timeframe. It's this aspect that I find confusing. How do I get tick data from a different timeframe to a second (or subsequent) indicator on the same chart?

For Indicators, one uses the OnCalculate() event handler and not OnTick() which is for EAs.

From your description you want to handle OHLC Bar data (not tick data). Tick data is not based on any time-frame, irrespective of it being used on a M1, H1 or D1 chart (or any other).

To obtain bar data of the other time-frames, use the appropriate functions: https://docs.mql4.com/series

However, you will need to handle 4066 and 4073 errors due to the delays in obtaining the data as the terminal downloads it for you.

Timeseries and Indicators Access - MQL4 Reference
Timeseries and Indicators Access - MQL4 Reference
  • docs.mql4.com
These are functions for working with timeseries and indicators. A timeseries differs from the usual data array by its reverse ordering - elements of timeseries are indexed from the end of an array to its begin (from the most recent data to the oldest ones). To copy the time-series values and indicator data, it's recommended to use dynamic...
Geester
155
Geester  
Fernando Carreiro:

For Indicators, one uses the OnCalculate() event handler and not OnTick() which is for EAs.

From your description you want to handle OHLC Bar data (not tick data). Tick data is not based on any time-frame, irrespective of it being used on a M1, H1 or D1 chart (or any other).

To obtain bar data of the other time-frames, use the appropriate functions: https://docs.mql4.com/series

However, you will need to handle 4066 and 4073 errors due to the delays in obtaining the data as the terminal downloads it for you.


Hi @Fernando Carreiro - many thanks for replying. Yes, you are right, I only want OHLC bar data. In summary, I think that I will need to get the values from the iHigh/iLow/iClose/iOpen functions, as opposed to using the default timeframe data from the same named arrays High[],Low[] etc?

With regard to the errors you mentioned, are you saying that if I reference a value from one of the iHigh/iLow/iClose/iOpen functions, I will need to test for the error numbers you have mentioned?

I feel I might be missing something so if I am, please advise. Thank you once again.

whroeder1
17050
whroeder1  
  1. Geester: , I will need to test for the error numbers you have mentioned?
    On MT4: Unless the current chart is the specific pair/TF referenced, you must handle 4066/4073 errors.
              Download history in MQL4 EA - MQL4 and MetaTrader 4 - MQL4 programming forum

  2. Remember, don't mix apples and oranges.
Fernando Carreiro
3951
Fernando Carreiro  

Geester: Hi @Fernando Carreiro - many thanks for replying. Yes, you are right, I only want OHLC bar data. In summary, I think that I will need to get the values from the iHigh/iLow/iClose/iOpen functions, as opposed to using the default timeframe data from the same named arrays High[],Low[] etc?

With regard to the errors you mentioned, are you saying that if I reference a value from one of the iHigh/iLow/iClose/iOpen functions, I will need to test for the error numbers you have mentioned?

I feel I might be missing something so if I am, please advise. Thank you once again.

Yes, that is correct - you need to check for the errors, but there are several alternatives to the iHigh/iLow/iClose/iOpen. See the link I provided in my previous post!
Geester
155
Geester  
whroeder1:
  1. On MT4: Unless the current chart is the specific pair/TF referenced, you must handle 4066/4073 errors.
              Download history in MQL4 EA - MQL4 and MetaTrader 4 - MQL4 programming forum

  2. Remember, don't mix apples and oranges.

Thanks for the links and advice @whroeder1 - much appreciated as always :)


Geester
155
Geester  
Fernando Carreiro:
Yes, that is correct - you need to check for the errors, but there are several alternatives to the iHigh/iLow/iClose/iOpen. See the link I provided in my previous post!

Thank you, @Fernando Carreiro - much clearer now!


To add comments, please log in or register