Skip to content

Commit

Permalink
Version 2.3
Browse files Browse the repository at this point in the history
- Implemented AccountFreeMarginCheck()
- added support for some obsolete MQL4 function : CurTime(), HistoryTotal(), LocalTime()
  • Loading branch information
eromawyn committed Sep 10, 2021
1 parent 00a0cda commit e190c02
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 21 deletions.
33 changes: 13 additions & 20 deletions MQL5/Include/mql4compat.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -150,23 +150,10 @@ ENUM_TIMEFRAMES TFMigrate(int tf)
}

/* Ask and Bid variables */
// Predefined Variables
double __Ask()
{
MqlTick last_tick;
SymbolInfoTick(_Symbol,last_tick);
return last_tick.ask;
}

double __Bid()
{
MqlTick last_tick;
SymbolInfoTick(_Symbol,last_tick);
return last_tick.bid;
}

#define Ask __Ask()
#define Bid __Bid()
// Predefined Variables
#define Bid (::SymbolInfoDouble(_Symbol, ::SYMBOL_BID))
#define Ask (::SymbolInfoDouble(_Symbol, ::SYMBOL_ASK))

/* Bars variable */
double Bars = Bars(_Symbol,_Period);
Expand Down Expand Up @@ -232,11 +219,13 @@ double AccountFreeMargin()
{
return AccountInfoDouble(ACCOUNT_FREEMARGIN);
}
double AccountFreeMarginCheck(string _symbol, int _cmd, double _volume)
double AccountFreeMarginCheck(const string Symb,const int Cmd,const double dVolume)
{
// Unimplemented stub
Print("Error: AccountFreeMarginCheck() - Not implemented stub.");
return -1;
double Margin;

return(::OrderCalcMargin((ENUM_ORDER_TYPE)Cmd, Symb, dVolume,
::SymbolInfoDouble(Symb,(Cmd==::ORDER_TYPE_BUY) ? ::SYMBOL_ASK : ::SYMBOL_BID),Margin) ?
::AccountInfoDouble(::ACCOUNT_MARGIN_FREE) - Margin : -1);
}

double AccountFreeMarginMode()
Expand Down Expand Up @@ -762,6 +751,10 @@ int Year()
TimeCurrent(tm);
return(tm.year);
}
// Obsolete MQL4 function
#define CurTime() TimeCurrent()
#define HistoryTotal() OrdersHistoryTotal()
#define LocalTime() TimeLocal()

//File Functions
int FileOpenHistory(string filename, int mode, int delimiter=';')
Expand Down
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ This library has covered most of functions except EA trading mechanisms. Also fo

**TODO:** EA trading mechanics for Orders sending and control. Some functions have generic stubs and will give according error messages in log. The return code for those are always **-1**. Meanwhile, you may find it convenient to check the MT4Orders library : https://www.mql5.com/en/code/16006

**Installation:**
### Installation

Put mql4compat.mqh in your Include directory (it resides on your Windows user roaming profile).

Expand Down Expand Up @@ -126,13 +126,15 @@ In indicators the manual tweaks are needed for OnInit() function and #property h

In custom indicators please see how **#property** headers are in MQL5 and then swap input parameters definitions type **extern** to **input**. Also in MQL5 they are now **constants** and any attempt to change values will lead to errors. The fix is by adding temporary variables then copy input parameters values to them instead.

### InitMQL4Env()
On first line of your base code please add MQL4 reserved variables initialization function (as of version 2.2, only needed if you use MQL4 global variable Bars) :

```MQL5
// -- Init MQL4 compatible environment
InitMQL4Env();
```

Using define for Bars would also affect the Bars function. If you know of any trick which would allow to redefine it while keeping the Bars() function available, keep free to send a patch.

## Changelog

Expand All @@ -149,6 +151,10 @@ Changelog only kept since version 2.0 ...
### Version 2.2
- InitMQL4Env() unfortunately still needed, but only if you use Bars global variable.

### Version 2.3
- Implemented AccountFreeMarginCheck()
- added support for some obsolete MQL4 function : CurTime(), HistoryTotal(), LocalTime()

### Credits

##### Github by Eromawyn (2021)
Expand Down

0 comments on commit e190c02

Please sign in to comment.