Skip to content

Commit

Permalink
It compiles! However, it's still a WIP.
Browse files Browse the repository at this point in the history
  • Loading branch information
nseam committed Jun 3, 2021
1 parent e00601c commit cbe4b49
Show file tree
Hide file tree
Showing 10 changed files with 676 additions and 350 deletions.
13 changes: 13 additions & 0 deletions Chart.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,19 @@ double iClose(string _symbol, int _tf, int _shift) {
}
#endif

#ifndef __MQL__
struct MqlRates {
datetime time; // Period start time
double open; // Open price
double high; // The highest price of the period
double low; // The lowest price of the period
double close; // Close price
long tick_volume; // Tick volume
int spread; // Spread
long real_volume; // Trade volume
};
#endif

/**
* Class to provide chart, timeframe and timeseries operations.
*/
Expand Down
128 changes: 64 additions & 64 deletions Chart.struct.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,70 +126,6 @@ struct ChartStatic {
#endif
}

/**
* Wrapper struct that returns close prices of each bar of the current chart.
*
* @see: https://docs.mql4.com/predefined/close
*/
struct ChartPriceClose {
string symbol;
ENUM_TIMEFRAMES tf;

ChartPriceClose() : symbol(_Symbol), tf(PERIOD_CURRENT) {}
double operator[](const int _shift) const { return Get(symbol, tf, _shift); }
static double Get(const string _symbol, const ENUM_TIMEFRAMES _tf, const int _shift) {
return ChartStatic::iClose(_symbol, _tf, _shift);
}
};

/**
* Wrapper struct that returns the highest prices of each bar of the current chart.
*
* @see: https://docs.mql4.com/predefined/high
*/
struct ChartPriceHigh {
string symbol;
ENUM_TIMEFRAMES tf;

ChartPriceHigh() : symbol(_Symbol), tf(PERIOD_CURRENT) {}
double operator[](const int _shift) const { return Get(symbol, tf, _shift); }
static double Get(const string _symbol, const ENUM_TIMEFRAMES _tf, const int _shift) {
return ChartStatic::iHigh(_symbol, _tf, _shift);
}
};

/**
* Wrapper struct that returns the lowest prices of each bar of the current chart.
*
* @see: https://docs.mql4.com/predefined/low
*/
struct ChartPriceLow {
string symbol;
ENUM_TIMEFRAMES tf;

ChartPriceLow() : symbol(_Symbol), tf(PERIOD_CURRENT) {}
double operator[](const int _shift) const { return Get(symbol, tf, _shift); }
static double Get(const string _symbol, const ENUM_TIMEFRAMES _tf, const int _shift) {
return ChartStatic::iLow(_symbol, _tf, _shift);
}
};

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

ChartPriceOpen() : symbol(_Symbol), tf(PERIOD_CURRENT) {}
double operator[](const int _shift) const { return Get(symbol, tf, _shift); }
static double Get(const string _symbol, const ENUM_TIMEFRAMES _tf, const int _shift) {
return ChartStatic::iOpen(_symbol, _tf, _shift);
}
};

/**
* Search for a bar by its time.
*
Expand Down Expand Up @@ -443,6 +379,70 @@ struct ChartPriceOpen {
static long ID() { return ::ChartID(); }
};

/**
* Wrapper struct that returns close prices of each bar of the current chart.
*
* @see: https://docs.mql4.com/predefined/close
*/
struct ChartPriceClose {
string symbol;
ENUM_TIMEFRAMES tf;

ChartPriceClose() : symbol(_Symbol), tf(PERIOD_CURRENT) {}
double operator[](const int _shift) const { return Get(symbol, tf, _shift); }
static double Get(const string _symbol, const ENUM_TIMEFRAMES _tf, const int _shift) {
return ChartStatic::iClose(_symbol, _tf, _shift);
}
};

/**
* Wrapper struct that returns the highest prices of each bar of the current chart.
*
* @see: https://docs.mql4.com/predefined/high
*/
struct ChartPriceHigh {
string symbol;
ENUM_TIMEFRAMES tf;

ChartPriceHigh() : symbol(_Symbol), tf(PERIOD_CURRENT) {}
double operator[](const int _shift) const { return Get(symbol, tf, _shift); }
static double Get(const string _symbol, const ENUM_TIMEFRAMES _tf, const int _shift) {
return ChartStatic::iHigh(_symbol, _tf, _shift);
}
};

