Skip to content

Commit

Permalink
WIP. Removed unnecessary files. Moved IndicatorTickReal into Indi_Tic…
Browse files Browse the repository at this point in the history
…kMt. Fixed many of the tests.
  • Loading branch information
nseam committed Jun 28, 2022
1 parent 92c58e2 commit aba07ba
Show file tree
Hide file tree
Showing 25 changed files with 401 additions and 678 deletions.
3 changes: 2 additions & 1 deletion Account/AccountBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@

// Includes.
//#include "../Serializer.mqh"
#include "../Refs.mqh"
#include "AccountBase.struct.h"

/**
* Class to provide functions that return parameters of the current account.
*/
class AccountBase {
class AccountBase : public Dynamic {
protected:
/**
* Init code (called on constructor).
Expand Down
23 changes: 16 additions & 7 deletions Exchange/Exchange.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@
#include "../Trade.mqh"
#include "Exchange.struct.h"

class Exchange {
class Exchange : public Dynamic {
protected:
DictObject<string, AccountBase> accounts;
DictObject<string, SymbolInfo> symbols;
DictObject<string, Trade> trades;
DictStruct<string, Ref<AccountBase>> accounts;
DictStruct<string, Ref<SymbolInfo>> symbols;
DictStruct<string, Ref<Trade>> trades;
ExchangeParams eparams;

public:
Expand All @@ -61,17 +61,26 @@ class Exchange {
/**
* Adds account instance to the list.
*/
void AccountAdd(AccountBase &_account, string _name) { accounts.Set(_name, _account); }
void AccountAdd(AccountBase *_account, string _name) {
Ref<AccountBase> _ref = _account;
accounts.Set(_name, _ref);
}

/**
* Adds symbol instance to the list.
*/
void SymbolAdd(SymbolInfo &_sinfo, string _name) { symbols.Set(_name, _sinfo); }
void SymbolAdd(SymbolInfo *_sinfo, string _name) {
Ref<SymbolInfo> _ref = _sinfo;
symbols.Set(_name, _ref);
}

/**
* Adds trade instance to the list.
*/
void TradeAdd(Trade &_trade, string _name) { trades.Set(_name, _trade); }
void TradeAdd(Trade *_trade, string _name) {
Ref<Trade> _ref = _trade;
trades.Set(_name, _ref);
}

/* Removers */

Expand Down
37 changes: 23 additions & 14 deletions Exchange/tests/Exchange.test.mq5
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,18 @@
*/

// Includes.
#include "../../Platform.h"
#include "../../Test.mqh"
#include "../Exchange.h"

// Test classes.
class AccountDummy : public AccountBase {}; // <AccountForexState, AccountForexEntry>
class ExchangeDummy : public Exchange {};
class SymbolDummy : public SymbolInfo {};
class TradeDummy : public Trade {};
class TradeDummy : public Trade {
public:
TradeDummy(IndicatorBase *_indi_candle) : Trade(_indi_candle) {}
};

// Global variables.
ExchangeDummy ex_dummy;
Expand All @@ -41,29 +45,34 @@ ExchangeDummy ex_dummy;
bool TestExchange01() {
bool _result = true;
// Initialize a dummy Exchange instance.
ExchangeDummy exchange;
Ref<ExchangeDummy> exchange = new ExchangeDummy();

// Attach instances of dummy accounts.
AccountDummy account01;
AccountDummy account02;
exchange.AccountAdd(account01, "Account01");
exchange.AccountAdd(account02, "Account02");
Ref<AccountDummy> account01 = new AccountDummy();
Ref<AccountDummy> account02 = new AccountDummy();
exchange REF_DEREF AccountAdd(account01.Ptr(), "Account01");
exchange REF_DEREF AccountAdd(account02.Ptr(), "Account02");

// Attach instances of dummy symbols.
SymbolDummy symbol01;
SymbolDummy symbol02;
exchange.SymbolAdd(symbol01, "Symbol01");
exchange.SymbolAdd(symbol02, "Symbol02");
Ref<SymbolDummy> symbol01 = new SymbolDummy();
Ref<SymbolDummy> symbol02 = new SymbolDummy();
exchange REF_DEREF SymbolAdd(symbol01.Ptr(), "Symbol01");
exchange REF_DEREF SymbolAdd(symbol02.Ptr(), "Symbol02");

// Attach instances of dummy trades.
TradeDummy trade01;
TradeDummy trade02;
exchange.TradeAdd(trade01, "Trade01");
exchange.TradeAdd(trade02, "Trade02");
Ref<TradeDummy> trade01 = new TradeDummy(Platform::FetchDefaultCandleIndicator(_Symbol, PERIOD_CURRENT));
Ref<TradeDummy> trade02 = new TradeDummy(Platform::FetchDefaultCandleIndicator(_Symbol, PERIOD_CURRENT));

exchange REF_DEREF TradeAdd(trade01.Ptr(), "Trade01");
exchange REF_DEREF TradeAdd(trade02.Ptr(), "Trade02");
return _result;
}

/**
* Implements OnInit().
*/
int OnInit() {
Platform::Init();
bool _result = true;
assertTrueOrFail(TestExchange01(), "Fail!");
return _result && GetLastError() == 0 ? INIT_SUCCEEDED : INIT_FAILED;
Expand Down
4 changes: 2 additions & 2 deletions Indicator.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -950,8 +950,8 @@ class Indicator : public IndicatorBase {
_curr = _curr.GetDataSource(false), --_iterations_left) {
if (_curr == THIS_PTR) {
// Circular dependency found.
Print("Error: Circular dependency found when trying to attach to " + GetFullName() + " data so " +
_indi.GetFullName() + " data source!");
Print("Error: Circular dependency found when trying to attach " + _indi PTR_DEREF GetFullName() + " into " +
GetFullName() + "!");
DebugBreak();
return;
}
Expand Down
108 changes: 0 additions & 108 deletions Indicator/IndicatorCandleSource.h

This file was deleted.

99 changes: 0 additions & 99 deletions Indicator/IndicatorTickOrCandleSource.h

This file was deleted.

Loading

0 comments on commit aba07ba

Please sign in to comment.