Skip to content

Commit

Permalink
WIP. Code is now compiling for a FX31337-wasm's tests/js/TestRunner.js
Browse files Browse the repository at this point in the history
  • Loading branch information
nseam committed Jan 20, 2023
1 parent db0b8a0 commit f4c5d18
Show file tree
Hide file tree
Showing 40 changed files with 648 additions and 473 deletions.
9 changes: 5 additions & 4 deletions Account/AccountMt.h
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ class AccountMt {
*/
bool IsFreeMargin(ENUM_ORDER_TYPE _cmd, double size_of_lot, string _symbol = NULL) {
bool _res = true;
double margin = AccountFreeMarginCheck(_symbol, _cmd, size_of_lot);
// double margin = AccountFreeMarginCheck(_symbol, _cmd, size_of_lot);
if (GetLastError() == 134 /* NOT_ENOUGH_MONEY */) _res = false;
return (_res);
}
Expand Down Expand Up @@ -618,9 +618,10 @@ class AccountMt {
return StringFormat(
"Type: %s, Server/Company/Name: %s/%s/%s, Currency: %s, Balance: %g, Credit: %g, Equity: %g, Profit: %g, "
"Margin Used/Free/Avail: %g(%.1f%%)/%g/%g, Orders limit: %g: Leverage: 1:%d, StopOut Level: %d (Mode: %d)",
GetType(), GetServerName(), GetCompanyName(), GetAccountName(), GetCurrency(), GetBalance(), GetCredit(),
GetEquity(), GetProfit(), GetMarginUsed(), GetMarginUsedInPct(), GetMarginFree(), GetMarginAvail(),
GetLimitOrders(), GetLeverage(), GetStopoutLevel(), GetStopoutMode());
C_STR(GetType()), C_STR(GetServerName()), C_STR(GetCompanyName()), C_STR(GetAccountName()),
C_STR(GetCurrency()), GetBalance(), GetCredit(), GetEquity(), GetProfit(), GetMarginUsed(),
GetMarginUsedInPct(), GetMarginFree(), GetMarginAvail(), GetLimitOrders(), GetLeverage(), GetStopoutLevel(),
GetStopoutMode());
}

