Skip to content

Commit

Permalink
Adding missing methods, making code MQL/C++ compatible.
Browse files Browse the repository at this point in the history
  • Loading branch information
nseam committed Jun 8, 2021
1 parent 59df30a commit 178e8c8
Show file tree
Hide file tree
Showing 10 changed files with 110 additions and 96 deletions.
3 changes: 2 additions & 1 deletion Bar.struct.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ struct BarOHLC
_time = TimeCurrent();
}
}
BarOHLC(float &_prices[], datetime _time = 0) : time(_time) {
BarOHLC(ARRAY_REF(float, _prices), datetime _time = 0) : time(_time) {
_time = _time == 0 ? TimeCurrent() : _time;
int _size = ArraySize(_prices);
close = _prices[0];
Expand Down Expand Up @@ -187,6 +187,7 @@ struct BarOHLC
float GetWickUpper() const { return high - GetMaxOC(); }
float GetWickUpperInPct() const { return GetRange() > 0 ? 100 / GetRange() * GetWickUpper() : 0; }
short GetType() const { return IsBull() ? 1 : (IsBear() ? -1 : 0); }
void GetValues(ARRAY_REF(float, _out)) {
ArrayResize(_out, 4);
int _index = ArraySize(_out) - 4;
_out[_index++] = open;
Expand Down
6 changes: 6 additions & 0 deletions DictIteratorBase.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@

#include "DictBase.mqh"

template <typename K, typename V>
class DictBase;

template <typename K, typename V>
class DictIteratorBase {
protected:
Expand Down Expand Up @@ -106,6 +109,9 @@ class DictIteratorBase {
}
};

template <typename K, typename V>
class DictSlot;

template <typename K, typename V>
struct DictSlotsRef {
DictSlot<K, V> DictSlots[];
Expand Down
2 changes: 0 additions & 2 deletions Indicator.struct.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,10 @@ class Indicator;
struct ChartParams;

// Includes.
#include "Chart.struct.h"
#include "Chart.struct.tf.h"
#include "Data.struct.h"
#include "DateTime.struct.h"
#include "Indicator.enum.h"
#include "Indicator.struct.signal.h"
#include "SerializerNode.enum.h"

/**
Expand Down
8 changes: 5 additions & 3 deletions Indicator.struct.signal.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ struct IndicatorParams;

// Includes.
#include "Chart.struct.h"
#include "Indicator.struct.h"

/* Structure for indicator signals. */
struct IndicatorSignal {
Expand All @@ -55,14 +56,15 @@ struct IndicatorSignal {
unsigned int signals; // Store signals (@see: ENUM_INDICATOR_SIGNAL).

// Constructors.
void IndicatorSignal(int _signals = 0) : signals(_signals) {}
void IndicatorSignal(IndicatorDataEntry &_data[], IndicatorParams &_ip, ChartParams &_cp, int _m1 = 0, int _m2 = 0)
IndicatorSignal(int _signals = 0) : signals(_signals) {}
IndicatorSignal(ARRAY_REF(IndicatorDataEntry, _data), IndicatorParams &_ip, ChartParams &_cp, int _m1 = 0, int _m2 = 0)
: signals(0) {
CalcSignals(_data, _ip, _cp, _m1, _m2);
}
// Main methods.
// Calculate signal values.
void CalcSignals(IndicatorDataEntry &_data[], IndicatorParams &_ip, ChartParams &_cp, int _m1 = 0, int _m2 = 0) {
void CalcSignals(ARRAY_REF(IndicatorDataEntry, _data), IndicatorParams &_ip, ChartParams &_cp, int _m1 = 0,
int _m2 = 0) {
int _size = ArraySize(_data);
// INDICATOR_SIGNAL_CROSSOVER
bool _is_cross = false;
Expand Down
20 changes: 10 additions & 10 deletions Market.struct.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ struct MarketTimeForex : MqlDateTime {
MARKET_TIME_FOREX_HOURS_PACIFIC = MARKET_TIME_FOREX_HOURS_SYDNEY | MARKET_TIME_FOREX_HOURS_WELLINGTON,
};
// Constructors.
MarketTimeForex(datetime _time_gmt) { TimeToStruct(_time_gmt, this); }
MarketTimeForex(MqlDateTime &_dt_gmt) { this = _dt_gmt; }
MarketTimeForex(datetime _time_gmt) { TimeToStruct(_time_gmt, THIS_REF); }
MarketTimeForex(MqlDateTime &_dt_gmt) { THIS_REF = _dt_gmt; }
// State methods.
/* Getters */
bool CheckHours(unsigned int _hours_enums) {
Expand Down Expand Up @@ -137,13 +137,13 @@ struct MarketTimeForex : MqlDateTime {
case MARKET_TIME_FOREX_HOURS_WELLINGTON:
return 6;
case MARKET_TIME_FOREX_HOURS_AMERICA:
return fmax(GetCloseHour(MARKET_TIME_FOREX_HOURS_NEWYORK), GetCloseHour(MARKET_TIME_FOREX_HOURS_CHICAGO));
return MathMax(GetCloseHour(MARKET_TIME_FOREX_HOURS_NEWYORK), GetCloseHour(MARKET_TIME_FOREX_HOURS_CHICAGO));
case MARKET_TIME_FOREX_HOURS_ASIA:
return fmax(GetCloseHour(MARKET_TIME_FOREX_HOURS_TOKYO), GetCloseHour(MARKET_TIME_FOREX_HOURS_HONGKONG));
return MathMax(GetCloseHour(MARKET_TIME_FOREX_HOURS_TOKYO), GetCloseHour(MARKET_TIME_FOREX_HOURS_HONGKONG));
case MARKET_TIME_FOREX_HOURS_EUROPE:
return fmax(GetCloseHour(MARKET_TIME_FOREX_HOURS_LONDON), GetCloseHour(MARKET_TIME_FOREX_HOURS_FRANKFURT));
return MathMax(GetCloseHour(MARKET_TIME_FOREX_HOURS_LONDON), GetCloseHour(MARKET_TIME_FOREX_HOURS_FRANKFURT));
case MARKET_TIME_FOREX_HOURS_PACIFIC:
return fmax(GetCloseHour(MARKET_TIME_FOREX_HOURS_SYDNEY), GetCloseHour(MARKET_TIME_FOREX_HOURS_WELLINGTON));
return MathMax(GetCloseHour(MARKET_TIME_FOREX_HOURS_SYDNEY), GetCloseHour(MARKET_TIME_FOREX_HOURS_WELLINGTON));
default:
return 0;
}
Expand All @@ -168,13 +168,13 @@ struct MarketTimeForex : MqlDateTime {
case MARKET_TIME_FOREX_HOURS_WELLINGTON:
return 22;
case MARKET_TIME_FOREX_HOURS_AMERICA:
return fmin(GetOpenHour(MARKET_TIME_FOREX_HOURS_NEWYORK), GetOpenHour(MARKET_TIME_FOREX_HOURS_CHICAGO));
return MathMin(GetOpenHour(MARKET_TIME_FOREX_HOURS_NEWYORK), GetOpenHour(MARKET_TIME_FOREX_HOURS_CHICAGO));
case MARKET_TIME_FOREX_HOURS_ASIA:
return fmin(GetOpenHour(MARKET_TIME_FOREX_HOURS_TOKYO), GetOpenHour(MARKET_TIME_FOREX_HOURS_HONGKONG));
return MathMin(GetOpenHour(MARKET_TIME_FOREX_HOURS_TOKYO), GetOpenHour(MARKET_TIME_FOREX_HOURS_HONGKONG));
case MARKET_TIME_FOREX_HOURS_EUROPE:
return fmin(GetOpenHour(MARKET_TIME_FOREX_HOURS_LONDON), GetOpenHour(MARKET_TIME_FOREX_HOURS_FRANKFURT));
return MathMin(GetOpenHour(MARKET_TIME_FOREX_HOURS_LONDON), GetOpenHour(MARKET_TIME_FOREX_HOURS_FRANKFURT));
case MARKET_TIME_FOREX_HOURS_PACIFIC:
return fmin(GetOpenHour(MARKET_TIME_FOREX_HOURS_SYDNEY), GetOpenHour(MARKET_TIME_FOREX_HOURS_WELLINGTON));
return MathMin(GetOpenHour(MARKET_TIME_FOREX_HOURS_SYDNEY), GetOpenHour(MARKET_TIME_FOREX_HOURS_WELLINGTON));
default:
return 0;
}
Expand Down
6 changes: 5 additions & 1 deletion Order.enum.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@ enum ENUM_ORDER_REASON {
ORDER_REASON_TP, // The order was placed as a result of Take Profit activation.
ORDER_REASON_WEB, // The order was placed from a web platform.
};
#else
#endif

#ifndef __MQ4__
/**
* Enumeration for order selection type.
*
Expand Down Expand Up @@ -229,6 +231,8 @@ enum ENUM_POSITION_PROPERTY_DOUBLE {
POSITION_VOLUME, // Position volume (double).
};

#define POSITION_TICKET

/**
* Returns integer type of the position property.
*
Expand Down
10 changes: 5 additions & 5 deletions Order.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ class Order : public SymbolInfo {
// and only for the symbols with Market or Exchange execution.
// In case of partial filling a market or limit order with remaining volume is not canceled but processed further.
ENUM_ORDER_TYPE_FILLING _result = ORDER_FILLING_RETURN;
const long _filling_mode = SymbolInfo::GetFillingMode(_symbol);
const long _filling_mode = SymbolInfoStatic::GetFillingMode(_symbol);
if ((_filling_mode & SYMBOL_FILLING_IOC) == SYMBOL_FILLING_IOC) {
// Execute a deal with the volume maximally available in the market within that indicated in the order.
// In case the order cannot be filled completely, the available volume of the order will be filled, and the
Expand Down Expand Up @@ -369,8 +369,8 @@ class Order : public SymbolInfo {
*/
static ENUM_ORDER_TYPE_FILLING GetOrderFilling(const string _symbol, const long _type) {
const ENUM_SYMBOL_TRADE_EXECUTION _exe_mode =
(ENUM_SYMBOL_TRADE_EXECUTION)SymbolInfo::SymbolInfoInteger(_symbol, SYMBOL_TRADE_EXEMODE);
const long _filling_mode = SymbolInfo::GetFillingMode(_symbol);
(ENUM_SYMBOL_TRADE_EXECUTION)SymbolInfoStatic::SymbolInfoInteger(_symbol, SYMBOL_TRADE_EXEMODE);
const long _filling_mode = SymbolInfoStatic::GetFillingMode(_symbol);
return ((_filling_mode == 0 || (_type >= ORDER_FILLING_RETURN) || ((_filling_mode & (_type + 1)) != _type + 1))
? (((_exe_mode == SYMBOL_TRADE_EXECUTION_EXCHANGE) || (_exe_mode == SYMBOL_TRADE_EXECUTION_INSTANT))
? ORDER_FILLING_RETURN
Expand Down Expand Up @@ -2638,7 +2638,7 @@ class Order : public SymbolInfo {
* @return
* Returns true when the condition is met.
*/
bool CheckCondition(ENUM_ORDER_CONDITION _cond, DataParamEntry REF(_args)[]) {
bool CheckCondition(ENUM_ORDER_CONDITION _cond, ARRAY_REF(DataParamEntry, _args)) {
switch (_cond) {
case ORDER_COND_IN_LOSS:
return GetProfit() < 0;
Expand Down Expand Up @@ -2726,7 +2726,7 @@ class Order : public SymbolInfo {
* @return
* Returns true when the condition is met.
*/
bool ExecuteAction(ENUM_ORDER_ACTION _action, DataParamEntry REF(_args)[]) {
bool ExecuteAction(ENUM_ORDER_ACTION _action, ARRAY_REF(DataParamEntry, _args)) {
switch (_action) {
case ORDER_ACTION_CLOSE:
switch (oparams.dummy) {
Expand Down
10 changes: 5 additions & 5 deletions Order.struct.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ struct OrderParams {
color color_arrow; // Color of the opening arrow on the chart.
unsigned short refresh_rate; // How often to refresh order values (in secs).
ENUM_ORDER_CONDITION cond_close; // Close condition.
DataParamEntry cond_close_args[]; // Close condition argument.
ARRAY(DataParamEntry, cond_close_args); // Close condition argument.
// Special struct methods.
OrderParams() : dummy(false), color_arrow(clrNONE), refresh_rate(10), cond_close(ORDER_COND_NONE){};
OrderParams(bool _dummy) : dummy(_dummy), color_arrow(clrNONE), refresh_rate(10), cond_close(ORDER_COND_NONE){};
Expand Down Expand Up @@ -105,7 +105,7 @@ struct OrderParams {
}
SetUserError(ERR_INVALID_PARAMETER);
}
void SetConditionClose(ENUM_ORDER_CONDITION _cond, DataParamEntry REF(_args)[]) {
void SetConditionClose(ENUM_ORDER_CONDITION _cond, ARRAY_REF(DataParamEntry, _args)) {
cond_close = _cond;
ArrayResize(cond_close_args, ArraySize(_args));
for (int i = 0; i < ArraySize(_args); i++) {
Expand Down Expand Up @@ -441,7 +441,7 @@ struct OrderData {
}
SetUserError(ERR_INVALID_PARAMETER);
}
void ProcessLastError() { last_error = fmax(last_error, Terminal::GetLastError()); }
void ProcessLastError() { last_error = MathMax(last_error, (unsigned int)Terminal::GetLastError()); }
void ResetError() {
ResetLastError();
last_error = ERR_NO_ERROR;
Expand Down Expand Up @@ -784,7 +784,7 @@ struct OrderStatic {
* Usage: SerializerConverter::FromObject(MqlTradeRequestProxy(_request)).ToString<SerializerJson>());
*/
struct MqlTradeRequestProxy : MqlTradeRequest {
MqlTradeRequestProxy(MqlTradeRequest &r) { this = r; }
MqlTradeRequestProxy(MqlTradeRequest &r) { THIS_REF = r; }

SerializerNodeType Serialize(Serializer &s) {
s.PassEnum(THIS_REF, "action", action);
Expand Down Expand Up @@ -814,7 +814,7 @@ struct MqlTradeRequestProxy : MqlTradeRequest {
* Usage: SerializerConverter::FromObject(MqlTradeResultProxy(_request)).ToString<SerializerJson>());
*/
struct MqlTradeResultProxy : MqlTradeResult {
MqlTradeResultProxy(MqlTradeResult &r) { this = r; }
MqlTradeResultProxy(MqlTradeResult &r) { THIS_REF = r; }

SerializerNodeType Serialize(Serializer &s) {
s.Pass(THIS_REF, "retcode", retcode);
Expand Down
56 changes: 28 additions & 28 deletions SerializerJson.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -64,27 +64,27 @@ class SerializerJson {

repr += ident;

if (_node.GetKeyParam() != NULL && _node.GetKeyParam().AsString(false, false) != "")
repr += _node.GetKeyParam().AsString(false, true) + ":" + (trimWhitespaces ? "" : " ");
if (PTR_ATTRIB(_node, GetKeyParam()) != NULL && PTR_ATTRIB(PTR_ATTRIB(_node, GetKeyParam()), AsString(false, false)) != "")
repr += PTR_ATTRIB(PTR_ATTRIB(_node, GetKeyParam()), AsString(false, true)) + ":" + (trimWhitespaces ? "" : " ");

if (_node.GetValueParam() != NULL) repr += _node.GetValueParam().AsString(false, true);
if (PTR_ATTRIB(_node, GetValueParam()) != NULL) repr += PTR_ATTRIB(PTR_ATTRIB(_node, GetValueParam()), AsString(false, true));

switch (_node.GetType()) {
switch (PTR_ATTRIB(_node, GetType())) {
case SerializerNodeObject:
repr += "{" + (trimWhitespaces ? "" : "\n");
repr += string("{") + (trimWhitespaces ? "" : "\n");
break;
case SerializerNodeArray:
repr += "[" + (trimWhitespaces ? "" : "\n");
repr += string("[") + (trimWhitespaces ? "" : "\n");
break;
}

if (_node.HasChildren()) {
for (unsigned int j = 0; j < _node.NumChildren(); ++j) {
repr += _node.GetChild(j).ToString(trimWhitespaces, indentSize, indent + 1);
if (PTR_ATTRIB(_node, HasChildren())) {
for (unsigned int j = 0; j < PTR_ATTRIB(_node, NumChildren()); ++j) {
repr += PTR_ATTRIB(PTR_ATTRIB(_node, GetChild(j)), ToString(trimWhitespaces, indentSize, indent + 1));
}
}

switch (_node.GetType()) {
switch (PTR_ATTRIB(_node, GetType())) {
case SerializerNodeObject:
repr += ident + "}";
break;
Expand All @@ -93,7 +93,7 @@ class SerializerJson {
break;
}

if (!_node.IsLast()) repr += ",";
if (!PTR_ATTRIB(_node, IsLast())) repr += ",";

// Appending newline only when inside the root node.
if (indent != 0) repr += (trimWhitespaces ? "" : "\n");
Expand Down Expand Up @@ -169,17 +169,17 @@ class SerializerJson {
if (ch == '"') {
extracted = ExtractString(data, i + 1);

if (extracted == NULL) {
if (extracted == "") {
return GracefulReturn("Unexpected end of file when parsing string", i, root, key);
}
if (expectingKey) {
key = SerializerNodeParam::FromString(extracted);
expectingKey = false;
expectingSemicolon = true;
} else if (expectingValue) {
current.AddChild(new SerializerNode(
current.GetType() == SerializerNodeObject ? SerializerNodeObjectProperty : SerializerNodeArrayItem,
current, key, SerializerNodeParam::FromString(extracted)));
PTR_ATTRIB(current, AddChild(new SerializerNode(
PTR_ATTRIB(current, GetType()) == SerializerNodeObject ? SerializerNodeObjectProperty : SerializerNodeArrayItem,
current, key, SerializerNodeParam::FromString(extracted))));

#ifdef __debug__
Print("SerializerJson: Value \"" + extracted + "\" for key " +
Expand Down Expand Up @@ -212,7 +212,7 @@ class SerializerJson {

if (!root) root = node;

if (expectingValue) current.AddChild(node);
if (expectingValue) PTR_ATTRIB(current, AddChild(node));

current = node;

Expand All @@ -221,7 +221,7 @@ class SerializerJson {
expectingKey = ch2 != '}';
key = NULL;
} else if (ch == '}') {
if (expectingKey || expectingValue || current.GetType() != SerializerNodeObject) {
if (expectingKey || expectingValue || PTR_ATTRIB(current, GetType()) != SerializerNodeObject) {
return GracefulReturn("Unexpected end of object", i, root, key);
}

Expand All @@ -231,7 +231,7 @@ class SerializerJson {
: "<none>"));
#endif

current = current.GetParent();
current = PTR_ATTRIB(current, GetParent());
expectingValue = false;
} else if (ch == '[') {
#ifdef __debug__
Expand All @@ -246,7 +246,7 @@ class SerializerJson {

if (!root) root = node;

if (expectingValue) current.AddChild(node);
if (expectingValue) PTR_ATTRIB(current, AddChild(node));

current = node;
expectingValue = ch2 != ']';
Expand All @@ -257,11 +257,11 @@ class SerializerJson {
Print("SerializerJson: Leaving list for key " + (key != NULL ? ("\"" + key.ToString() + "\"") : "<none>"));
#endif

if (expectingKey || expectingValue || current.GetType() != SerializerNodeArray) {
if (expectingKey || expectingValue || PTR_ATTRIB(current, GetType()) != SerializerNodeArray) {
return GracefulReturn("Unexpected end of array", i, root, key);
}

current = current.GetParent();
current = PTR_ATTRIB(current, GetParent());
expectingValue = false;
} else if (ch >= '0' && ch <= '9') {
if (!expectingValue) {
Expand All @@ -279,9 +279,9 @@ class SerializerJson {
(key != NULL ? ("\"" + key.ToString() + "\"") : "<none>"));
#endif

current.AddChild(new SerializerNode(
current.GetType() == SerializerNodeObject ? SerializerNodeObjectProperty : SerializerNodeArrayItem, current,
key, value));
PTR_ATTRIB(current, AddChild(new SerializerNode(
PTR_ATTRIB(current, GetType()) == SerializerNodeObject ? SerializerNodeObjectProperty : SerializerNodeArrayItem, current,
key, value)));
expectingValue = false;

// Skipping value.
Expand All @@ -302,9 +302,9 @@ class SerializerJson {
// Skipping value.
i += ch == 't' ? 3 : 4;

current.AddChild(new SerializerNode(
current.GetType() == SerializerNodeObject ? SerializerNodeObjectProperty : SerializerNodeArrayItem, current,
key, value));
PTR_ATTRIB(current, AddChild(new SerializerNode(
PTR_ATTRIB(current, GetType()) == SerializerNodeObject ? SerializerNodeObjectProperty : SerializerNodeArrayItem, current,
key, value)));
expectingValue = false;

// We don't want to delete it twice.
Expand All @@ -314,7 +314,7 @@ class SerializerJson {
return GracefulReturn("Unexpected comma", i, root, key);
}

if (current.GetType() == SerializerNodeObject)
if (PTR_ATTRIB(current, GetType()) == SerializerNodeObject)
expectingKey = true;
else
expectingValue = true;
Expand Down
Loading

0 comments on commit 178e8c8

Please sign in to comment.