Skip to content

Commit

Permalink
Merge tag 'v2.002' into dev-refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
kenorb committed Apr 29, 2021
2 parents 81667dc + 2d89dd6 commit 43477b5
Show file tree
Hide file tree
Showing 256 changed files with 2,766 additions and 1,855 deletions.
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ jobs:
- MarketTest
- MatrixTest
- OrderTest
- OrdersTest
- StatsTest
- StrategyTest
- StrategyTest-RSI
Expand Down
25 changes: 25 additions & 0 deletions Account.define.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//+------------------------------------------------------------------+
//| EA31337 framework |
//| Copyright 2016-2021, EA31337 Ltd |
//| https://github.com/EA31337 |
//+------------------------------------------------------------------+

/*
* This file is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

// Defines.
#define ACC_OP_BALANCE 6 // Undocumented balance history statement entry.
#define ACC_OP_CREDIT 7 // Undocumented credit history statement entry.
2 changes: 1 addition & 1 deletion Account.enum.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//+------------------------------------------------------------------+
//| EA31337 framework |
//| Copyright 2016-2021, 31337 Investments Ltd |
//| Copyright 2016-2021, EA31337 Ltd |
//| https://github.com/EA31337 |
//+------------------------------------------------------------------+

Expand Down
81 changes: 26 additions & 55 deletions Account.mqh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//+------------------------------------------------------------------+
//| EA31337 framework |
//| Copyright 2016-2021, 31337 Investments Ltd |
//| Copyright 2016-2021, EA31337 Ltd |
//| https://github.com/EA31337 |
//+------------------------------------------------------------------+

Expand Down Expand Up @@ -28,16 +28,20 @@
class Account;

// Includes.
#include "Account.define.h"
#include "Account.enum.h"
#include "Account.struct.h"
#include "Array.mqh"
#include "BufferStruct.mqh"
#include "Chart.mqh"
#include "Convert.mqh"
#include "Data.struct.h"
#include "Indicator.struct.h"
#include "Order.struct.h"
#include "Orders.mqh"
#include "Serializer.mqh"
#include "SymbolInfo.mqh"
#include "Trade.struct.h"

/**
* Class to provide functions that return parameters of the current account.
Expand All @@ -53,34 +57,20 @@ class Account {
double acc_stats[FINAL_ENUM_ACC_STAT_VALUE][FINAL_ENUM_ACC_STAT_PERIOD][FINAL_ENUM_ACC_STAT_TYPE]
[FINAL_ENUM_ACC_STAT_INDEX];

// Class variables.
Orders *trades;
Orders *history;
Orders *dummy;

public:
// Defines.
#define ACC_OP_BALANCE 6 // Undocumented balance history statement entry.
#define ACC_OP_CREDIT 7 // Undocumented credit history statement entry.

/**
* Class constructor.
*/
Account()
: init_balance(CalcInitDeposit()),
start_balance(GetBalance()),
start_credit(GetCredit()),
trades(new Orders(ORDERS_POOL_TRADES)),
history(new Orders(ORDERS_POOL_HISTORY)),
dummy(new Orders(ORDERS_POOL_DUMMY)) {}
start_credit(GetCredit()) {}

/**
* Class deconstructor.
*/
~Account() {
delete trades;
delete history;
delete dummy;
}

