Quantitative research in MT4

 

Hello guys,

I was wondering if there is a way to get data with an indicator or an EA that will count how many bars on average was the price not touching the Moving average. I tried searching the forum and other sources but I don't know what exactly should I search for. Thanks in advanse

 

If you have coding experience you could write a script to check each Bar against a moving average and count each one that doesnt touch. Look up iMA() and Bars. In the documentation.

 
yes I know the function iMA() and Bars and I have some exp in coding. But the question is how to count and save the data. For example It should count the bars that were above or below (not touching the MA) a certain period and save that info somewhere and after that sum those numbers up and divide it to the number of crosses that the price made. I am just not sure if that is possible to do in MT4.
 

Count the bars that have their low above the MA

and those that have their high below the MA

otherwise, they must have straddled the MA

 
rori4:
yes I know the function iMA() and Bars and I have some exp in coding. But the question is how to count and save the data. For example It should count the bars that were above or below (not touching the MA) a certain period and save that info somewhere and after that sum those numbers up and divide it to the number of crosses that the price made. I am just not sure if that is possible to do in MT4.

Counting and holding values for calculations is beginner level coding. You probably need to read the MQL4 Book and Reference.

You can use For loops for counting and cycling through the Bars and variables for holding the values you want to perform calculations on.

Reason: