In Part 33 we discussed the ins and out of the PcntTradeSize() function. I told you we would discuss a few other tricks, but we just didn’t have the space. So this time we’ll talk about some of those, most notably the built-in MarketInfo() function.
The MarketInfo() function, among other things, allows us to know the specific broker’s parameters for their MT4 platform. You can find the complete documentation for this function here. The ins and outs of the function are very straightforward. The two inputs:
Symbol – string – as you may know, can be the actual symbol in quotes (e.g. “EURUSD”, no slash – be sure to include prefixes and suffixes if your broker uses them) or the built-in function Symbol() which represents the symbol of the chart on which the EA is loaded. Being able to use pairs other than the pair on the chart on which the EA is loaded allows you to use a single chart/EA combination to manipulate any or all the pairs. Our EA is designed to work only on the pair of the chart on which it is loaded, but we could actually, with some limitations, manipulate other pairs as well.
Type – int – the type is an integer, but in keeping with MQL4’s other features, there are a series of predefined constants to represent the integers you can use for this parameter.
It’s output is simply a double variable. But it represents many different numbers depending upon the Type value you send the function. Some of the MarketInfo() information for the current pair is available through other predefined variables [e.g. Point = MarketInfo(Symbol(),MODE_POINT) & Digits = MarketInfo(Symb0l(), MODE_DIGITS).] The Types in which we’re interested for the trade size calculation are the ones representing the broker’s min/max/step trade size information.
MODE_MINLOT (23) – Minimum permitted amount of a lot.
MODE_MAXLOT (25) – Maximum permitted amount of a lot.
MODE_LOTSTEP (24) – Step for changing lots.
In my experience, most brokers (but not all) use 0.01 (one micro-lot or 1,000 nominal currency units) as the minimum and lot step. The maximum varies by broker. One of my brokers uses 0.1 (one mini-lot or 10,000 nominal currency units) as the minimum but uses 0.01 as the lot step. My account is large enough to use mini-lots, but it’s still nice to have the granularity of adjusting my lot size by micros. It makes me happy to have lots of control of my trade risk because that’s the name of the game.
In addition, we also use:
MODE_TICKVALUE (16) – Tick value in the deposit currency.
To relate the currency pair price to the deposit currency.
A few other MarketInfo() types that we’re not using for the PcntTradeSize() function, but that I find very useful are:
MODE_SWAPLONG (18) & MODE_SWAPSHORT (19) – Swap of the Long and Short positions
MODE_MARGINREQUIRED (32) – Free margin required to open 1 lot for buying.
MODE_STOPLEVEL (14) – Stop level in points.
MODE_FREEZELEVEL (33) – Order freeze level in points. If the execution price lies within the range defined by the freeze level, the order cannot be modified, cancelled or closed.
The MarketInfo() function is pretty handy. I use it quite a bit.
That’s it for today. Next time we’ll talk about using the MAXover() and PcntTradeSize() functions in our EA. Thanks for your attention and please follow me on Twitter and LinkedIn.
Winner’s Edge Trading, as seen on: