Skip to content

Commit

Permalink
WIP. Refactoring of MQL code to be compatible with C++.
Browse files Browse the repository at this point in the history
  • Loading branch information
nseam committed Jun 2, 2021
1 parent 5a93edf commit e00601c
Show file tree
Hide file tree
Showing 24 changed files with 695 additions and 563 deletions.
9 changes: 7 additions & 2 deletions Bar.struct.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,16 @@
// Includes.
#include "Bar.enum.h"
#include "Chart.enum.h"
#include "ISerializable.h"
#include "Serializer.mqh"
#include "SerializerNode.enum.h"

/* Struct for storing OHLC values. */
struct BarOHLC {
struct BarOHLC
#ifndef __MQL__
: public ISerializable
#endif
{
datetime time;
float open, high, low, close;
// Struct constructor.
Expand Down Expand Up @@ -231,7 +236,7 @@ struct BarEntry {
// Serializers.
void SerializeStub(int _n1 = 1, int _n2 = 1, int _n3 = 1, int _n4 = 1, int _n5 = 1) {}
SerializerNodeType Serialize(Serializer &s) {
s.PassStruct(this, "ohlc", ohlc, SERIALIZER_FIELD_FLAG_DYNAMIC);
s.PassStruct(THIS_REF, "ohlc", ohlc, SERIALIZER_FIELD_FLAG_DYNAMIC);
return SerializerNodeObject;
}
string ToCSV() { return StringFormat("%s", ohlc.ToCSV()); }
Expand Down
38 changes: 19 additions & 19 deletions Chart.struct.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,25 +126,7 @@ struct ChartStatic {
#endif
}

/**
* Wrapper struct that returns open time of each bar of the current chart.
*
* @see: https://docs.mql4.com/predefined/time
*/
struct ChartBarTime {
protected:
string symbol;
ENUM_TIMEFRAMES tf;

public:
ChartBarTime() : symbol(_Symbol), tf(PERIOD_CURRENT) {}
datetime operator[](const int _shift) const { return Get(symbol, tf, _shift); }
static datetime Get(const string _symbol, const ENUM_TIMEFRAMES _tf, const int _shift) {
return ChartStatic::iTime(_symbol, _tf, _shift);
}
};

/**
/**
* Wrapper struct that returns close prices of each bar of the current chart.
*
* @see: https://docs.mql4.com/predefined/close
Expand Down Expand Up @@ -460,3 +442,21 @@ struct ChartPriceOpen {
*/
static long ID() { return ::ChartID(); }
};

/**
* Wrapper struct that returns open time of each bar of the current chart.
*
* @see: https://docs.mql4.com/predefined/time
*/
struct ChartBarTime {
protected:
string symbol;
ENUM_TIMEFRAMES tf;

public:
ChartBarTime() : symbol(_Symbol), tf(PERIOD_CURRENT) {}
datetime operator[](const int _shift) const { return Get(symbol, tf, _shift); }
static datetime Get(const string _symbol, const ENUM_TIMEFRAMES _tf, const int _shift) {
return ChartStatic::iTime(_symbol, _tf, _shift);
}
};
2 changes: 2 additions & 0 deletions Chart.struct.tf.h
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,8 @@ struct ChartTf {
SerializerNodeType Serialize(Serializer& s);
};

#include "Serializer.mqh"

/* Method to serialize ChartTf structure. */
SerializerNodeType ChartTf::Serialize(Serializer& s) {
s.PassEnum(THIS_REF, "tf", tf);
Expand Down
55 changes: 54 additions & 1 deletion Data.struct.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ struct MqlParam;

// Includes.
#include "Data.enum.h"
#include "Serializer.mqh"
#include "SerializerNode.enum.h"
#include "SymbolInfo.struct.h"

#ifndef __MQL__
/**
Expand All @@ -54,6 +54,56 @@ struct MqlParam {
double double_value; // Field to store a double type.
string string_value; // Field to store a string type.
};
MqlParam() { type = (ENUM_DATATYPE)WRONG_VALUE; }

MqlParam(const MqlParam &_r) { THIS_REF = _r; }

MqlParam &operator=(const MqlParam &_r) {
type = _r.type;
switch (type) {
case TYPE_BOOL:
case TYPE_CHAR:
case TYPE_INT:
case TYPE_LONG:
case TYPE_SHORT:
case TYPE_UINT:
case TYPE_ULONG:
case TYPE_USHORT:
case TYPE_UCHAR:
case TYPE_COLOR:
case TYPE_DATETIME:
integer_value = _r.integer_value;
break;
case TYPE_DOUBLE:
case TYPE_FLOAT:
double_value = _r.double_value;
break;
case TYPE_STRING:
string_value = _r.string_value;
}
}

MqlParam(long _value) {
type = ENUM_DATATYPE::TYPE_LONG;
integer_value = _value;
}
MqlParam(int _value) {
type = ENUM_DATATYPE::TYPE_INT;
integer_value = _value;
}
MqlParam(bool _value) {
type = ENUM_DATATYPE::TYPE_BOOL;
integer_value = _value ? 1 : 0;
}
MqlParam(float _value) {
type = ENUM_DATATYPE::TYPE_FLOAT;
double_value = (double)_value;
}
MqlParam(double _value) {
type = ENUM_DATATYPE::TYPE_DOUBLE;
double_value = _value;
}
~MqlParam() {}
};
#endif

Expand All @@ -66,6 +116,7 @@ struct MqlParam {
*/
struct DataParamEntry : public MqlParam {
public:
DataParamEntry(const DataParamEntry &_r) { ((MqlParam &)THIS_REF) = ((MqlParam &)_r); }
// Struct operators.
void operator=(const bool _value) {
type = TYPE_BOOL;
Expand Down Expand Up @@ -126,6 +177,8 @@ struct DataParamEntry : public MqlParam {
SerializerNodeType Serialize(Serializer &s);
};

#include "Serializer.mqh"

/* Method to serialize DataParamEntry struct. */
SerializerNodeType DataParamEntry::Serialize(Serializer &s) {
s.PassEnum(THIS_REF, "type", type, SERIALIZER_FIELD_FLAG_HIDDEN);
Expand Down
2 changes: 1 addition & 1 deletion DateTime.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ class DateTime {
* @return
* Returns true when the condition is met.
*/
static bool CheckCondition(ENUM_DATETIME_CONDITION _cond, DataParamEntry REF(_args)[]) {
static bool CheckCondition(ENUM_DATETIME_CONDITION _cond, ARRAY_REF(DataParamEntry, _args)) {
switch (_cond) {
case DATETIME_COND_IS_PEAK_HOUR:
return DateTimeStatic::IsPeakHour();
Expand Down
Loading

0 comments on commit e00601c

Please sign in to comment.