/**
Expand Down
4 changes: 3 additions & 1 deletion Array.extern.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ int ArraySize(const ARRAY_REF(T, _array)) {
}

template <typename T, int size>
constexpr int ArraySize(const T REF(_array)[size]);
constexpr int ArraySize(const T REF(_array)[size]) {
return size;
}

template <typename T>
int ArrayResize(ARRAY_REF(T, _array), int _new_size, int _reserve_size = 0) {
Expand Down
6 changes: 3 additions & 3 deletions Array.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -760,7 +760,7 @@ static int GetLowestArrDoubleValue(double& arr[][], int key) {
template <typename X>
static void ArrayStore(ARRAY_REF(X, array), int index, X value, int reserve_size = 0) {
if (index >= ArraySize(array)) {
ArrayResize(array, MathMax(index + 1, ArraySize(array)), reserve_size);
::ArrayResize(array, MathMax(index + 1, ArraySize(array)), reserve_size);
} else if (index < 0) {
Print("Index cannot be negative! " + IntegerToString(index) + " passed.");
DebugBreak();
Expand All @@ -772,11 +772,11 @@ static int GetLowestArrDoubleValue(double& arr[][], int key) {

template <typename X>
void ArrayPush(ARRAY_REF(X, array), X value) {
ArrayResize(Array::ArraySize(array) + 1);
::ArrayResize(array, Array::ArraySize(array) + 1);
array[ArraySize(array) - 1] = value;
}
template <typename X>
void ArrayPushObject(ARRAY_REF(X, array), X& value) {
ArrayResize(array, Array::ArraySize(array) + 1);
::ArrayResize(array, Array::ArraySize(array) + 1);
array[Array::ArraySize(array) - 1] = value;
}
4 changes: 2 additions & 2 deletions Bar.struct.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ struct BarOHLC
datetime time;
double open, high, low, close;
// Struct constructor.
BarOHLC() : open(0), high(0), low(0), close(0), time(0){};
BarOHLC() : time(0), open(0), high(0), low(0), close(0){};
BarOHLC(double _open, double _high, double _low, double _close, datetime _time = 0)
: time(_time), open(_open), high(_high), low(_low), close(_close) {
if (_time == (datetime)0) {
Expand Down Expand Up @@ -259,5 +259,5 @@ struct BarEntry {
s.PassStruct(THIS_REF, "ohlc", ohlc, SERIALIZER_FIELD_FLAG_DYNAMIC);
return SerializerNodeObject;
}
string ToCSV() { return StringFormat("%s", ohlc.ToCSV()); }
string ToCSV() { return StringFormat("%s", C_STR(ohlc.ToCSV())); }
};
6 changes: 3 additions & 3 deletions BufferStruct.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ class BufferStruct : public DictStruct<long, TStruct> {
/**
* Constructor.
*/
BufferStruct() : max(INT_MIN), min(INT_MAX) { THIS_ATTR SetOverflowListener(BufferStructOverflowListener, 10); }
BufferStruct(BufferStruct& _right) : max(INT_MIN), min(INT_MAX) {
BufferStruct() : min(INT_MAX), max(INT_MIN) { THIS_ATTR SetOverflowListener(BufferStructOverflowListener, 10); }
BufferStruct(BufferStruct& _right) : min(INT_MAX), max(INT_MIN) {
this = _right;
THIS_ATTR SetOverflowListener(BufferStructOverflowListener, 10);
}
Expand All @@ -74,7 +74,7 @@ class BufferStruct : public DictStruct<long, TStruct> {
*/
void Add(TStruct& _value, long _dt = 0) {
_dt = _dt > 0 ? _dt : (long)TimeCurrent();
if (Set(_dt, _value)) {
if (THIS_ATTR Set(_dt, _value)) {
min = _dt < min ? _dt : min;
max = _dt > max ? _dt : max;
}
Expand Down
2 changes: 2 additions & 0 deletions Chart.struct.static.h
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,8 @@ struct ChartStatic {
ChartStatic::iClose(_symbol, _tf, _shift) + ChartStatic::iClose(_symbol, _tf, _shift)) /
4;
break;
default:
break; // FINAL_APPLIED_PRICE_ENTRY.
}
return _result;
}
Expand Down
69 changes: 60 additions & 9 deletions Chart.struct.tf.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ struct ChartTf {
public:
// Constructors.
ChartTf(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : tf(_tf), tfi(ChartTf::TfToIndex(_tf)){};
ChartTf(ENUM_TIMEFRAMES_INDEX _tfi) : tfi(_tfi), tf(ChartTf::IndexToTf(_tfi)){};
ChartTf(ENUM_TIMEFRAMES_INDEX _tfi) : tf(ChartTf::IndexToTf(_tfi)), tfi(_tfi){};
ChartTf(const ChartTf& _ctf) : tf(_ctf.tf), tfi(_ctf.tfi){};

// Struct operators.
Expand Down Expand Up @@ -186,6 +186,65 @@ struct ChartTf {
return PERIOD_CURRENT;
}

/**
* Convert timeframe period to seconds.
*
* @param
* _tf ENUM_TIMEFRAMES Specify timeframe enum.
*/
static unsigned int TfToSeconds(const ENUM_TIMEFRAMES _tf) {
switch (_tf) {
case PERIOD_CURRENT:
return TfToSeconds(Period());
case PERIOD_M1: // 1 minute.
return 60;
case PERIOD_M2: // 2 minutes (non-standard).
return 60 * 2;
case PERIOD_M3: // 3 minutes (non-standard).
return 60 * 3;
case PERIOD_M4: // 4 minutes (non-standard).
return 60 * 4;
case PERIOD_M5: // 5 minutes.
return 60 * 5;
case PERIOD_M6: // 6 minutes (non-standard).
return 60 * 6;
case PERIOD_M10: // 10 minutes (non-standard).
return 60 * 10;
case PERIOD_M12: // 12 minutes (non-standard).
return 60 * 12;
case PERIOD_M15: // 15 minutes.
return 60 * 15;
case PERIOD_M20: // 20 minutes (non-standard).
return 60 * 20;
case PERIOD_M30: // 30 minutes.
return 60 * 30;
case PERIOD_H1: // 1 hour.
return 60 * 60;
case PERIOD_H2: // 2 hours (non-standard).
return 60 * 60 * 2;
case PERIOD_H3: // 3 hours (non-standard).
return 60 * 60 * 3;
case PERIOD_H4: // 4 hours.
return 60 * 60 * 4;
case PERIOD_H6: // 6 hours (non-standard).
return 60 * 60 * 6;
case PERIOD_H8: // 8 hours (non-standard).
return 60 * 60 * 8;
case PERIOD_H12: // 12 hours (non-standard).
return 60 * 60 * 12;
case PERIOD_D1: // Daily.
return 60 * 60 * 24;
case PERIOD_W1: // Weekly.
return 60 * 60 * 24 * 7;
case PERIOD_MN1: // Monthly.
return 60 * 60 * 24 * 30;
default:
break;
}
SetUserError(ERR_INVALID_PARAMETER);
return 0;
}

/**
* Convert period to proper chart timeframe value.
*
Expand Down Expand Up @@ -274,14 +333,6 @@ struct ChartTf {
*/
static double TfToMinutes(const ENUM_TIMEFRAMES _tf) { return ChartTf::TfToSeconds(_tf) / 60; }

/**
* Convert timeframe period to seconds.
*
* @param
* _tf ENUM_TIMEFRAMES Specify timeframe enum.
*/
static unsigned int TfToSeconds(const ENUM_TIMEFRAMES _tf) { return ChartTf::TfToSeconds(_tf); }

/**
* Returns text representation of the timeframe constant.
*
Expand Down
11 changes: 5 additions & 6 deletions Collection.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
/**
* Class to deal with collection of objects.
*/
template<typename X>
template <typename X>
class Collection {
protected:
// Variables.
Expand All @@ -45,8 +45,7 @@ class Collection {
Collection() {}
Collection(string _name) : name(_name) {}
Collection(void *_obj) { Add(_obj); }
~Collection() {
}
~Collection() {}

/* Setters */

Expand Down Expand Up @@ -99,7 +98,7 @@ class Collection {
/**
* Returns pointer to the current object.
*/
X* GetCurrentItem() { return data[index].Ptr() != NULL ? data[index].Ptr() : NULL; }
X *GetCurrentItem() { return data[index].Ptr() != NULL ? data[index].Ptr() : NULL; }

/**
* Returns ID of the current object.
Expand Down Expand Up @@ -160,7 +159,7 @@ class Collection {
X *_object = GetSize() > 0 ? data[0].Ptr() : NULL;
for (i = 0; i < ArraySize(data); i++) {
double _weight = data[i].Ptr().GetWeight();
if (_weight < _object.GetWeight()) {
if (_weight < _object PTR_DEREF GetWeight()) {
_object = data[i].Ptr();
}
}
Expand All @@ -175,7 +174,7 @@ class Collection {
X *_object = GetSize() > 0 ? data[0].Ptr() : NULL;
for (i = 0; i < ArraySize(data); i++) {
double _weight = data[i].Ptr().GetWeight();
if (_weight > _object.GetWeight()) {
if (_weight > _object PTR_DEREF GetWeight()) {
_object = data[i].Ptr();
}
}
Expand Down
28 changes: 28 additions & 0 deletions Convert.basic.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,13 @@ class ConvertBasic {
#endif
}

template <typename X>
static X StringTo(string _value) {
X _out;
StringToType(_value, _out);
return _out;
}

static void BoolToType(bool _value, bool& _out) { _out = _value; }
static void BoolToType(bool _value, char& _out) { _out = (char)_value; }
static void BoolToType(bool _value, unsigned char& _out) { _out = (unsigned char)_value; }
Expand All @@ -119,6 +126,13 @@ class ConvertBasic {
static void BoolToType(bool _value, color& _out) { _out = 0; }
static void BoolToType(bool _value, datetime& _out) {}

template <typename X>
static X BoolTo(bool _value) {
X _out;
BoolToType(_value, _out);
return _out;
}

static void LongToType(long _value, bool& _out) { _out = (bool)_value; }
static void LongToType(long _value, char& _out) { _out = (char)_value; }
static void LongToType(long _value, unsigned char& _out) { _out = (unsigned char)_value; }
Expand All @@ -134,6 +148,13 @@ class ConvertBasic {
static void LongToType(long _value, color& _out) { _out = 0; }
static void LongToType(long _value, datetime& _out) {}

template <typename X>
static X LongTo(long _value) {
X _out;
LongToType(_value, _out);
return _out;
}

static void DoubleToType(double _value, bool& _out) { _out = (bool)_value; }
static void DoubleToType(double _value, char& _out) { _out = (char)_value; }
static void DoubleToType(double _value, unsigned char& _out) { _out = (unsigned char)_value; }
Expand All @@ -148,4 +169,11 @@ class ConvertBasic {
static void DoubleToType(double _value, string& _out) { _out = _value ? "1" : "0"; }
static void DoubleToType(double _value, color& _out) { _out = 0; }
static void DoubleToType(double _value, datetime& _out) {}

template <typename X>
static X DoubleTo(double _value) {
X _out;
DoubleToType(_value, _out);
return _out;
}
};
8 changes: 4 additions & 4 deletions Dict.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ class Dict : public DictBase<K, V> {

if (!slot) return (V)NULL;

return slot.value;
return slot PTR_DEREF value;
}

/**
Expand All @@ -143,7 +143,7 @@ class Dict : public DictBase<K, V> {
return _default;
}

return slot.value;
return slot PTR_DEREF value;
}

/**
Expand All @@ -159,7 +159,7 @@ class Dict : public DictBase<K, V> {
return _empty;
}

return slot.value;
return slot PTR_DEREF value;
}

/**
Expand All @@ -174,7 +174,7 @@ class Dict : public DictBase<K, V> {

if (!slot) return false;

return slot.value == value;
return slot PTR_DEREF value == value;
}

/**
Expand Down
20 changes: 18 additions & 2 deletions DictBase.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,15 @@ class DictBase {

if (GetMode() == DictModeList) {
// In list mode value index is the slot index.
position = (int)key;
#ifndef __MQL__
if constexpr (std::is_same<K, int>::value) {
#endif
position = (int)key;
#ifndef __MQL__
} else {
RUNTIME_ERROR("List mode for a dict could only work if Dict's key type is an integer!");
}
#endif
} else {
position = Hash(key) % ArraySize(_DictSlots_ref.DictSlots);
}
Expand All @@ -203,7 +211,15 @@ class DictBase {

if (_DictSlots_ref.DictSlots[position].IsUsed()) {
if (GetMode() == DictModeList) {
_should_be_removed = position == (unsigned int)key;
#ifndef __MQL__
if constexpr (std::is_same<K, int>::value) {
#endif
_should_be_removed = position == (unsigned int)key;
#ifndef __MQL__
} else {
RUNTIME_ERROR("List mode for a dict could only work if Dict's key type is an integer!");
}
#endif
} else {
_should_be_removed =
_DictSlots_ref.DictSlots[position].HasKey() && _DictSlots_ref.DictSlots[position].key == key;
Expand Down
15 changes: 0 additions & 15 deletions DictStruct.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -123,21 +123,6 @@ class DictStruct : public DictBase<K, V> {
*/
bool operator+=(V& value) { return Push(value); }

/**
* Inserts value using hashless key.
*
* @todo Get rid of this method.
*/
#ifdef __MQL__
template <>
#endif
bool Push(Dynamic* value) {
V ptr = value;

if (!InsertInto(THIS_ATTR _DictSlots_ref, ptr)) return false;
return true;
}

/**
* Inserts or replaces value for a given key.
*/
Expand Down
8 changes: 4 additions & 4 deletions Indicator/Indicator.enum.h
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,10 @@ enum ENUM_APPLIED_VOLUME { VOLUME_TICK = 0, VOLUME_REAL = 1 };

// Indicator flags.
enum ENUM_INDI_FLAGS {
INDI_FLAG_INDEXABLE_BY_SHIFT, // Indicator supports indexation by shift.
INDI_FLAG_INDEXABLE_BY_TIMESTAMP, // Indicator supports indexation by shift.
INDI_FLAG_SOURCE_REQ_INDEXABLE_BY_SHIFT, // Source indicator must be indexable by shift.
INDI_FLAG_SOURCE_REQ_INDEXABLE_BY_TIMESTAMP // Source indicator must be indexable by timestamp.
INDI_FLAG_INDEXABLE_BY_SHIFT = 1 << 0, // Indicator supports indexation by shift.
INDI_FLAG_INDEXABLE_BY_TIMESTAMP = 1 << 1, // Indicator supports indexation by shift.
INDI_FLAG_SOURCE_REQ_INDEXABLE_BY_SHIFT = 1 << 2, // Source indicator must be indexable by shift.
INDI_FLAG_SOURCE_REQ_INDEXABLE_BY_TIMESTAMP = 1 << 3 // Source indicator must be indexable by timestamp.
};

// Flags indicating which data sources are required to be provided in order indicator to work.
Expand Down
Loading

0 comments on commit f4c5d18

Please sign in to comment.