Skip to content

Commit

Permalink
Merge tag 'v2.009' into dev-indi-no-chart
Browse files Browse the repository at this point in the history
* tag 'v2.009': (27 commits)
  • Loading branch information
kenorb committed Nov 8, 2021
2 parents ad92ef6 + 86dc933 commit 191c573
Show file tree
Hide file tree
Showing 54 changed files with 387 additions and 228 deletions.
4 changes: 4 additions & 0 deletions .markdownlint.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
---
# MD013 line-length - Line length
MD013:
line_length: 120
# MD033 no-inline-html - Inline HTML
MD033:
allowed_elements: [details]
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
repos:

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.1.0
rev: v4.0.1
hooks:
- id: check-added-large-files
- id: check-byte-order-marker
Expand All @@ -14,12 +14,12 @@ repos:
- id: trailing-whitespace

- repo: https://github.com/igorshubovych/markdownlint-cli.git
rev: v0.23.1
rev: v0.29.0
hooks:
- id: markdownlint

- repo: https://github.com/adrienverge/yamllint.git
rev: v1.23.0
rev: v1.26.3
hooks:
- id: yamllint
args: ["-c", ".yamllint", "-s"]
4 changes: 2 additions & 2 deletions Bar.enum.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@

/* Pivot Point calculation method. */
enum ENUM_PP_TYPE {
PP_CAMARILLA = 1, // A set of eight levels which resemble support and resistance values
PP_CAMARILLA = 1, // Camarilla: A set of eight levels which resemble support and resistance values
PP_CLASSIC = 2, // Classic pivot point
PP_FIBONACCI = 3, // Fibonacci pivot point
PP_FLOOR = 4, // Most basic and popular type of pivots used in Forex trading technical analysis
PP_FLOOR = 4, // Floor: Most basic and popular type of pivots used in Forex trading technical analysis
PP_TOM_DEMARK = 5, // Tom DeMark's pivot point (predicted lows and highs of the period)
PP_WOODIE = 6, // Woodie's pivot point are giving more weight to the Close price of the previous period
};
12 changes: 6 additions & 6 deletions Chart.struct.static.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ struct ChartStatic {
#else // __MQL5__
ARRAY(double, _arr);
ArraySetAsSeries(_arr, true);
return (_shift >= 0 && CopyClose(_symbol, _tf, _shift, 1, _arr) > 0) ? _arr[0] : -1;
return (_shift >= 0 && CopyClose(_symbol, _tf, _shift, 1, _arr) > 0) ? _arr[0] : 0;
#endif
}

Expand All @@ -95,7 +95,7 @@ struct ChartStatic {
#else // __MQL5__
ARRAY(double, _arr);
ArraySetAsSeries(_arr, true);
return (_shift >= 0 && CopyHigh(_symbol, _tf, _shift, 1, _arr) > 0) ? _arr[0] : -1;
return (_shift >= 0 && CopyHigh(_symbol, _tf, _shift, 1, _arr) > 0) ? _arr[0] : 0;
#endif
}

Expand Down Expand Up @@ -152,7 +152,7 @@ struct ChartStatic {
#else // __MQL5__
ARRAY(double, _arr);
ArraySetAsSeries(_arr, true);
return (_shift >= 0 && CopyLow(_symbol, _tf, _shift, 1, _arr) > 0) ? _arr[0] : -1;
return (_shift >= 0 && CopyLow(_symbol, _tf, _shift, 1, _arr) > 0) ? _arr[0] : 0;
#endif
}

Expand Down Expand Up @@ -209,7 +209,7 @@ struct ChartStatic {
#else // __MQL5__
ARRAY(double, _arr);
ArraySetAsSeries(_arr, true);
return (_shift >= 0 && CopyOpen(_symbol, _tf, _shift, 1, _arr) > 0) ? _arr[0] : -1;
return (_shift >= 0 && CopyOpen(_symbol, _tf, _shift, 1, _arr) > 0) ? _arr[0] : 0;
#endif
}

