Download MetaTrader 5
To add comments, please log in or register
How to launch your trading signal and become a provider
klin007
18
klin007 2014.11.27 05:11 

I am starting to code in OOP in MT4. My previously written code in C is quite complex and so I want to use encapsulation to control coding more tightly.

I have transferred class definitions from MT5 to MT4 but get some enums undefined. I have tried to find where the enums are defined but they seem to be hiding.

Can anyone advise where I can find them to modif/add to them or am I doing something really stupid

many thanks

Enrico Lambino
4268
Enrico Lambino 2014.11.27 06:20  

You would not be able to find the enum definitions on the code. They are only included upon compilation. It is possible to redeclare the missing enums if you are going to use some MT5 classes in MT4, though more work may be needed for some to be fully compatible.

Alain Verleyen
Moderator
30180
Alain Verleyen 2014.11.27 08:05  
klin007:

I am starting to code in OOP in MT4. My previously written code in C is quite complex and so I want to use encapsulation to control coding more tightly.

I have transferred class definitions from MT5 to MT4 but get some enums undefined. I have tried to find where the enums are defined but they seem to be hiding.

Can anyone advise where I can find them to modif/add to them or am I doing something really stupid

many thanks

Which enums ?
klin007
18
klin007 2014.11.28 11:14  
angevoyageur:
Which enums ?

Thanks for the answers guys

ENUM_SYMBOL_CALC_MODE and ENUM_SYMBOL_SWAP_MODE as examples

I have defined other ENUM types in my own code to get mqh files to compile but I simply unearth other missing ones as I go

Enum definitions have to reside somewhere and I simply want to include any additional ones in the same location so I reduce the likelihood of errors

Alain Verleyen
Moderator
30180
Alain Verleyen 2014.11.28 14:57  
klin007:

Thanks for the answers guys

ENUM_SYMBOL_CALC_MODE and ENUM_SYMBOL_SWAP_MODE as examples

I have defined other ENUM types in my own code to get mqh files to compile but I simply unearth other missing ones as I go

Enum definitions have to reside somewhere and I simply want to include any additional ones in the same location so I reduce the likelihood of errors

With mql4 :

//--- ENUM_SYMBOL_SWAP_MODE equivalent
MarketInfo(_Symbol,MODE_SWAPTYPE);

//--- ENUM_SYMBOL_CALC_MODE equivalent
MarketInfo(_Symbol,MODE_PROFITCALCMODE);
// OR
MarketInfo(_Symbol,MODE_MARGINCALCMODE);
klin007
18
klin007 2014.11.28 23:41  

OK I think I see where I was going wrong.

The enum definitions are embedded in the compilation process and in line with OOP are private and so directly inaccessible to me the programmer. I can add my own if I want to, but they should also be private in any object I instantiate.

Am I on the right track?

Enrico Lambino
4268
Enrico Lambino 2014.11.29 02:26  
klin007:

OK I think I see where I was going wrong.

The enum definitions are embedded in the compilation process and in line with OOP are private and so directly inaccessible to me the programmer. I can add my own if I want to, but they should also be private in any object I instantiate.

Am I on the right track?

You can declare the missing enums globally if you are to compile using the MQL4 compiler. In the MQL5 compiler, however, they are already declared so re-declaring them will produce an error.

Some enum definitions in the MQL5 compiler are missing in the MQL4 compiler. The documentation is your friend:

https://www.mql5.com/en/docs/standardlibrary/tradeclasses/csymbolinfo/csymbolinfotradecalcmode

You should be able to see there the possible values for ENUM_SYMBOL_CALC_MODE.


That is just the tip of the iceberg. These are some other components in the MT5 classes that are not compatible with MQL4:

Mqldatetime (struct)

Mqltick (struct)

CTrade/CExpertTrade

(all other classes that use or are derived from these classes and structs)

For the structs, you will also need to redeclare them if you are going to use them. For the trade classes, you will need to revise them since the architecture between the two platforms in terms of communicating with the trade server is different. 

Documentation on MQL5: Standard Library / Trade Classes / CSymbolInfo / TradeCalcMode
Documentation on MQL5: Standard Library / Trade Classes / CSymbolInfo / TradeCalcMode
  • www.mql5.com
Standard Library / Trade Classes / CSymbolInfo / TradeCalcMode - Reference on algorithmic/automated trading language for MetaTrader 5
klin007
18
klin007 2014.12.01 01:06  
Iceron:

You can declare the missing enums globally if you are to compile using the MQL4 compiler. In the MQL5 compiler, however, they are already declared so re-declaring them will produce an error.

Some enum definitions in the MQL5 compiler are missing in the MQL4 compiler. The documentation is your friend:

https://www.mql5.com/en/docs/standardlibrary/tradeclasses/csymbolinfo/csymbolinfotradecalcmode

You should be able to see there the possible values for ENUM_SYMBOL_CALC_MODE.


That is just the tip of the iceberg. These are some other components in the MT5 classes that are not compatible with MQL4:

Mqldatetime (struct)

Mqltick (struct)

CTrade/CExpertTrade

(all other classes that use or are derived from these classes and structs)

For the structs, you will also need to redeclare them if you are going to use them. For the trade classes, you will need to revise them since the architecture between the two platforms in terms of communicating with the trade server is different. 

klin007
18
klin007 2014.12.01 01:08  
klin007:
OK thanks guys. As you say "the tip of the iceberg"! However I will continue to open this can of worms as I can see I will increase my expertise, as well as developing robust code for MT4.
/
To add comments, please log in or register