Skip to content

Commit

Permalink
Minor code improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
kenorb committed May 4, 2021
1 parent 1bf09df commit 804cdc5
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 31 deletions.
3 changes: 3 additions & 0 deletions Bar.struct.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

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

Expand Down Expand Up @@ -130,6 +131,8 @@ struct BarOHLC {
_s3 = _s1 - _range;
_s4 = _s2 - _range; // ?
break;
default:
break;
}
return _r4 > _r3 && _r3 > _r2 && _r2 > _r1 && _r1 > _pp && _pp > _s1 && _s1 > _s2 && _s2 > _s3 && _s3 > _s4;
}
Expand Down
1 change: 1 addition & 0 deletions Chart.enum.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

#ifndef __MQL__
// Defines enumeration for price price base calculations.
// https://docs.mql4.com/constants/indicatorconstants/prices
enum ENUM_APPLIED_PRICE {
PRICE_CLOSE = 0, // Close price.
PRICE_OPEN = 1, // Open price.
Expand Down
2 changes: 1 addition & 1 deletion Chart.struct.tf.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ struct ChartTf {
return (ENUM_TIMEFRAMES_INDEX)i;
}
}
return NULL;
return FINAL_ENUM_TIMEFRAMES_INDEX;
}

/**
Expand Down
3 changes: 3 additions & 0 deletions Convert.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -366,15 +366,18 @@ public:
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);
Expand Down
2 changes: 1 addition & 1 deletion DateTime.enum.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,4 @@ enum ENUM_TIME {
TIME_MINUTES = 1 << 1, // Formats date as hh:mi.
TIME_SECONDS = 1 << 2, // Formats date as hh:mi:ss.
};
#endif
#endif
7 changes: 7 additions & 0 deletions DateTime.struct.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
#pragma once
#endif

// Forward declarations.
struct DateTimeStatic;

// Includes.
#include "DateTime.enum.h"
#include "DateTime.struct.h"
Expand Down Expand Up @@ -89,6 +92,8 @@ struct DateTimeEntry : MqlDateTime {
return GetMonth();
case DATETIME_YEAR:
return GetYear();
default:
break;
}
return _result;
}
Expand Down Expand Up @@ -150,6 +155,8 @@ struct DateTimeEntry : MqlDateTime {
case DATETIME_YEAR:
SetYear(_value);
break;
default:
break;
}
}
void SetValue(unsigned short _unit, int _value) {
Expand Down
9 changes: 0 additions & 9 deletions Math.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,6 @@
#include "Math.enum.h"
#include "Math.struct.h"

// Includes standard C++ library for non-MQL code.
#ifndef __MQLBUILD__
#include <bits/stdc++.h> // GNU GCC extension.

#include <cfloat>
#include <cmath>
using namespace std;
#endif

// Defines macros.
#define fmax2(_v1, _v2) fmax(_v1, _v2)
#define fmax3(_v1, _v2, _v3) fmax(fmax(_v1, _v2), _v3)
Expand Down
20 changes: 0 additions & 20 deletions String.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -28,26 +28,6 @@
#define NL "\n" // New line: 0x0A (MQL file functions auto-convert 0x0A to 0x0D0A).
#define TAB "\t" // Tab: 0x09.

// Includes standard C++ library for non-MQL code.
#ifndef __MQLBUILD__
#include <memory> // For std::unique_ptr
#include <stdarg.h> // For va_start, etc.
#include <string>

template<typename ... Args>
std::string StringFormat(const std::string& format, Args ... args)
{
size_t size = snprintf(nullptr, 0, format.c_str(), args ...) + 1; // Extra space for '\0'
if (size <= 0) { throw std::runtime_error("Error during formatting."); }
std::unique_ptr<char[]> buf(new char[size]);
snprintf(buf.get(), size, format.c_str(), args ...);
return std::string(buf.get(), buf.get() + size - 1); // We don't want the '\0' inside
}

#define PrintFormat printf

#endif

/**
* Class to provide methods to deal with strings.
*/
Expand Down

0 comments on commit 804cdc5

Please sign in to comment.