/**
* Wrapper struct that returns the lowest prices of each bar of the current chart.
*
* @see: https://docs.mql4.com/predefined/low
*/
struct ChartPriceLow {
string symbol;
ENUM_TIMEFRAMES tf;

ChartPriceLow() : symbol(_Symbol), tf(PERIOD_CURRENT) {}
double operator[](const int _shift) const { return Get(symbol, tf, _shift); }
static double Get(const string _symbol, const ENUM_TIMEFRAMES _tf, const int _shift) {
return ChartStatic::iLow(_symbol, _tf, _shift);
}
};

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

ChartPriceOpen() : symbol(_Symbol), tf(PERIOD_CURRENT) {}
double operator[](const int _shift) const { return Get(symbol, tf, _shift); }
static double Get(const string _symbol, const ENUM_TIMEFRAMES _tf, const int _shift) {
return ChartStatic::iOpen(_symbol, _tf, _shift);
}
};

/**
* Wrapper struct that returns open time of each bar of the current chart.
*
Expand Down
101 changes: 63 additions & 38 deletions Convert.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@
#define CONVERT_MQH

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

/**
Expand Down Expand Up @@ -58,7 +59,7 @@ public:
case ORDER_TYPE_BUY_STOP:
return ORDER_TYPE_BUY;
default:
return NULL;
return (ENUM_ORDER_TYPE)WRONG_VALUE;
}
}

Expand Down Expand Up @@ -101,7 +102,7 @@ public:
* Returns number of points per pip.
*/
static uint PointsPerPip(string _symbol = NULL) {
return PointsPerPip((uint) SymbolInfo::SymbolInfoInteger(_symbol, SYMBOL_DIGITS));
return PointsPerPip((uint) SymbolInfoStatic::SymbolInfoInteger(_symbol, SYMBOL_DIGITS));
}

/**
Expand All @@ -127,7 +128,7 @@ public:
* Convert pips into price value.
*/
static double PipsToValue(double pips, string _symbol = NULL) {
return PipsToValue(pips, (uint) SymbolInfo::SymbolInfoInteger(_symbol, SYMBOL_DIGITS));
return PipsToValue(pips, (uint) SymbolInfoStatic::SymbolInfoInteger(_symbol, SYMBOL_DIGITS));
}

/**
Expand All @@ -141,7 +142,7 @@ public:
* Convert value into pips.
*/
static double ValueToPips(double value, string _symbol = NULL) {
return ValueToPips(value, (uint) SymbolInfo::SymbolInfoInteger(_symbol, SYMBOL_DIGITS));
return ValueToPips(value, (uint) SymbolInfoStatic::SymbolInfoInteger(_symbol, SYMBOL_DIGITS));
}

/**
Expand All @@ -155,7 +156,7 @@ public:
* Convert pips into points.
*/
static uint PipsToPoints(double pips, string _symbol = NULL) {
return PipsToPoints(pips, (uint) SymbolInfo::SymbolInfoInteger(_symbol, SYMBOL_DIGITS));
return PipsToPoints(pips, (uint) SymbolInfoStatic::SymbolInfoInteger(_symbol, SYMBOL_DIGITS));
}

/**
Expand All @@ -169,7 +170,7 @@ public:
* Convert points into pips.
*/
static double PointsToPips(long pts, string _symbol = NULL) {
return PointsToPips(pts, (uint) SymbolInfo::SymbolInfoInteger(_symbol, SYMBOL_DIGITS));
return PointsToPips(pts, (uint) SymbolInfoStatic::SymbolInfoInteger(_symbol, SYMBOL_DIGITS));
}

/**
Expand All @@ -180,19 +181,19 @@ public:
switch (mode) {
case 0: // Forex.
// In currencies a tick is a point.
return pts * SymbolInfo::SymbolInfoDouble(_symbol, SYMBOL_TRADE_TICK_SIZE);
return pts * SymbolInfoStatic::SymbolInfoDouble(_symbol, SYMBOL_TRADE_TICK_SIZE);
case 1: // CFD.
// In metals a Tick is still the smallest change, but is larger than a point.
// If price can change from 123.25 to 123.50,
// you have a TickSize of 0.25 and a point of 0.01. Pip has no meaning.
// @todo
return pts * SymbolInfo::SymbolInfoDouble(_symbol, SYMBOL_TRADE_TICK_SIZE);
return pts * SymbolInfoStatic::SymbolInfoDouble(_symbol, SYMBOL_TRADE_TICK_SIZE);
case 2: // Futures.
// @todo
return pts * SymbolInfo::SymbolInfoDouble(_symbol, SYMBOL_TRADE_TICK_SIZE);
return pts * SymbolInfoStatic::SymbolInfoDouble(_symbol, SYMBOL_TRADE_TICK_SIZE);
case 3: // CFD for indices.
// @todo
return pts * SymbolInfo::SymbolInfoDouble(_symbol, SYMBOL_TRADE_TICK_SIZE);
return pts * SymbolInfoStatic::SymbolInfoDouble(_symbol, SYMBOL_TRADE_TICK_SIZE);
}
return false;
}
Expand Down Expand Up @@ -222,7 +223,7 @@ public:
* Convert points into price value.
*/
static double PointsToValue(long pts, string _symbol = NULL) {
return PointsToValue(pts, (int) SymbolInfo::SymbolInfoInteger(_symbol, SYMBOL_TRADE_CALC_MODE));
return PointsToValue(pts, (int) SymbolInfoStatic::SymbolInfoInteger(_symbol, SYMBOL_TRADE_CALC_MODE));
}

/**
Expand All @@ -232,8 +233,8 @@ public:
* Returns amount in a base currency based on the given the value.
*/
static double ValueToMoney(double value, string _symbol = NULL) {
double _tick_value = SymbolInfo::GetTickValue(_symbol) > 0 ? SymbolInfo::GetTickValue(_symbol) : 1;
return value * _tick_value / SymbolInfo::GetPointSize(_symbol);
double _tick_value = SymbolInfoStatic::GetTickValue(_symbol) > 0 ? SymbolInfoStatic::GetTickValue(_symbol) : 1;
return value * _tick_value / SymbolInfoStatic::GetPointSize(_symbol);
}

/**
Expand All @@ -243,15 +244,15 @@ public:
* Returns value in points equivalent to the amount in a base currency.
*/
static float MoneyToValue(float money, float lot_size, string _symbol = NULL) {
double _tick_value = SymbolInfo::GetTickValue(_symbol) > 0 ? SymbolInfo::GetTickValue(_symbol) : 1;
return money > 0 && lot_size > 0 ? float(money / _tick_value * SymbolInfo::GetPointSize(_symbol) / lot_size) : 0;
double _tick_value = SymbolInfoStatic::GetTickValue(_symbol) > 0 ? SymbolInfoStatic::GetTickValue(_symbol) : 1;
return money > 0 && lot_size > 0 ? float(money / _tick_value * SymbolInfoStatic::GetPointSize(_symbol) / lot_size) : 0;
}

/**
* Get the difference between two price values (in pips).
*/
static double GetValueDiffInPips(double price1, double price2, bool abs = false, int digits = NULL, string _symbol = NULL) {
digits = digits ? digits : (int) SymbolInfo::SymbolInfoInteger(_symbol, SYMBOL_DIGITS);
digits = digits ? digits : (int) SymbolInfoStatic::SymbolInfoInteger(_symbol, SYMBOL_DIGITS);
return ValueToPips(abs ? fabs(price1 - price2) : (price1 - price2), digits);
}

