Download MetaTrader 5
To add comments, please log in or register
Have you published a program in the Market? Place it in your blog as well - the widget will help!
Rangel Stoilov
199
Rangel Stoilov 2014.03.10 17:16 

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

Ian Venner
2583
Ian Venner 2014.03.10 18:28  

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.

Rangel Stoilov
199
Rangel Stoilov 2014.03.10 19:04  
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.
Keith Watford
Moderator
7951
Keith Watford 2014.03.10 21:58  

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

Ian Venner
2583
Ian Venner 2014.03.11 00:01  
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.

/
To add comments, please log in or register