If we want to check several timeframes, it would be obviously a lot of work to create a separate module for each time frame so we want our module to handle all the time frames and we don’t want to recode it every time. And, we want people to be able to change the time frame in the expert advisor properties.


Please hit the F4 key to bring up Meta Editor and remove every occurrence of the time frame value. So now, we would call our module CheckAnyTrend. And we would now declare a variable called extern double TrendFrame with the value of 10080. If you mark the word extern, and hit the F1 key, you will see in the MQL4 reference that external variables are available from the properties window.


In the OnTick function, we want to call the CheckTrend function and handover the value TrendFrame to calculate the trend. Now, I open the CheckTrend MQ4 file and save it with the name CheckAnyTrend.MQ4. Right here, within the round brackets, it will receive the double value TrendFrame and it will now use the value TrendFrame to calculate the trend.


So we have no fixed numbers anymore and now, we would be able to use our module for each and every time frame. Don’t forget to save it, and I will also give the main expert advisor a new name. The compilation succeeded but we got warnings. The reason is: The iMA function expects an integer for the time frame and we have used the double value.
We are going to fix this in the next part. For now, hit the F4 key, select the new expert advisor and hit the Start button. Okay it works. In fact, the double value is more accurate than an integer value. This is the reason it says it’s a possible loss and it’s a warning so you should correct it, but you don’t absolutely have to, everything you absolutely have to correct would have created an error over here.

Trading Tutorial Automation was found for: