How to Create a Trading Range Module in MQL4

In 2014, the Euro US dollar currency pair dropped like a stone and many people lost lots of money. Most of the time, currency pairs will be pretty stable, but if you want to avoid huge draw downs, it might be handy to define rules for buying and selling. So I have defined a price range here that currently says sell only.

I have created a module called CheckPriceRange.mq4 and a string variable that is called PriceIsInRange. Now, when a new tick comes in, we will call a function called CheckPriceRange() and here is the module. And if the current symbol is Euro US dollar, the max upper price is 1.3211 and the min lower price is 1.3178, and if the ask price is between that two prices, our system will be allowed to buy or sell.
If it’s above sell only is allowed and if it is below, it might only buy. So in the comment line, you see, now, it’s saying, “buy only.” And now, it’s sell only, because the price is above 1.32. We don’t buy at an all-time high, right? This is the way to prevent it.