Skip to content

Commit

Permalink
C++ compatibility fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
nseam committed Sep 6, 2024
1 parent 999de5f commit 4d428e7
Show file tree
Hide file tree
Showing 14 changed files with 104 additions and 96 deletions.
13 changes: 7 additions & 6 deletions EA.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ class EA : public Taskable<DataParamEntry> {
*/
void InitTask() {
// Add and process init task.
TaskObject<EA, EA> _taskobj_init(eparams.GetStruct<TaskEntry>(STRUCT_ENUM(EAParams, EA_PARAM_STRUCT_TASK_ENTRY)),
TaskEntry _task_entry(eparams.GetStruct<TaskEntry>(STRUCT_ENUM(EAParams, EA_PARAM_STRUCT_TASK_ENTRY)));
TaskObject<EA, EA> _taskobj_init(_task_entry,
THIS_PTR, THIS_PTR);
estate.Set(STRUCT_ENUM(EAState, EA_STATE_FLAG_ON_INIT), true);
_taskobj_init.Process();
Expand Down Expand Up @@ -418,14 +419,14 @@ class EA : public Taskable<DataParamEntry> {
if (!_result) { // && _strade.IsTradeRecommended(
MqlTradeRequestProxy _request_proxy(_request);
logger.Debug(StringFormat("Error while sending a trade request! Entry: %s",
SerializerConverter::FromObject(_request_proxy).ToString<SerializerJson>()),
C_STR(SerializerConverter::FromObject(_request_proxy).ToString<SerializerJson>())),
__FUNCTION_LINE__,
StringFormat("Code: %d, Msg: %s", _LastError, Terminal::GetErrorText(_LastError)));
StringFormat("Code: %d, Msg: %s", _LastError, C_STR(Terminal::GetErrorText(_LastError))));
if (_trade PTR_DEREF IsTradeRecommended()) {
logger.Debug(StringFormat("Error while sending a trade request! Entry: %s",
SerializerConverter::FromObject(_request_proxy).ToString<SerializerJson>()),
C_STR(SerializerConverter::FromObject(_request_proxy).ToString<SerializerJson>())),
__FUNCTION_LINE__,
StringFormat("Code: %d, Msg: %s", _LastError, Terminal::GetErrorText(_LastError)));
StringFormat("Code: %d, Msg: %s", _LastError, C_STR(Terminal::GetErrorText(_LastError))));
}
#ifdef __debug_ea__
Print(__FUNCTION_LINE__ + "(): " + SerializerConverter::FromObject(_request_proxy).ToString<SerializerJson>());
Expand Down Expand Up @@ -774,7 +775,7 @@ class EA : public Taskable<DataParamEntry> {
bool StrategyAdd(ENUM_TIMEFRAMES _tf, int64 _magic_no = 0, int _type = 0) {
bool _result = true;
_magic_no = _magic_no > 0 ? _magic_no : rand();
Ref<Strategy> _strat = ((SClass *)NULL).Init(_tf, THIS_PTR);
Ref<Strategy> _strat = new SClass(_tf, THIS_PTR);
_strat REF_DEREF Set<int64>(STRAT_PARAM_ID, _magic_no);
_strat REF_DEREF Set<int64>(TRADE_PARAM_MAGIC_NO, _magic_no);
_strat REF_DEREF Set<int>(STRAT_PARAM_LOG_LEVEL,
Expand Down
8 changes: 5 additions & 3 deletions EA.struct.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
*/

#ifndef __MQL__
// Allows the preprocessor to include a header file when it is needed.
#pragma once
// Allows the preprocessor to include a header file when it is needed.
#pragma once
#endif

// Includes.
Expand Down Expand Up @@ -204,7 +204,9 @@ struct EAParams {
}
void SetTaskEntry(TaskEntry &_task_entry) { task_init = _task_entry; }
// Printers.
string ToString(string _dlm = ",") { return StringFormat("%s v%s by %s (%s)", name, ver, author, desc); }
string ToString(string _dlm = ",") {
return StringFormat("%s v%s by %s (%s)", C_STR(name), C_STR(ver), C_STR(author), C_STR(desc));
}
};

/* Defines struct to store results for EA processing. */
Expand Down
64 changes: 32 additions & 32 deletions Indicators/Price/Indi_MA.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,24 @@
*/

#ifndef __MQL__
// Allows the preprocessor to include a header file when it is needed.
#pragma once
// Allows the preprocessor to include a header file when it is needed.
#pragma once
#endif

// Prevents processing this includes file for the second time.
#ifndef INDI_MA_MQH
#define INDI_MA_MQH

// Includes.
#include "../../Indicator/Indicator.h"
#include "../../Refs.mqh"
#include "../../Storage/Dict/Dict.h"
#include "../../Storage/Dict/DictObject.h"
#include "../../Storage/Singleton.h"
#include "../../Storage/String.h"
#include "../../Storage/ValueStorage.h"

#ifndef __MQL__
#define INDI_MA_MQH

// Includes.
#include "../../Indicator/Indicator.h"
#include "../../Refs.mqh"
#include "../../Storage/Dict/Dict.h"
#include "../../Storage/Dict/DictObject.h"
#include "../../Storage/Singleton.h"
#include "../../Storage/String.h"
#include "../../Storage/ValueStorage.h"

#ifndef __MQL__
// Enums.
// @see: https://www.mql5.com/en/docs/constants/indicatorconstants/enum_ma_method
enum ENUM_MA_METHOD {
Expand All @@ -47,7 +47,7 @@ enum ENUM_MA_METHOD {
MODE_SMMA, // Smoothed averaging.
MODE_LWMA, // Linear-weighted averaging.
};
#endif
#endif

// Structs.
struct IndiMAParams : IndicatorParams {
Expand All @@ -65,11 +65,11 @@ struct IndiMAParams : IndicatorParams {
ENUM_APPLIED_PRICE _ap = PRICE_OPEN, int _shift = 10)
: period(_period), ma_shift(_ma_shift), ma_method(_ma_method), applied_array(_ap), IndicatorParams(INDI_MA) {
if (custom_indi_name == "") {
#ifdef __MQL5__
#ifdef __MQL5__
SetCustomIndicatorName("Examples\\Custom Moving Average");
#else
#else
SetCustomIndicatorName("Custom Moving Averages");
#endif
#endif
}
shift = _shift;
};
Expand Down Expand Up @@ -127,20 +127,20 @@ class Indi_MA : public Indicator<IndiMAParams> {
static double iMA(string _symbol, ENUM_TIMEFRAMES _tf, unsigned int _ma_period, unsigned int _ma_shift,
ENUM_MA_METHOD _ma_method, ENUM_APPLIED_PRICE _applied_price, int _shift = 0,
IndicatorData *_obj = NULL) {
#ifdef __MQL__
#ifdef __MQL4__
#ifdef __MQL__
#ifdef __MQL4__
return ::iMA(_symbol, _tf, _ma_period, _ma_shift, _ma_method, _applied_price, _shift);
#else // __MQL5__
#else // __MQL5__
INDICATOR_BUILTIN_CALL_AND_RETURN(::iMA(_symbol, _tf, _ma_period, _ma_shift, _ma_method, _applied_price), 0,
_shift);
#endif
#else // Non-MQL.
#endif
#else // Non-MQL.
// @todo: Use Platform class.
RUNTIME_ERROR(
"Not implemented. Please use an On-Indicator mode and attach "
"indicator via Platform::Add/AddWithDefaultBindings().");
return DBL_MAX;
#endif
#endif
}

/**
Expand All @@ -162,16 +162,16 @@ class Indi_MA : public Indicator<IndiMAParams> {
*/
static double iMAOnArray(ARRAY_REF(double, price), int total, int ma_period, int ma_shift, ENUM_MA_METHOD ma_method,
int shift, IndiBufferCache<double> *cache = NULL) {
#ifdef __MQL4__
#ifdef __MQL4__
return ::iMAOnArray(price, total, ma_period, ma_shift, ma_method, shift);
#else
#else
// We're reusing the same native array for each consecutive calculation.
NativeValueStorage<double> *_array_storage = Singleton<NativeValueStorage<double>>::Get();
_array_storage PTR_DEREF SetData(price);

return iMAOnArray(PTR_TO_REF((ValueStorage<double> *)_array_storage), total, ma_period, ma_shift, ma_method, shift,
cache);
#endif
#endif
}

/**
Expand Down Expand Up @@ -565,7 +565,7 @@ class Indi_MA : public Indicator<IndiMAParams> {
}

static int LinearWeightedMAOnBuffer(const int rates_total, const int prev_calculated, const int begin,
const int period, const ARRAY_REF(double, price), ARRAY_REF(double, buffer),
const int period, ARRAY_REF(double, price), ARRAY_REF(double, buffer),
int &weight_sum) {
int i, k;

Expand Down Expand Up @@ -849,14 +849,14 @@ class Indi_MA : public Indicator<IndiMAParams> {
}
};

#ifdef __MQL4__
#ifdef __MQL4__
// MQL4 version of the method doesn't have last parameter.
int LinearWeightedMAOnBuffer(const int rates_total, const int prev_calculated, const int begin, const int period,
const double &price[], double &buffer[]) {
double &price[], double &buffer[]) {
int _weight_sum;
return Indi_MA::LinearWeightedMAOnBuffer(rates_total, prev_calculated, begin, period, price, buffer, _weight_sum);
}
#else // !__MQL__4
#else // !__MQL__4
// Defines global functions (for MQL4 backward compability).
double iMA(string _symbol, int _tf, int _ma_period, int _ma_shift, ENUM_MA_METHOD _ma_method, int _ap, int _shift) {
ResetLastError();
Expand All @@ -868,6 +868,6 @@ double iMAOnArray(ARRAY_REF(double, _arr), int _total, int _period, int _ma_shif
ResetLastError();
return Indi_MA::iMAOnArray(_arr, _total, _period, _ma_shift, _ma_method, _abs_shift, _cache);
}
#endif // __MQL4__
#endif // __MQL4__

#endif // INDI_MA_MQH
14 changes: 7 additions & 7 deletions Indicators/PriceRange/Indi_Envelopes.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
*/

#ifndef __MQL__
// Allows the preprocessor to include a header file when it is needed.
#pragma once
// Allows the preprocessor to include a header file when it is needed.
#pragma once
#endif

// Includes.
Expand Down Expand Up @@ -116,9 +116,9 @@ class Indi_Envelopes : public Indicator<IndiEnvelopesParams> {
// UPPER_LINE, 1 - LOWER_LINE
int _shift = 0, IndicatorData *_obj = NULL) {
#ifdef __MQL__
#ifdef __MQL4__
#ifdef __MQL4__
return ::iEnvelopes(_symbol, _tf, _ma_period, _ma_method, _ma_shift, _ap, _deviation, _mode, _shift);
#else // __MQL5__
#else // __MQL5__
switch (_mode) {
case LINE_UPPER:
_mode = 0;
Expand All @@ -130,7 +130,7 @@ class Indi_Envelopes : public Indicator<IndiEnvelopesParams> {

INDICATOR_BUILTIN_CALL_AND_RETURN(::iEnvelopes(_symbol, _tf, _ma_period, _ma_shift, _ma_method, _ap, _deviation),
_mode, _shift);
#endif
#endif
#else // Non-MQL.
// @todo: Use Platform class.
RUNTIME_ERROR(
Expand All @@ -151,7 +151,7 @@ class Indi_Envelopes : public Indicator<IndiEnvelopesParams> {
_ma_method, _ma_shift, _deviation, _mode, _shift, _target PTR_DEREF GetCache());
}

static double iEnvelopesOnArray(CONST_ARRAY_REF(double, price), int total, int ma_period, ENUM_MA_METHOD ma_method,
static double iEnvelopesOnArray(ARRAY_REF(double, price), int total, int ma_period, ENUM_MA_METHOD ma_method,
int ma_shift, double deviation, int mode, int shift,
IndiBufferCache<double> *_cache = NULL) {
#ifdef __MQL4__
Expand Down Expand Up @@ -331,7 +331,7 @@ double iEnvelopes(string _symbol, int _tf, int _period, int _ma_method, int _ma_
return Indi_Envelopes::iEnvelopes(_symbol, (ENUM_TIMEFRAMES)_tf, _period, (ENUM_MA_METHOD)_ma_method, _ma_shift,
(ENUM_APPLIED_PRICE)_ap, _deviation, _mode, _shift);
}
double iEnvelopesOnArray(CONST_ARRAY_REF(double, _arr), int _total, int _ma_period, int _ma_method, int _ma_shift,
double iEnvelopesOnArray(ARRAY_REF(double, _arr), int _total, int _ma_period, int _ma_method, int _ma_shift,
double _deviation, int _mode, int _shift) {
ResetLastError();
return Indi_Envelopes::iEnvelopesOnArray(_arr, _total, _ma_period, (ENUM_MA_METHOD)_ma_method, _ma_shift, _deviation,
Expand Down
2 changes: 1 addition & 1 deletion Market.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ class Market : public SymbolInfo {
case MARKET_COND_SPREAD_GT_20:
return GetSpreadInPts() > 20;
default:
logger.Error(StringFormat("Invalid market condition: %s!", EnumToString(_cond), __FUNCTION_LINE__));
logger.Error(StringFormat("Invalid market condition: %s!", C_STR(EnumToString(_cond)), __FUNCTION_LINE__));
return false;
}
}
Expand Down
29 changes: 14 additions & 15 deletions Math/Matrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,30 +25,29 @@
#define MATRIX_MQH

#ifndef __MQL__
// Allows the preprocessor to include a header file when it is needed.
#pragma once
// Allows the preprocessor to include a header file when it is needed.
#pragma once
#endif


#ifdef __MQL5__
#define MATRIX_USE_OPENCL
#define MATRIX_USE_OPENCL
#endif

#ifdef USE_MQL_MATH_STAT
#ifdef __MQL5__
#include <Math/Stat/Normal.mqh>
#endif
#ifdef __MQL5__
#include <Math/Stat/Normal.mqh>
#endif
#endif

// Includes.
#include "Math.h"

#ifdef MATRIX_USE_OPENCL
#include "OpenCL.h"
#include "OpenCL.h"

#resource "Matrix.matmul.cl" as string CLSource_Matrix_MatMul
#resource "Matrix.matmul.naive.cl" as string CLSource_Matrix_MatMul_Naive
#resource "Matrix.matmul.test.cl" as string CLSource_Matrix_MatMul_Test
#resource "Matrix.matmul.cl" as string CLSource_Matrix_MatMul
#resource "Matrix.matmul.naive.cl" as string CLSource_Matrix_MatMul_Naive
#resource "Matrix.matmul.test.cl" as string CLSource_Matrix_MatMul_Test
#endif // MATRIX_USE_OPENCL

#define MATRIX_DIMENSIONS 6
Expand Down Expand Up @@ -843,7 +842,7 @@ class Matrix {
return;
}

Initialize(_right.ptr_first_dimension.Clone());
Initialize(_right.ptr_first_dimension PTR_DEREF Clone());
#ifdef MATRIX_USE_OPENCL
InitializeOpenCL();
#endif
Expand Down Expand Up @@ -2673,7 +2672,7 @@ unsigned long Matrix<X>::version_counter = 0;

#ifdef MATRIX_USE_OPENCL

#ifdef __MQL__
#ifdef __MQL__
template <typename X>
Ref<OpenCLProgram> Matrix::cl_program_matmul;
template <typename X>
Expand All @@ -2684,7 +2683,7 @@ template <typename X>
DictStruct<int, Ref<OpenCLBuffer>> Matrix::cl_buffers_in_1;
template <typename X>
DictStruct<int, Ref<OpenCLBuffer>> Matrix::cl_buffers_out;
#else
#else
template <typename X>
Ref<OpenCLProgram> Matrix<X>::cl_program_matmul;
template <typename X>
Expand All @@ -2695,7 +2694,7 @@ template <typename X>
DictStruct<int, Ref<OpenCLBuffer>> Matrix<X>::cl_buffers_in_1;
template <typename X>
DictStruct<int, Ref<OpenCLBuffer>> Matrix<X>::cl_buffers_out;
#endif // __MQL__
#endif // __MQL__

#endif // MATRIX_USE_OPENCL

Expand Down
4 changes: 2 additions & 2 deletions Serializer/SerializerNodeParam.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class SerializerNodeParam {
/**
* Returns new SerializerNodeParam object from given source value.
*/
static SerializerNodeParam* FromValue(datetime value) { return FromLong(value); }
static SerializerNodeParam* FromValue(datetime value) { return FromLong((int64)value); }

/**
* Returns new SerializerNodeParam object from given source value.
Expand Down Expand Up @@ -345,7 +345,7 @@ SerializerNodeParam* SerializerNodeParam::FromLong(int64 value) {
/**
* Returns new SerializerNodeParam object from given source value.
*/
SerializerNodeParam* SerializerNodeParam::FromLong(uint64 value) { return FromLong((signed int64)value); }
SerializerNodeParam* SerializerNodeParam::FromLong(uint64 value) { return FromLong((uint64)value); }

/**
* Returns new SerializerNodeParam object from given source value.
Expand Down
6 changes: 3 additions & 3 deletions Storage/Dict/Buffer/BufferTick.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
*/

#ifndef __MQL__
// Allows the preprocessor to include a header file when it is needed.
#pragma once
// Allows the preprocessor to include a header file when it is needed.
#pragma once
#endif

// Includes.
Expand Down Expand Up @@ -77,7 +77,7 @@ class BufferTickValueStorage : ValueStorage<TV> {
/**
* Returns number of values available to fetch (size of the values buffer).
*/
int Size() override { return (int)THIS_ATTR buffer_tick.Size(); }
int Size() override { return (int)THIS_ATTR buffer_tick PTR_DEREF Size(); }
};

/**
Expand Down
6 changes: 3 additions & 3 deletions Storage/ValueStorage.native.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
*/

#ifndef __MQL__
// Allows the preprocessor to include a header file when it is needed.
#pragma once
// Allows the preprocessor to include a header file when it is needed.
#pragma once
#endif

// Includes.
Expand Down Expand Up @@ -55,7 +55,7 @@ class NativeValueStorage : public ValueStorage<C> {
/**
* Initializes array with given one.
*/
void SetData(CONST_ARRAY_REF(C, _arr)) {
void SetData(ARRAY_REF(C, _arr)) {
bool _was_series = ArrayGetAsSeries(_arr);
ArraySetAsSeries(_arr, false);
ArraySetAsSeries(_values, false);
Expand Down
Loading

0 comments on commit 4d428e7

Please sign in to comment.