Skip to content

Commit

Permalink
Finally fixed #include loops.
Browse files Browse the repository at this point in the history
  • Loading branch information
nseam committed Jun 8, 2021
1 parent cbe4b49 commit 7076a40
Show file tree
Hide file tree
Showing 12 changed files with 179 additions and 94 deletions.
56 changes: 50 additions & 6 deletions Array.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@
*
*/

// Prevents processing this includes file for the second time.
#ifndef ARRAY_MQH
#define ARRAY_MQH
#ifndef __MQL__
// Allows the preprocessor to include a header file when it is needed.
#pragma once
#endif

// Defines.
#ifndef MODE_ASCEND
Expand All @@ -38,6 +39,26 @@
#define WHOLE_ARRAY 0
#endif

/**
* Reference to the array.
*
* @usage
* ARRAY_REF(<type of the array items>, <name of the variable>)
*/
#ifdef __MQL__
#define ARRAY_REF(T, N) REF(T) N
#endif

/**
* Array definition.
*
* @usage
* ARRAY(<type of the array items>, <name of the variable>)
*/
#ifdef __MQL__
#define ARRAY(T, N) T N[];
#endif

/*
* Class to provide methods to deal with arrays.
*/
Expand Down Expand Up @@ -698,7 +719,19 @@ class Array {
*/
template <typename X>
static int ArrayMinimum(const ARRAY_REF(X, _array), int _start = 0, int _count = WHOLE_ARRAY) {
#ifdef __MQL__
return ::ArrayMinimum(_array);
#else
int _peak_index = 0;

for (int i = 1; i < ArraySize(_array); ++i) {
if (_array[i] < _array[_peak_index]) {
_peak_index = i;
}
}

return _peak_index;
#endif
}

/**
Expand All @@ -718,8 +751,20 @@ class Array {
* - https://www.mql5.com/en/docs/array/arraymaximum
*/
template <typename X>
static int ArrayMaximum(const ARRAY_REF(X, array), int start = 0, int count = WHOLE_ARRAY) {
return ::ArrayMaximum(array);
static int ArrayMaximum(const ARRAY_REF(X, _array), int start = 0, int count = WHOLE_ARRAY) {
#ifdef __MQL__
return ::ArrayMaximum(_array);
#else
int _peak_index = 0;

for (int i = 1; i < ArraySize(_array); ++i) {
if (_array[i] > _array[_peak_index]) {
_peak_index = i;
}
}

return _peak_index;
#endif
}

/**
Expand All @@ -739,4 +784,3 @@ class Array {
return ::ArraySize(array);
}
};
#endif // ARRAY_MQH
7 changes: 6 additions & 1 deletion Bar.struct.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,14 @@
#pragma once
#endif

// Forward class declaration.
class Serializer;

// Includes.
#include "Bar.enum.h"
#include "Chart.enum.h"
#include "ISerializable.h"
#include "Serializer.mqh"
#include "Serializer.enum.h"
#include "SerializerNode.enum.h"

/* Struct for storing OHLC values. */
Expand Down Expand Up @@ -216,6 +219,8 @@ struct BarOHLC
string ToCSV() { return StringFormat("%d,%g,%g,%g,%g", time, open, high, low, close); }
};

#include "Serializer.mqh"

/* Method to serialize BarOHLC structure. */
SerializerNodeType BarOHLC::Serialize(Serializer &s) {
// s.Pass(this, "time", TimeToString(time));
Expand Down
6 changes: 3 additions & 3 deletions Chart.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,11 @@ struct MqlRates {
class Chart : public Market {
protected:
// Structs.
ChartEntry chart_saves[];
ARRAY(ChartEntry, chart_saves);
ChartParams cparams;

// Stores information about the prices, volumes and spread.
MqlRates rates[];
ARRAY(MqlRates, rates);
ChartEntry c_entry;

// Stores indicator instances.
Expand Down Expand Up @@ -452,7 +452,7 @@ class Chart : public Market {
long StartBar = 0;
long StartGenM1 = 0;
long HistoryTotal = 0;
datetime modeling_start_time = D'1971.01.01 00:00';
datetime modeling_start_time = DATETIME_LITERAL(1971.01.01 00:00);

if (TimePr == NULL) TimePr = (ENUM_TIMEFRAMES)Period();
if (TimePr == PERIOD_M1) TimeNearPr = PERIOD_M1;
Expand Down
55 changes: 0 additions & 55 deletions Convert.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@

// Includes.
#include "Account.enum.h"
#include "Math.h"
#include "SymbolInfo.static.h"
#include "Order.enum.h"

Expand Down Expand Up @@ -357,60 +356,6 @@ public:
static void DoubleToType(double _value, float& _out) { _out = (float)_value; }
static void DoubleToType(double _value, double& _out) { _out = (double)_value; }
static void DoubleToType(double _value, string& _out) { _out = _value ? "1" : "0"; }

/**
* Converts MqlParam struct to double.
*
* @todo: Move to Data class.
*/
static double MqlParamToDouble(MqlParam& param) {
switch (param.type) {
case TYPE_BOOL:
return param.integer_value ? 1 : 0;
case TYPE_INT:
case TYPE_LONG:
case TYPE_UINT:
case TYPE_ULONG:
return (double)param.integer_value;
case TYPE_DOUBLE:
case TYPE_FLOAT:
return param.double_value;
case TYPE_CHAR:
case TYPE_STRING:
case TYPE_UCHAR:
return StringToDouble(param.string_value);
}
return DBL_MIN;
}

/**
* Converts MqlParam struct to integer.
*
* @todo: Move to Data class.
*/
static long MqlParamToInteger(MqlParam& param) {
switch (param.type) {
case TYPE_BOOL:
return param.integer_value ? 1 : 0;
case TYPE_DATETIME:
case TYPE_INT:
case TYPE_LONG:
case TYPE_UINT:
case TYPE_ULONG:
case TYPE_SHORT:
return param.integer_value;
case TYPE_DOUBLE:
case TYPE_FLOAT:
return (int) param.double_value;
case TYPE_CHAR:
case TYPE_COLOR:
case TYPE_STRING:
case TYPE_UCHAR:
return StringToInteger(param.string_value);
}
return INT_MIN;
}

};


Expand Down
54 changes: 54 additions & 0 deletions Data.struct.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ struct MqlParam;

// Includes.
#include "Data.enum.h"
#include "Serializer.enum.h"
#include "SerializerNode.enum.h"

#ifndef __MQL__
Expand Down Expand Up @@ -106,6 +107,59 @@ struct MqlParam {
};
#endif

/**
* Converts MqlParam struct to integer.
*
* @todo: Move to Data class.
*/
long MqlParamToInteger(MqlParam &param) {
switch (param.type) {
case TYPE_BOOL:
return param.integer_value ? 1 : 0;
case TYPE_DATETIME:
case TYPE_INT:
case TYPE_LONG:
case TYPE_UINT:
case TYPE_ULONG:
case TYPE_SHORT:
return param.integer_value;
case TYPE_DOUBLE:
case TYPE_FLOAT:
return (int)param.double_value;
case TYPE_CHAR:
case TYPE_COLOR:
case TYPE_STRING:
case TYPE_UCHAR:
return StringToInteger(param.string_value);
}
return INT_MIN;
}

/**
* Converts MqlParam struct to double.
*
* @todo: Move to Data class.
*/
static double MqlParamToDouble(MqlParam &param) {
switch (param.type) {
case TYPE_BOOL:
return param.integer_value ? 1 : 0;
case TYPE_INT:
case TYPE_LONG:
case TYPE_UINT:
case TYPE_ULONG:
return (double)param.integer_value;
case TYPE_DOUBLE:
case TYPE_FLOAT:
return param.double_value;
case TYPE_CHAR:
case TYPE_STRING:
case TYPE_UCHAR:
return StringToDouble(param.string_value);
}
return DBL_MIN;
}

/**
* Struct to provide multitype data parameters.
*
Expand Down
6 changes: 6 additions & 0 deletions DateTime.enum.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@
#pragma once
#endif

#ifdef __MQL__
#define DATETIME_LITERAL(STR) D'##STR##'
#else
#define DATETIME_LITERAL(STR) D"##STR##"
#endif

/* Defines datetime conditions. */
enum ENUM_DATETIME_CONDITION {
DATETIME_COND_IS_PEAK_HOUR = 1, // On peak hour
Expand Down
9 changes: 4 additions & 5 deletions Math.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@
*
*/

// Prevents processing this includes file for the second time.
#ifndef MATH_H
#define MATH_H
#ifndef __MQL__
// Allows the preprocessor to include a header file when it is needed.
#pragma once
#endif

// Includes.
#include "Data.struct.h"
Expand Down Expand Up @@ -256,5 +257,3 @@ class Math {
}
}
};

#endif // MATH_M
48 changes: 48 additions & 0 deletions MqlTick.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
//+------------------------------------------------------------------+
//| EA31337 framework |
//| Copyright 2016-2021, EA31337 Ltd |
//| https://github.com/EA31337 |
//+------------------------------------------------------------------+

/*
* This file is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

/**
* @file
* MqlTick structure.
*/

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

#ifndef __MQL__
/**
* Structure for storing the latest prices of the symbol.
* @docs
* https://www.mql5.com/en/docs/constants/structures/mqltick
*/
struct MqlTick {
datetime time; // Time of the last prices update.
double ask; // Current Ask price.
double bid; // Current Bid price.
double last; // Price of the last deal (last).
double volume_real; // Volume for the current last price with greater accuracy.
long time_msc; // Time of a price last update in milliseconds.
unsigned int flags; // Tick flags.
unsigned long volume; // Volume for the current last price.
};
#endif
1 change: 1 addition & 0 deletions Serializer.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#define SERIALIZER_MQH

// Includes.
#include "Convert.mqh"
#include "Serializer.define.h"
#include "Serializer.enum.h"
#include "SerializerNode.mqh"
Expand Down
2 changes: 1 addition & 1 deletion SymbolInfo.define.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

/* Defines */

#ifndef __MQL4__
#ifdef __MQL5__
// --
#define Point _Point
#define Digits _Digits
Expand Down
Loading

0 comments on commit 7076a40

Please sign in to comment.