Expand Down Expand Up @@ -268,7 +268,7 @@ struct ChartStatic {
ARRAY(datetime, _arr);
// ENUM_TIMEFRAMES _tf = MQL4::TFMigrate(_tf);
// @todo: Improves performance by caching values.
return (_shift >= 0 && ::CopyTime(_symbol, _tf, _shift, 1, _arr) > 0) ? _arr[0] : -1;
return (_shift >= 0 && ::CopyTime(_symbol, _tf, _shift, 1, _arr) > 0) ? _arr[0] : 0;
#endif
}

Expand All @@ -289,7 +289,7 @@ struct ChartStatic {
#else // __MQL5__
ARRAY(long, _arr);
ArraySetAsSeries(_arr, true);
return (_shift >= 0 && CopyTickVolume(_symbol, _tf, _shift, 1, _arr) > 0) ? _arr[0] : -1;
return (_shift >= 0 && CopyTickVolume(_symbol, _tf, _shift, 1, _arr) > 0) ? _arr[0] : 0;
#endif
}

Expand Down
2 changes: 1 addition & 1 deletion Convert.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#include "Array.mqh"
#include "Order.enum.h"
#include "SymbolInfo.enum.h"
#include "SymbolInfo.static.h"
#include "SymbolInfo.struct.static.h"