Expand Down Expand Up @@ -286,14 +287,14 @@ public:
/**
* Convert character into integer.
*/
static int CharToInt(int REF(_chars)[]) {
static int CharToInt(ARRAY_REF(int, _chars)) {
return ((_chars[0]) | (_chars[1] << 8) | (_chars[2] << 16) | (_chars[3] << 24));
}

/**
* Assume: len % 4 == 0.
*/
static int String4ToIntArray(int REF(output)[], string in) {
static int String4ToIntArray(ARRAY_REF(int, output), string in) {
int len;
int i, j;
len = StringLen(in);
Expand All @@ -310,28 +311,52 @@ public:
}

static void StringToType(string _value, bool& _out) {
#ifdef __MQL__
_out = _value != "" && _value != NULL && _value != "0" && _value != "false";
#else
_out = _value != "" && _value != "0" && _value != "false";
#endif
}

static void StringToType(string _value, int& _out) {
_out = (int)StringToInteger(_value);
}

static void StringToType(string _value, long& _out) {
_out = StringToInteger(_value);
}

static void StringToType(string _value, short& _out) {
_out = (short) StringToInteger(_value);
}

static void StringToType(string _value, double& _out) {
_out = StringToDouble(_value);
}

static void StringToType(string _value, string& _out) {
_out = _value;
}
static void StringToType(string _value, int& _out) { _out = (int)StringToInteger(_value); }
static void StringToType(string _value, unsigned int& _out) { _out = (unsigned int)StringToInteger(_value); }
static void StringToType(string _value, long& _out) { _out = StringToInteger(_value); }
static void StringToType(string _value, unsigned long& _out) { _out = StringToInteger(_value); }
static void StringToType(string _value, short& _out) { _out = (short)StringToInteger(_value); }
static void StringToType(string _value, unsigned short& _out) { _out = (unsigned short)StringToInteger(_value); }
static void StringToType(string _value, float& _out) { _out = (float)StringToDouble(_value); }
static void StringToType(string _value, double& _out) { _out = StringToDouble(_value); }
static void StringToType(string _value, string& _out) { _out = _value; }

static void BoolToType(bool _value, int& _out) { _out = (int)_value; }
static void BoolToType(bool _value, unsigned int& _out) { _out = (unsigned int)_value; }
static void BoolToType(bool _value, long& _out) { _out = (long)_value; }
static void BoolToType(bool _value, unsigned long& _out) { _out = (unsigned long)_value; }
static void BoolToType(bool _value, short& _out) { _out = (short)_value; }
static void BoolToType(bool _value, unsigned short& _out) { _out = (unsigned short)_value; }
static void BoolToType(bool _value, float& _out) { _out = (float)_value; }
static void BoolToType(bool _value, double& _out) { _out = (double)_value; }
static void BoolToType(bool _value, string& _out) { _out = _value ? "1" : "0"; }

static void LongToType(long _value, int& _out) { _out = (int)_value; }
static void LongToType(long _value, unsigned int& _out) { _out = (unsigned int)_value; }
static void LongToType(long _value, long& _out) { _out = (long)_value; }
static void LongToType(long _value, unsigned long& _out) { _out = (unsigned long)_value; }
static void LongToType(long _value, short& _out) { _out = (short)_value; }
static void LongToType(long _value, unsigned short& _out) { _out = (unsigned short)_value; }
static void LongToType(long _value, float& _out) { _out = (float)_value; }
static void LongToType(long _value, double& _out) { _out = (double)_value; }
static void LongToType(long _value, string& _out) { _out = _value ? "1" : "0"; }

static void DoubleToType(double _value, int& _out) { _out = (int)_value; }
static void DoubleToType(double _value, unsigned int& _out) { _out = (unsigned int)_value; }
static void DoubleToType(double _value, long& _out) { _out = (long)_value; }
static void DoubleToType(double _value, unsigned long& _out) { _out = (unsigned long)_value; }
static void DoubleToType(double _value, short& _out) { _out = (short)_value; }
static void DoubleToType(double _value, unsigned short& _out) { _out = (unsigned short)_value; }
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.
Expand Down
2 changes: 1 addition & 1 deletion Data.struct.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ struct MqlParam;
// Includes.
#include "Data.enum.h"
#include "SerializerNode.enum.h"
#include "SymbolInfo.struct.h"

#ifndef __MQL__
/**
Expand Down Expand Up @@ -116,6 +115,7 @@ struct MqlParam {
*/
struct DataParamEntry : public MqlParam {
public:
DataParamEntry() { type = (ENUM_DATATYPE)WRONG_VALUE; }
DataParamEntry(const DataParamEntry &_r) { ((MqlParam &)THIS_REF) = ((MqlParam &)_r); }
// Struct operators.
void operator=(const bool _value) {
Expand Down
Loading

0 comments on commit cbe4b49

Please sign in to comment.