Skip to content

Commit

Permalink
WIP. Fixing MT4 errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
nseam committed Feb 25, 2023
1 parent 16ebdc4 commit 65b8f29
Show file tree
Hide file tree
Showing 14 changed files with 77 additions and 93 deletions.
52 changes: 26 additions & 26 deletions Indicator/Indicator.define.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,32 +100,32 @@
#define EMPTY_VALUE DBL_MAX
#endif

#define INDICATOR_BUILTIN_CALL_AND_RETURN(NATIVE_METHOD_CALL, MODE, SHIFT) \
int _handle = Object::IsValid(_obj) ? _obj.Get<int>(IndicatorState::INDICATOR_STATE_PROP_HANDLE) : NULL; \
double _res[]; \
ResetLastError(); \
if (_handle == NULL || _handle == INVALID_HANDLE) { \
if ((_handle = NATIVE_METHOD_CALL) == INVALID_HANDLE) { \
SetUserError(ERR_USER_INVALID_HANDLE); \
return EMPTY_VALUE; \
} else if (Object::IsValid(_obj)) { \
_obj.SetHandle(_handle); \
} \
} \
if (Terminal::IsVisualMode()) { \
/* To avoid error 4806 (ERR_INDICATOR_DATA_NOT_FOUND), */ \
/* we check the number of calculated data only in visual mode. */ \
int _bars_calc = BarsCalculated(_handle); \
if (GetLastError() > 0) { \
return EMPTY_VALUE; \
} else if (_bars_calc <= 2) { \
SetUserError(ERR_USER_INVALID_BUFF_NUM); \
return EMPTY_VALUE; \
} \
} \
if (CopyBuffer(_handle, MODE, SHIFT, 1, _res) < 0) { \
return ArraySize(_res) > 0 ? _res[0] : EMPTY_VALUE; \
} \
#define INDICATOR_BUILTIN_CALL_AND_RETURN(NATIVE_METHOD_CALL, MODE, SHIFT) \
int _handle = Object::IsValid(_obj) ? _obj PTR_DEREF Get<int>(IndicatorState::INDICATOR_STATE_PROP_HANDLE) : 0; \
ARRAY(double, _res); \
ResetLastError(); \
if (_handle == 0 || _handle == INVALID_HANDLE) { \
if ((_handle = NATIVE_METHOD_CALL) == INVALID_HANDLE) { \
SetUserError(ERR_USER_INVALID_HANDLE); \
return EMPTY_VALUE; \
} else if (Object::IsValid(_obj)) { \
_obj.SetHandle(_handle); \
} \
} \
if (Terminal::IsVisualMode()) { \
/* To avoid error 4806 (ERR_INDICATOR_DATA_NOT_FOUND), */ \
/* we check the number of calculated data only in visual mode. */ \
int _bars_calc = BarsCalculated(_handle); \
if (GetLastError() > 0) { \
return EMPTY_VALUE; \
} else if (_bars_calc <= 2) { \
SetUserError(ERR_USER_INVALID_BUFF_NUM); \
return EMPTY_VALUE; \
} \
} \
if (CopyBuffer(_handle, MODE, SHIFT, 1, _res) < 0) { \
return ArraySize(_res) > 0 ? _res[0] : EMPTY_VALUE; \
} \
return _res[0];