/* Entries */
Expand Down Expand Up @@ -145,50 +135,50 @@ class Account {
* Returns balance value of the current account.
*/
static double AccountBalance() { return AccountInfoDouble(ACCOUNT_BALANCE); }
double GetBalance() {
float GetBalance() {
// @todo: Adds caching.
// return UpdateStats(ACC_BALANCE, AccountBalance());
return Account::AccountBalance();
return (float) Account::AccountBalance();
}

/**
* Returns credit value of the current account.
*/
static double AccountCredit() { return AccountInfoDouble(ACCOUNT_CREDIT); }
double GetCredit() {
float GetCredit() {
// @todo: Adds caching.
// return UpdateStats(ACC_CREDIT, AccountCredit());
return Account::AccountCredit();
return (float) Account::AccountCredit();
}

/**
* Returns profit value of the current account.
*/
static double AccountProfit() { return AccountInfoDouble(ACCOUNT_PROFIT); }
double GetProfit() {
float GetProfit() {
// @todo: Adds caching.
// return UpdateStats(ACC_PROFIT, AccountProfit());
return Account::AccountProfit();
return (float) Account::AccountProfit();
}

/**
* Returns equity value of the current account.
*/
static double AccountEquity() { return AccountInfoDouble(ACCOUNT_EQUITY); }
double GetEquity() {
float GetEquity() {
// @todo: Adds caching.
// return UpdateStats(ACC_EQUITY, AccountEquity());
return Account::AccountEquity();
return (float) Account::AccountEquity();
}

/**
* Returns margin value of the current account.
*/
static double AccountMargin() { return AccountInfoDouble(ACCOUNT_MARGIN); }
double GetMarginUsed() {
float GetMarginUsed() {
// @todo: Adds caching.
// return UpdateStats(ACC_MARGIN_USED, AccountMargin());
return Account::AccountMargin();
return (float) Account::AccountMargin();
}

/**
Expand All @@ -207,10 +197,10 @@ class Account {
* Returns free margin value of the current account.
*/
static double AccountFreeMargin() { return AccountInfoDouble(ACCOUNT_MARGIN_FREE); }
double GetMarginFree() {
float GetMarginFree() {
// @todo: Adds caching.
// return UpdateStats(ACC_MARGIN_FREE, AccountFreeMargin());
return Account::AccountFreeMargin();
return (float) Account::AccountFreeMargin();
}

/**
Expand Down Expand Up @@ -258,13 +248,13 @@ class Account {
* Get account total balance (including credit).
*/
static double AccountTotalBalance() { return AccountBalance() + AccountCredit(); }
double GetTotalBalance() { return GetBalance() + GetCredit(); }
float GetTotalBalance() { return (float) (GetBalance() + GetCredit()); }

/**
* Get account available margin.
*/
static double AccountAvailMargin() { return fmin(AccountFreeMargin(), AccountTotalBalance()); }
double GetMarginAvail() { return AccountAvailMargin(); }
float GetMarginAvail() { return (float) AccountAvailMargin(); }

/**
* Returns the calculation mode of free margin allowed to open orders on the current account.
Expand Down Expand Up @@ -439,46 +429,36 @@ class Account {
* Returns value from 0.0 (no risk) and 1.0 (100% risk).
* The risk higher than 1.0 means that the risk is extremely high.
*/
/* @fixme
double GetRiskMarginLevel(ENUM_ORDER_TYPE _cmd = NULL) {
double _avail_margin = AccountAvailMargin() * Convert::ValueToMoney(trades.TotalSL(_cmd));
return _avail_margin > 0 ? 1 / _avail_margin : 0;
}
*/

/**
* Calculates initial deposit based on the current balance and previous orders.
*/
static double CalcInitDeposit() {
double deposit = AccountInfoDouble(ACCOUNT_BALANCE);
for (int i = Account::OrdersHistoryTotal() - 1; i >= 0; i--) {
double deposit = Account::AccountInfoDouble(ACCOUNT_BALANCE);
for (int i = TradeHistoryStatic::HistoryOrdersTotal() - 1; i >= 0; i--) {
if (!Order::TryOrderSelect(i, SELECT_BY_POS, MODE_HISTORY)) continue;
int type = Order::OrderType();
// Initial balance not considered.
if (i == 0 && type == ACC_OP_BALANCE) break;
if (type == ORDER_TYPE_BUY || type == ORDER_TYPE_SELL) {
// Calculate profit.
double profit = Order::OrderProfit() + Order::OrderCommission() + Order::OrderSwap();
double profit = OrderStatic::Profit() + OrderStatic::Commission() + OrderStatic::Swap();
// Calculate decrease balance.
deposit -= profit;
}
if (type == ACC_OP_BALANCE || type == ACC_OP_CREDIT) {
deposit -= Order::OrderProfit();
deposit -= OrderStatic::Profit();
}
}
return deposit;
}

/**
* Returns the number of closed orders in the account history loaded into the terminal.
*/
static int OrdersHistoryTotal() {
#ifdef __MQL4__
return ::OrdersHistoryTotal();
#else
::HistorySelect(0, TimeCurrent());
return ::HistoryOrdersTotal();
#endif
}

/**
* Calculate total profit.
*/
Expand Down Expand Up @@ -643,15 +623,6 @@ class Account {
GetMarginFree(), GetMarginAvail());
}

/* Class access methods */

/**
* Returns Orders class to access the current trades.
*/
Orders *Trades() { return trades; }
Orders *History() { return history; }
Orders *Dummy() { return dummy; }

/* Serializers */

/**
Expand Down
2 changes: 1 addition & 1 deletion Account.struct.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//+------------------------------------------------------------------+
//| EA31337 framework |
//| Copyright 2016-2021, 31337 Investments Ltd |
//| Copyright 2016-2021, EA31337 Ltd |
//| https://github.com/EA31337 |
//+------------------------------------------------------------------+

Expand Down
2 changes: 1 addition & 1 deletion Action.enum.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//+------------------------------------------------------------------+
//| EA31337 framework |
//| Copyright 2016-2021, 31337 Investments Ltd |
//| Copyright 2016-2021, EA31337 Ltd |
//| https://github.com/EA31337 |
//+------------------------------------------------------------------+

Expand Down
2 changes: 1 addition & 1 deletion Action.mqh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//+------------------------------------------------------------------+
//| EA31337 framework |
//| Copyright 2016-2021, 31337 Investments Ltd |
//| Copyright 2016-2021, EA31337 Ltd |
//| https://github.com/EA31337 |
//+------------------------------------------------------------------+

Expand Down
18 changes: 9 additions & 9 deletions Action.struct.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//+------------------------------------------------------------------+
//| EA31337 framework |
//| Copyright 2016-2021, 31337 Investments Ltd |
//| Copyright 2016-2021, EA31337 Ltd |
//| https://github.com/EA31337 |
//+------------------------------------------------------------------+

Expand Down Expand Up @@ -40,14 +40,14 @@

/* Entry for Action class. */
struct ActionEntry {
unsigned char flags; /* Action flags. */
datetime last_success; /* Time of the previous check. */
long action_id; /* Action ID. */
short tries; /* Number of retries left. */
void *obj; /* Reference to associated object. */
ENUM_ACTION_TYPE type; /* Action type. */
ENUM_TIMEFRAMES frequency; /* How often to check. */
DataParamEntry args[]; /* Action arguments. */
unsigned char flags; /* Action flags. */
datetime last_success; /* Time of the previous check. */
long action_id; /* Action ID. */
short tries; /* Number of retries left. */
void *obj; /* Reference to associated object. */
ENUM_ACTION_TYPE type; /* Action type. */
ENUM_TIMEFRAMES frequency; /* How often to check. */
DataParamEntry args[]; /* Action arguments. */
// Constructors.
void ActionEntry() : type(FINAL_ACTION_TYPE_ENTRY), action_id(WRONG_VALUE) { Init(); }
void ActionEntry(long _action_id, ENUM_ACTION_TYPE _type) : type(_type), action_id(_action_id) { Init(); }
Expand Down
2 changes: 1 addition & 1 deletion Array.mqh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//+------------------------------------------------------------------+
//| EA31337 framework |
//| Copyright 2016-2021, 31337 Investments Ltd |
//| Copyright 2016-2021, EA31337 Ltd |
//| https://github.com/EA31337 |
//+------------------------------------------------------------------+

Expand Down
2 changes: 1 addition & 1 deletion Bar.enum.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//+------------------------------------------------------------------+
//| EA31337 framework |
//| Copyright 2016-2021, 31337 Investments Ltd |
//| Copyright 2016-2021, EA31337 Ltd |
//| https://github.com/EA31337 |
//+------------------------------------------------------------------+

Expand Down
3 changes: 2 additions & 1 deletion Bar.struct.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//+------------------------------------------------------------------+
//| EA31337 framework |
//| Copyright 2016-2021, 31337 Investments Ltd |
//| Copyright 2016-2021, EA31337 Ltd |
//| https://github.com/EA31337 |
//+------------------------------------------------------------------+

Expand All @@ -27,6 +27,7 @@

// Includes.
#include "Bar.enum.h"
#include "SerializerNode.enum.h"
#include "Serializer.mqh"

/* Struct for storing OHLC values. */
Expand Down
2 changes: 1 addition & 1 deletion BasicTrade.mqh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//+------------------------------------------------------------------+
//| EA31337 framework |
//| Copyright 2016-2021, 31337 Investments Ltd |
//| Copyright 2016-2021, EA31337 Ltd |
//| https://github.com/EA31337 |
//+------------------------------------------------------------------+

Expand Down
2 changes: 1 addition & 1 deletion Buffer.mqh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//+------------------------------------------------------------------+
//| EA31337 framework |
//| Copyright 2016-2021, 31337 Investments Ltd |
//| Copyright 2016-2021, EA31337 Ltd |
//| https://github.com/EA31337 |
//+------------------------------------------------------------------+

Expand Down
2 changes: 1 addition & 1 deletion BufferStruct.mqh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//+------------------------------------------------------------------+
//| EA31337 framework |
//| Copyright 2016-2021, 31337 Investments Ltd |
//| Copyright 2016-2021, EA31337 Ltd |
//| https://github.com/EA31337 |
//+------------------------------------------------------------------+

Expand Down
2 changes: 1 addition & 1 deletion Chart.enum.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//+------------------------------------------------------------------+
//| EA31337 framework |
//| Copyright 2016-2021, 31337 Investments Ltd |
//| Copyright 2016-2021, EA31337 Ltd |
//| https://github.com/EA31337 |
//+------------------------------------------------------------------+

Expand Down
2 changes: 1 addition & 1 deletion Chart.mqh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//+------------------------------------------------------------------+
//| EA31337 framework |
//| Copyright 2016-2021, 31337 Investments Ltd |
//| Copyright 2016-2021, EA31337 Ltd |
//| https://github.com/EA31337 |
//+------------------------------------------------------------------+

Expand Down
Loading

0 comments on commit 43477b5

Please sign in to comment.