Hi,
As a beginning programmer, i wish to use an object orientated programming approach using MQL4. I am compiling with metaeditor version 5.00 build 1526. I am using inlude files from Andrew Youngs "Expert Advisor Programming for Metatrader4". In the trade.mqh file wrappers are used calling the MqlTradeRequest structure. Unfortanately the structure and its members aren't defined anywhere. Goal is to build an expert advisor template based on include files.
My first question is, what structures and enumerations are built in by design in MQL4?
In the stdlib.mq4 library, no structures or enumerations are defined, in my newbie view. The assumption is, i need to define, declare and initialise structures and enumarations by myself, in the stdlib.mq4 libary. These structures and enumarations will consecutively be called, with an import preproccessor file in the expert advisor ex4, pointing to the stdlib.mq4 file. Am i on the right track with this design?
Thitd question is how does the current compiler handles pre proccesor include files in MQL4? On compilation, are the include files .mqh, compiled to one single ex4 runtime file? e.g three ex4 files compiled from trade.mqh, trailingstop.mqh and expert advisor.mqh are run as an single expert advisor from the terminal.exe instance view
The reason i want to stick with MQL 4 is the avalabilty of testing with real ticks using Birt's tick data suite.
Thanks in advance for reading.
If you are just starting, consider learning MQL5 instead, because development on MetaTrader v4 has stopped. However, if you prefer to continue to learn MQL4 and use MetaTrader 4, you will have to develop your own Trading Classes because MQL4 does not have those (only in MQL5).
Many of your other queries can be answered by reading the official documentation:
Also, MetaTrader 5 already has built-in support for testing with Real Tick data and does not need to use Birt's Tick Data Suite, nor is it restricted to data from just one broker (namely Dukascopy). You can choose to use Data from any broker.
By the way, Andrew Young, also has a book for MetaTrader 5: Expert Advisor Programming for MetaTrader 5: Creating automated trading systems in the MQL5 language (Andrew R. Young)- expertadvisorbook.com
Rudolf De Heer:
what structures and enumerations are built in by design in MQL4?
Thitd question is how does the current compiler handles pre proccesor include files in MQL4? On compilation, are the include files .mqh, compiled to one single ex4 runtime file? e.g three ex4- Data Structures - Standard Constants, Enumerations and Structures - MQL4 Reference says 8 but only lists 3 that I remember.
- Enumerations: Series Array Identifiers(ENUM_SERIESMODE) Smoothing Methods(ENUM_MA_METHOD) ENUM_TIMEFRAMES(ENUM_TIMEFRAMES) ENUM_APPLIED_PRICE(ENUM_APPLIED_PRICE.) Possibility others.
- Just Print(typename(MODE_SMA)) and see.
- Some are ints not enumerations, so I just define a numerically equal equivalents with compatible functions.
Trade operation /** @defgroup tradeop Trade Operations
* An enumeration of Order types with extended values and related functions.
* @{ */
/** [Trade operations](
* http://docs.mql4.com/constants/tradingconstants/orderproperties "Order
* Properties - MQL4 Documentation") e.g.\ OP_BUY, etc.\ as an enumeration with
* [extended values](http://forum.mql4.com/30708 "Check Deposit / Withdrawal
* information - MQL4 forum").
*
* `TO_BALANCE` occurs in the history pool, usually for deposit and withdrawals.
* There is no magic number or symbol associated with these entries. In FXCM,
* the comment is "Deposit".
*
* They also occur with some brokers as entries for commission and swap rather
* than using a OrderCommission() and cummulative OrderSwap(). */
enum Trade_Operation{
TO_BUY, TO_SELL, TO_BUYLIMIT, TO_SELLLIMIT, TO_BUYSTOP, TO_SELLSTOP,
TO_BALANCE, ///< (6) May occur in history pool.
TO_CREDIT}; ///< (7) May occur in history pool.
const Trade_Operation MKT_FIRST = TO_BUY; ///< (0) OP_BUY.
const Trade_Operation MKT_LAST = TO_SELL; ///< (1) OP_SELL.
const Trade_Operation PND_FIRST = TO_BUYLIMIT;///< (2) OP_BUYLIMIT.
const Trade_Operation PND_LAST = TO_SELLSTOP;///< (5) OP_SELLSTOP.
const COUNT MKT_COUNT = 2; ///< (2) [OP_BUY-OP_SELL]
Trade_Operation opposite(Trade_Operation op){
return (op == TO_BUY) ? TO_SELL : TO_BUY;
}
/** Tests an trade operation type.
* @param [in] op If not supplied the `OrderType()` of the currently selected
* order is used.
* @returns True if the _op_ is [MKT_FIRST .. MKT_LAST] i.e.\ an open order. */
bool is_market(Trade_Operation op=WRONG_VALUE){
if(op == WRONG_VALUE) op = (Trade_Operation)OrderType();
return op <= MKT_LAST;
}
/** Tests an trade operation type.
* @param [in] op If not supplied the `OrderType()` of the currently selected
* order is used.
* @return True if the _op_ is not [MKT_FIRST .. MKT_LAST] i.e.\ an Pending
* order. */
bool is_pending(Trade_Operation op=WRONG_VALUE){
return !is_market(op);
}
/** Tests an trade operation direction. This is used to create direction
* independent code e.g.
* ~~~~{.cpp}
* double dir = op_direction();
* PRICE oop = OrderOpenPrice();
* PRICE SL = Oop -dir* trailingStop;
* ~~~~
* @param [in] op If not supplied the `OrderType()` of the currently selected
* order is used.
* @returns Plus one (+1) if the _op_ is `TO_BUY`, Minus one (-1) for a
* `TO_SELL`. */
double op_direction(Trade_Operation op=WRONG_VALUE){
if(op == WRONG_VALUE) op = (Trade_Operation)OrderType();
return TO_BUY == (op % MKT_COUNT) ? +1.0 : -1.0;
}
/** Converts a trade operation to a string.
* @param op If not supplied the `OrderType()` of the currently selected order
* is used.
* @return "BUY", "SELL", "BUYLIMIT", "SELLLIMIT", "BUYSTOP", "SELLSTOP",
* "Balance", or "CREDIT". */
string as_string(Trade_Operation op=WRONG_VALUE){
if(op == WRONG_VALUE) op = (Trade_Operation)OrderType();
string TO_xxx = EnumToString(op); // TO_XXX
return StringSubstr(TO_xxx, 3); // XXX
}
// defgroup tradeop Trade Operations
/// @}deinitialization reason /// Provide a proper enumeration for uninitialization reason codes.
enum Uninitialization_Reason{
UNINIT_PROGRAM, /**< Expert Advisor terminated its operation by calling
* the ExpertRemove() function */
UNINIT_REMOVE, ///< Program has been deleted from the chart
UNINIT_RECOMPILE, ///< Program has been recompiled
UNINIT_CHARTCHANGE, ///< Symbol or chart period has been changed
UNINIT_CHARTCLOSE, ///< Chart has been closed
UNINIT_PARAMETERS, ///< Input parameters have been changed by a user
UNINIT_ACCOUNT, /**< Another account has been activated or reconnection
* to the trade server has occurred due to changes in
* the account settings. */
UNINIT_TEMPLATE, ///< A new template has been applied
UNINIT_INITFAILED, /**< This value means that OnInit() handler has returned
* a nonzero value. */
UNINIT_CLOSE /**< Terminal has been closed*/ };
string as_string(Uninitialization_Reason reason){
string UNINIT_XXXX = EnumToString(reason);
return StringSubstr(UNINIT_XXXX, 7);
}
- Yes, No. Including file is the same as pasting the code right there (into your mq4,) you get your one ex4.
Thanks for the comments and code.
I will continue on learning programming on both platforms. I have the Ebook of Andrew Youngs expert advisor programming for Metatrader 5 . In the hardcover book of programming for Metatrader 4 by Young, include files are "borrowed"from MT5. Unfortunately the parsing/wrapping of the trade structures and enumarations seems to fail. I will contact him, borrow the stdlib from MT5 into MT4, consider a MT5 EA or write the classes for MT4 myself.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi,
As a beginning programmer, i wish to use an object orientated programming approach using MQL4. I am compiling with metaeditor version 5.00 build 1526. I am using inlude files from Andrew Youngs "Expert Advisor Programming for Metatrader4". In the trade.mqh file wrappers are used calling the MqlTradeRequest structure. Unfortanately the structure and its members aren't defined anywhere. Goal is to build an expert advisor template based on include files.
My first question is, what structures and enumerations are built in by design in MQL4?
In the stdlib.mq4 library, no structures or enumerations are defined, in my newbie view. The assumption is, i need to define, declare and initialise structures and enumarations by myself, in the stdlib.mq4 libary. These structures and enumarations will consecutively be called, with an import preproccessor file in the expert advisor ex4, pointing to the stdlib.mq4 file. Am i on the right track with this design?
Thitd question is how does the current compiler handles pre proccesor include files in MQL4? On compilation, are the include files .mqh, compiled to one single ex4 runtime file? e.g three ex4 files compiled from trade.mqh, trailingstop.mqh and expert advisor.mqh are run as an single expert advisor from the terminal.exe instance view
The reason i want to stick with MQL 4 is the avalabilty of testing with real ticks using Birt's tick data suite.
Thanks in advance for reading.