25.10.2016 Views

Expert Advisor Programming by Andrew R. Young

Expert Advisor Programming by Andrew R. Young

Expert Advisor Programming by Andrew R. Young

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Order Placement<br />

From now on, we'll use UsePoint and UseSlippage to refer to these values. The above code<br />

assumes that your EA is placing orders on one currency only. This will be the case 98% of the time,<br />

but if you're creating an expert advisor that places orders on multiple currencies (or on a currency<br />

other than the current chart), you'll need to use the PipPoint() and GetSlippage() functions every<br />

time you need to calculate these values.<br />

MarketInfo()<br />

We used the MarketInfo() function above to retrieve the Point value and the number of digits in the<br />

currency quote. The MarketInfo() function has many uses, and you will be using it to retrieve<br />

necessary price information in your programs. Here is the syntax for the MarketInfo() function:<br />

double MarketInfo(string Symbol, int RequestType);<br />

The Symbol argument is simply the currency symbol that you want to retrieving the information for.<br />

For the current chart symbol, the Symbol() function can be used. For other symbols, you'll need to<br />

specify the currency symbol, such as EURJPY.<br />

RequestType is an integer constant, representing the information that you are requesting from the<br />

function. Here's a list of the most useful MarketInfo() constants. A complete list can be found in the<br />

MQL Reference, under Standard Constants – MarketInfo.<br />

• MODE_POINT – The point value. For example, 0.01 or 0.00001.<br />

• MODE_DIGITS – The number of decimal places in the price. Will be 2 or 3 for Yen pairs, and 4<br />

or 5 for all other pairs.<br />

• MODE_SPREAD – The current spread. For example, 3 pips (or 30 for a fractional pip broker).<br />

• MODE_STOPLEVEL – The stop level. For example, 3 pips (or 30 for a fractional pip broker).<br />

These request identifiers are generally used when checking price information on another currency, or<br />

anywhere where the symbol may be anything other than the current chart symbol:<br />

• MODE_BID – The current bid price of the selected symbol.<br />

• MODE_ASK – The current ask price of the selected symbol.<br />

• MODE_LOW – The low of the current bar of the selected symbol.<br />

• MODE_HIGH – The high of the current bar of the selected symbol.<br />

29

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!