/**
* Class to provide conversion methods.
Expand Down
102 changes: 26 additions & 76 deletions EA.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ class EA {
Account *account;
DictStruct<long, Ref<Strategy>> strats;
Log logger;
Ref<Market> market;
Terminal terminal;

// Data variables.
Expand All @@ -79,8 +78,7 @@ class EA {
/**
* Class constructor.
*/
EA(EAParams &_params)
: account(new Account), market(new Market(_params.Get<string>(STRUCT_ENUM(EAParams, EA_PARAM_PROP_SYMBOL)))) {
EA(EAParams &_params) : account(new Account) {
eparams = _params;
estate.Set(STRUCT_ENUM(EAState, EA_STATE_FLAG_ON_INIT), true);
UpdateStateFlags();
Expand All @@ -94,9 +92,6 @@ class EA {
Trade _trade(_tparams, _cparams);
trade.Set(_Symbol, _trade);
logger.Link(_trade.GetLogger());
// trade.GetByKey(_Symbol).GetLogger().Error("Test");
// logger.Flush();
// Loads existing trades by magic number.
}

/**
Expand All @@ -113,19 +108,16 @@ class EA {
/* Getters */

/**
* Gets EA parameter value.
* Gets EA state flag value.
*/
template <typename T>
T Get(STRUCT_ENUM(EAParams, ENUM_EA_PARAM_PROP) _param) {
return eparams.Get<T>(_param);
}
bool Get(STRUCT_ENUM(EAState, ENUM_EA_STATE_FLAGS) _prop) { return estate.Get(_prop); }

/**
* Gets EA state flag value.
* Gets EA parameter value.
*/
template <typename T>
T Get(STRUCT_ENUM(EAState, ENUM_EA_STATE_FLAGS) _prop) {
return estate.Get<T>(_prop);
T Get(STRUCT_ENUM(EAParams, ENUM_EA_PARAM_PROP) _param) {
return eparams.Get<T>(_param);
}

/**
Expand Down Expand Up @@ -204,6 +196,11 @@ class EA {
eparams.Set<T>(_param, _value);
}

/**
* Sets EA state flag value.
*/
void Set(STRUCT_ENUM(EAState, ENUM_EA_STATE_FLAGS) _prop, bool _value) { estate.Set(_prop, _value); }

/**
* Sets an strategy parameter value for all strategies.
*/
Expand All @@ -226,31 +223,6 @@ class EA {
}
}

/**
* Sets an strategy parameter value for all strategies.
*/
/* @fixme
template <typename T>
void Set(ENUM_TRADE_PARAM _param, T _value, ENUM_TIMEFRAMES _tf) {
for (DictStructIterator<long, Ref<Strategy>> iter = strats.Begin(); iter.IsValid(); ++iter) {
Strategy *_strat = iter.Value().Ptr();
_strat.Set<T>(_param, _value);
}
}
*/

/**
* Sets an strategy parameter value for the given timeframe.
*/
/* @fixme
template <typename T>
void Set(ENUM_TRADE_PARAM _param, T _value) {
for (DictStructIterator<long, Ref<Strategy>> iter = strats.Begin(); iter.IsValid(); ++iter) {
Set(_param, _value);
}
}
*/

/* Processing methods */

/**
Expand Down Expand Up @@ -292,6 +264,8 @@ class EA {
_strat.OnOrderClose(ORDER_TYPE_SELL);
}
}
_trade_allowed &= _trade.IsTradeAllowed();
_trade_allowed &= !_strat.IsSuspended();
if (_trade_allowed) {
float _sig_open = _signal.GetSignalOpen();
unsigned int _sig_f = eparams.Get<unsigned int>(STRUCT_ENUM(EAParams, EA_PARAM_PROP_SIGNAL_FILTER));
Expand Down Expand Up @@ -327,13 +301,13 @@ class EA {
_signal.Set(STRUCT_ENUM(TradeSignalEntry, TRADE_SIGNAL_FLAG_PROCESSED), true);
} else {
_last_error = GetLastError();
switch (_last_error) {
case ERR_NOT_ENOUGH_MEMORY:
logger.Error(StringFormat("Not enough money to open trades! Code: %d", _last_error), __FUNCTION_LINE__,
_strat.GetName());
logger.Warning(StringFormat("Suspending strategy.", _last_error), __FUNCTION_LINE__, _strat.GetName());
_strat.Suspended(true);
break;
if (_last_error > 0) {
logger.Warning(StringFormat("Error: %d", _last_error), __FUNCTION_LINE__, _strat.GetName());
ResetLastError();
}
if (_trade.Get<bool>(TRADE_STATE_MONEY_NOT_ENOUGH)) {
logger.Warning(StringFormat("Suspending strategy.", _last_error), __FUNCTION_LINE__, _strat.GetName());
_strat.Suspended(true);
}
}
}
Expand Down Expand Up @@ -383,7 +357,6 @@ class EA {
virtual EAProcessResult ProcessTick() {
if (estate.IsEnabled()) {
MqlTick _tick = SymbolInfoStatic::GetTick(_Symbol);
GetMarket().SetTick(_tick);
eresults.Reset();
if (estate.IsActive()) {
ProcessPeriods();
Expand All @@ -401,9 +374,9 @@ class EA {
eresults.stg_processed_periods++;
}
if (_strat.TickFilter(_tick)) {
_can_trade &= _can_trade && !_strat.IsSuspended();
_can_trade &= _can_trade && !_strat.CheckCondition(STRAT_COND_TRADE_COND, TRADE_COND_HAS_STATE,
TRADE_STATE_TRADE_CANNOT);
_can_trade &= !_strat.IsSuspended();
_can_trade &=
!_strat.CheckCondition(STRAT_COND_TRADE_COND, TRADE_COND_HAS_STATE, TRADE_STATE_TRADE_CANNOT);
TradeSignalEntry _sentry = GetStrategySignalEntry(_strat, _can_trade, _strat.Get<int>(STRAT_PARAM_SHIFT));
if (_sentry.Get<uint>(STRUCT_ENUM(TradeSignalEntry, TRADE_SIGNAL_PROP_SIGNALS)) > 0) {
TradeSignal _signal(_sentry);
Expand Down Expand Up @@ -752,6 +725,7 @@ class EA {
_strat.Ptr().Set<long>(STRAT_PARAM_ID, _magic_no);
_strat.Ptr().Set<ENUM_TIMEFRAMES>(STRAT_PARAM_TF, _tf);
_strat.Ptr().Set<int>(STRAT_PARAM_TYPE, _type);
_strat.Ptr().OnInit();
if (!strats.KeyExists(_magic_no)) {
_result &= strats.Set(_magic_no, _strat);
} else {
Expand Down Expand Up @@ -1044,11 +1018,6 @@ class EA {
return NULL;
}

/**
* Returns pointer to Terminal object.
*/
Market *GetMarket() { return market.Ptr(); }

/**
* Returns pointer to Market object.
*/
Expand All @@ -1064,11 +1033,6 @@ class EA {
*/
DictStruct<long, Ref<Strategy>> *GetStrategies() { return GetPointer(strats); }

/**
* Gets EA params.
*/
EAParams GetParams() { return eparams; }

/**
* Gets EA state.
*/
Expand All @@ -1086,21 +1050,11 @@ class EA {
*/
Log *GetLogger() { return GetPointer(logger); }

/**
* Gets pointer to market details.
*/
Market *Market() { return market.Ptr(); }

/**
* Gets reference to strategies.
*/
DictStruct<long, Ref<Strategy>> *Strategies() { return &strats; }

/**
* Gets pointer to symbol details.
*/
SymbolInfo *SymbolInfo() { return (SymbolInfo *)GetMarket(); }

/* Setters */

/* Virtual methods */
Expand Down Expand Up @@ -1176,12 +1130,6 @@ class EA {
SerializerNodeType Serialize(Serializer &_s) {
_s.Pass(THIS_REF, "account", account, SERIALIZER_FIELD_FLAG_DYNAMIC);

// In MQL it will be: Market* _market = GetMarket();
// In C++ it will be: Market& _market = GetMarket();
// It is needed as PassObject() expects reference to object instead of its pointer.
MAKE_REF_FROM_PTR(Market, _market, GetMarket());
_s.PassObject(THIS_REF, "market", _market, SERIALIZER_FIELD_FLAG_DYNAMIC);

for (DictStructIterator<long, Ref<Strategy>> _iter = GetStrategies().Begin(); _iter.IsValid(); ++_iter) {
Strategy *_strat = _iter.Value().Ptr();
// @fixme: GH-422
Expand All @@ -1192,6 +1140,8 @@ class EA {
_s.Pass(THIS_REF, "strat:params:" + _sname, _sparams);
_s.Pass(THIS_REF, "strat:results:" + _sname, _sresults);
}
_s.PassObject(THIS_REF, "trade", trade);
_s.PassObject(THIS_REF, "tsm", tsm);
return SerializerNodeObject;
}
};
Expand Down
8 changes: 5 additions & 3 deletions Indicator.define.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,15 @@
// Defines macros.
#define COMMA ,
#define DUMMY
#define ICUSTOM_DEF(PARAMS) \

#define ICUSTOM_DEF(SET_HANDLE, PARAMS) \
double _res[]; \
if (_handle == NULL || _handle == INVALID_HANDLE) { \
if ((_handle = ::iCustom(_symbol, _tf, _name PARAMS)) == INVALID_HANDLE) { \
SetUserError(ERR_USER_INVALID_HANDLE); \
return EMPTY_VALUE; \
} \
SET_HANDLE; \
} \
int _bars_calc = ::BarsCalculated(_handle); \
if (GetLastError() > 0) { \
Expand All @@ -49,7 +51,7 @@
return EMPTY_VALUE; \
} \
if (::CopyBuffer(_handle, _mode, _shift, 1, _res) < 0) { \
return EMPTY_VALUE; \
return ArraySize(_res) > 0 ? _res[0] : EMPTY_VALUE; \
} \
return _res[0];

Expand Down Expand Up @@ -123,6 +125,6 @@ class DrawIndicator;
} \
} \
if (CopyBuffer(_handle, MODE, SHIFT, 1, _res) < 0) { \
return EMPTY_VALUE; \
return ArraySize(_res) > 0 ? _res[0] : EMPTY_VALUE; \
} \
return _res[0];
Loading

0 comments on commit 191c573

Please sign in to comment.