#define INDI_REQUIRE_BARS_OR_RETURN(_indi, _period, _ret) \
Expand Down
11 changes: 4 additions & 7 deletions Indicator/IndicatorData.h
Original file line number Diff line number Diff line change
Expand Up @@ -1351,8 +1351,7 @@ class IndicatorData : public IndicatorBase {
* Returns value storage to be used for given applied price or applied price overriden by target indicator via
* SetDataSourceAppliedPrice().
*/
virtual ValueStorage<double>* GetSpecificAppliedPriceValueStorage(ENUM_APPLIED_PRICE _ap,
IndicatorData* _target = nullptr) {
ValueStorage<double>* GetSpecificAppliedPriceValueStorage(ENUM_APPLIED_PRICE _ap, IndicatorData* _target = nullptr) {
if (_target != nullptr) {
if (_target PTR_DEREF GetDataSourceAppliedType() != INDI_VS_TYPE_NONE) {
// User wants to use custom value storage type as applied price, so we forcefully override AP given as the
Expand Down Expand Up @@ -1448,15 +1447,13 @@ class IndicatorData : public IndicatorBase {
/**
* Fetches historic ticks for a given time range.
*/
virtual bool FetchHistoryByTimeRange(long _from_ms, long _to_ms, ARRAY_REF(TickTAB<double>, _out_ticks)) {
return false;
}
bool FetchHistoryByTimeRange(long _from_ms, long _to_ms, ARRAY_REF(TickTAB<double>, _out_ticks)) { return false; }

/**
* Fetches historic ticks for a given start time and minimum number of tick to retrieve.
*/
virtual bool FetchHistoryByStartTimeAndCount(long _from_ms, ENUM_ITEMS_HISTORY_DIRECTION _dir, int _min_count,
ARRAY_REF(TickTAB<double>, _out_ticks)) {
bool FetchHistoryByStartTimeAndCount(long _from_ms, ENUM_ITEMS_HISTORY_DIRECTION _dir, int _min_count,
ARRAY_REF(TickTAB<double>, _out_ticks)) {
// Print("FetchHistoryByStartTimeAndCount:");
// Print("- Requested _from_ms = ", _from_ms, ", _dir = ", EnumToString(_dir), ", _min_count = ", _min_count);

Expand Down
4 changes: 3 additions & 1 deletion Indicator/IndicatorData.struct.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#define STRUCT_ENUM_INDICATOR_STATE_PROP STRUCT_ENUM(IndicatorState, ENUM_INDICATOR_STATE_PROP)

// Includes.
#include "../Serializer/SerializerConversions.h"
#include "../Serializer/SerializerNode.enum.h"
#include "IndicatorData.enum.h"

Expand Down Expand Up @@ -389,7 +390,8 @@ struct IndicatorDataEntry {
int _asize = ArraySize(values);
string _result = "";
for (int i = 0; i < _asize; i++) {
_result += StringFormat("%s%s", (string)values[i].Get<T>(), i < _asize ? "," : "");
_result +=
StringFormat("%s%s", C_STR(SerializerConversions::ValueToString(values[i].Get<T>())), i < _asize ? "," : "");
}
return _result;
}
Expand Down
21 changes: 13 additions & 8 deletions Indicators/Indi_AC.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,15 @@
*
*/

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

// Includes.
#include "../BufferStruct.mqh"
#include "../Indicator/Indicator.h"

#ifndef __MQL4__
// Defines global functions (for MQL4 backward compability).
double iAC(string _symbol, int _tf, int _shift) {
ResetLastError();
return Indi_AC::iAC(_symbol, (ENUM_TIMEFRAMES)_tf, _shift);
}
#endif

// Structs.
struct IndiACParams : IndicatorParams {
// Struct constructor.
Expand Down Expand Up @@ -139,3 +136,11 @@ class Indi_AC : public Indicator<IndiACParams> {
return _ptr;
}
};

#ifndef __MQL4__
// Defines global functions (for MQL4 backward compability).
double iAC(string _symbol, int _tf, int _shift) {
ResetLastError();
return Indi_AC::iAC(_symbol, (ENUM_TIMEFRAMES)_tf, _shift);
}
#endif
36 changes: 0 additions & 36 deletions Indicators/Indi_RSI.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,6 @@
// Includes.
#include "../DictStruct.mqh"
#include "../Indicator/Indicator.h"
#include "Indi_Bands.mqh"
#include "Indi_CCI.mqh"
#include "Indi_Envelopes.mqh"
#include "Indi_MA.mqh"
#include "Indi_Momentum.mqh"
#include "Indi_StdDev.mqh"
#include "Price/Indi_Price.mqh"

#ifndef __MQL4__
Expand Down Expand Up @@ -336,34 +330,4 @@ class Indi_RSI : public Indicator<IndiRSIParams> {
}
return _value;
}

/**
* Provides built-in indicators whose can be used as data source.
*/
virtual IndicatorData *FetchDataSource(ENUM_INDICATOR_TYPE _id) {
if (_id == INDI_BANDS) {
IndiBandsParams bands_params;
return new Indi_Bands(bands_params);
} else if (_id == INDI_CCI) {
IndiCCIParams cci_params;
return new Indi_CCI(cci_params);
} else if (_id == INDI_ENVELOPES) {
IndiEnvelopesParams env_params;
return new Indi_Envelopes(env_params);
} else if (_id == INDI_MOMENTUM) {
IndiMomentumParams mom_params;
return new Indi_Momentum(mom_params);
} else if (_id == INDI_MA) {
IndiMAParams ma_params;
return new Indi_MA(ma_params);
} else if (_id == INDI_RSI) {
IndiRSIParams _rsi_params;
return new Indi_RSI(_rsi_params);
} else if (_id == INDI_STDDEV) {
IndiStdDevParams stddev_params;
return new Indi_StdDev(stddev_params);
}

return IndicatorData::FetchDataSource(_id);
}
};
2 changes: 1 addition & 1 deletion Indicators/Tick/Indi_TickProvider.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class Indi_TickProvider : public IndicatorTick<Indi_TickProviderParams, double,
/**
* Fetches historic ticks for a given time range.
*/
bool FetchHistoryByTimeRange(long _from_ms, long _to_ms, ARRAY_REF(TickTAB<double>, _out_ticks)) override {
bool FetchHistoryByTimeRange(long _from_ms, long _to_ms, ARRAY_REF(TickTAB<double>, _out_ticks)) {
// No history.
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion Indicators/Tick/Indi_TickRandom.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class Indi_TickRandom : public IndicatorTick<Indi_TickRandomParams, double, Item
/**
* Fetches historic ticks for a given time range.
*/
virtual bool FetchHistoryByTimeRange(long _from_ms, long _to_ms, ARRAY_REF(TickTAB<double>, _out_ticks)) {
bool FetchHistoryByTimeRange(long _from_ms, long _to_ms, ARRAY_REF(TickTAB<double>, _out_ticks)) {
// No history.
return false;
}
Expand Down
3 changes: 3 additions & 0 deletions Object.enum.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
*/

#ifndef __MQLBUILD__

#pragma once

// Used for checking the type of the object pointer.
// @docs
// - https://docs.mql4.com/constants/namedconstants/enum_pointer_type
Expand Down
3 changes: 3 additions & 0 deletions Object.extern.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@

#pragma once

// Includes.
#include "Object.enum.h"

template <typename X>
X* GetPointer(X& value) {
return &value;
Expand Down
3 changes: 3 additions & 0 deletions Platform.extern.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@
#pragma once

// Includes.
#include "Account/Account.enum.h"
#include "Data.define.h"
#include "Deal.enum.h"
#include "Object.extern.h"
#include "Order.define.h"
#include "Terminal.enum.h"

Expand Down
16 changes: 10 additions & 6 deletions Platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ class Platform {
};

bool Platform::initialized = false;
DateTime Platform::time = 0;
DateTime Platform::time = (datetime)0;
unsigned int Platform::time_flags = 0;
bool Platform::time_clear_flags = true;
int Platform::global_tick_index = 0;
Expand All @@ -385,9 +385,13 @@ int BarsCalculated(int indicator_handle) { return Platform::BarsCalculated(indic
*/
int CopyBuffer(int indicator_handle, int buffer_num, int start_pos, int count, ARRAY_REF(double, buffer)) {
Print("Not yet implemented: ", __FUNCTION__, " returns 0.");
return 0;
}

unsigned long PositionGetTicket(int _index) { Print("Not yet implemented: ", __FUNCTION__, " returns 0."); }
unsigned long PositionGetTicket(int _index) {
Print("Not yet implemented: ", __FUNCTION__, " returns 0.");
return 0;
}

long PositionGetInteger(ENUM_POSITION_PROPERTY_INTEGER property_id) {
Print("Not yet implemented: ", __FUNCTION__, " returns 0.");
Expand Down Expand Up @@ -573,20 +577,20 @@ long AccountInfoInteger(ENUM_ACCOUNT_INFO_INTEGER property_id) {

string AccountInfoInteger(ENUM_ACCOUNT_INFO_STRING property_id) {
Print("Not yet implemented: ", __FUNCTION__, " returns empty string.");
return false;
return "";
}

string Symbol() {
Print("Not yet implemented: ", __FUNCTION__, " returns empty string.");
return false;
return "";
}

string ObjectName(long _chart_id, int _pos, int _sub_window = -1, int _type = -1) {
string ObjectName(long _chart_id, int _pos, int _sub_window, int _type) {
Print("Not yet implemented: ", __FUNCTION__, " returns empty string.");
return "";
}

int ObjectsTotal(long chart_id, int type = EMPTY, int window = -1) {
int ObjectsTotal(long chart_id, int type, int window) {
Print("Not yet implemented: ", __FUNCTION__, " returns 0.");
return 0;
}
Expand Down
4 changes: 2 additions & 2 deletions Socket.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class Socket {
return true;
#else
return false;
#endif;
#endif
}

/**
Expand Down Expand Up @@ -184,7 +184,7 @@ class Socket {
}
#else
return false;
#endif;
#endif
}

/**
Expand Down
8 changes: 4 additions & 4 deletions Storage/Objects.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ class Objects {
* Tries to retrieve pointer to object for a given key. Returns true if object did exist.
*/
static bool TryGet(CONST_REF_TO(string) key, C*& out_ptr) {
int position;
if (!GetObjects().KeyExists(key, position)) {
unsigned int position;
if (!GetObjects() PTR_DEREF KeyExists(key, position)) {
out_ptr = NULL;
return false;
} else {
out_ptr = GetObjects().GetByPos(position).Ptr();
out_ptr = GetObjects() PTR_DEREF GetByPos(position).Ptr();
return true;
}
}
Expand All @@ -64,7 +64,7 @@ class Objects {
*/
static C* Set(CONST_REF_TO(string) key, C* ptr) {
Ref<C> _ref(ptr);
GetObjects().Set(key, _ref);
GetObjects() PTR_DEREF Set(key, _ref);
return ptr;
}
};
5 changes: 4 additions & 1 deletion SymbolInfo.struct.static.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@

#include "MQL5.mqh"
#include "Order.enum.h"
#include "Platform.extern.h"
#include "Std.h"
#include "SymbolInfo.enum.h"
#include "SymbolInfo.extern.h"
#include "Tick/Tick.struct.h"

/**
Expand All @@ -38,7 +41,7 @@ struct SymbolInfoStatic {
/**
* Get the current symbol pair from the current chart.
*/
static string GetCurrentSymbol() { return _Symbol; }
static string GetCurrentSymbol() { return ::Symbol(); }

/**
* Updates and gets the latest tick prices.
Expand Down

0 comments on commit 65b8f29

Please sign in to comment.