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 5, 2024
1 parent fd11f69 commit 999de5f
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 55 deletions.
2 changes: 1 addition & 1 deletion Indicator/Indicator.struct.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ struct IndicatorParams {
void Set(STRUCT_ENUM(IndicatorParams, ENUM_INDI_PARAMS_PROP) _prop, T _value) {
switch (_prop) {
case INDI_PARAMS_PROP_BPS:
bps = (uint)_value;
bps = (unsigned int)_value;
return;
default:
break;
Expand Down
2 changes: 1 addition & 1 deletion Indicator/IndicatorTf.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class IndicatorTf : public IndicatorCandle<TFP, double, ItemsHistoryTfCandleProv
/**
* Class constructor with timeframe index.
*/
IndicatorTf(ENUM_TIMEFRAMES_INDEX _tfi = 0) {
IndicatorTf(ENUM_TIMEFRAMES_INDEX _tfi = (ENUM_TIMEFRAMES_INDEX)0) {
SetTf(ChartTf::IndexToTf(_tfi));
Init();
}
Expand Down
16 changes: 9 additions & 7 deletions Platform/Chart/Chart.enum.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

#ifndef __MQL__
Expand All @@ -43,7 +43,9 @@ enum ENUM_APPLIED_PRICE {
PRICE_MEDIAN, // Median price (H+L)/2
PRICE_TYPICAL, // Typical price, (H+L+C)/3
PRICE_WEIGHTED, // Weighted close price (H+L+C+C)/4
FINAL_APPLIED_PRICE_ENTRY
FINAL_APPLIED_PRICE_ENTRY,
__PRICE_ASK = 128, // Required, so PRICE_ASK define could work without throwing compilation error.
__PRICE_BID = 129, // Required, so PRICE_BID define could work without throwing compilation error.
};
#endif

Expand Down Expand Up @@ -126,9 +128,9 @@ enum ENUM_TIMEFRAMES {
PERIOD_MN1 = 43200 // 1 month.
};

#ifdef EMSCRIPTEN
#include <emscripten.h>
#include <emscripten/bind.h>
#ifdef EMSCRIPTEN
#include <emscripten.h>
#include <emscripten/bind.h>

EMSCRIPTEN_BINDINGS(ENUM_TIMEFRAMES) {
emscripten::enum_<ENUM_TIMEFRAMES>("timeframes")
Expand Down Expand Up @@ -165,7 +167,7 @@ EMSCRIPTEN_BINDINGS(ENUM_APPLIED_PRICE) {
.value("weighted", PRICE_WEIGHTED);
}

#endif
#endif

#endif

Expand Down
38 changes: 20 additions & 18 deletions Platform/Order.enum.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

/* Order actions. */
Expand Down Expand Up @@ -92,17 +92,17 @@ enum ENUM_ORDER_PROPERTY_CUSTOM {

// Defines enumeration for order close reasons.
enum ENUM_ORDER_REASON_CLOSE {
ORDER_REASON_CLOSED_ALL = 0, // Closed all
ORDER_REASON_CLOSED_BY_ACTION, // Closed by action
ORDER_REASON_CLOSED_BY_CONDITION, // Closed by condition
ORDER_REASON_CLOSED_BY_EXPIRE, // Closed by expiration
ORDER_REASON_CLOSED_BY_OPPOSITE, // Closed by opposite order
ORDER_REASON_CLOSED_BY_SIGNAL, // Closed by signal
ORDER_REASON_CLOSED_BY_SL, // Closed by stop loss
ORDER_REASON_CLOSED_BY_TEST, // Closed by test
ORDER_REASON_CLOSED_BY_TP, // Closed by take profit
ORDER_REASON_CLOSED_BY_USER, // Closed by user
ORDER_REASON_CLOSED_UNKNOWN, // Closed by unknown event
ORDER_REASON_CLOSED_ALL = 0, // Closed all
ORDER_REASON_CLOSED_BY_ACTION, // Closed by action
ORDER_REASON_CLOSED_BY_CONDITION, // Closed by condition
ORDER_REASON_CLOSED_BY_EXPIRE, // Closed by expiration
ORDER_REASON_CLOSED_BY_OPPOSITE, // Closed by opposite order
ORDER_REASON_CLOSED_BY_SIGNAL, // Closed by signal
ORDER_REASON_CLOSED_BY_SL, // Closed by stop loss
ORDER_REASON_CLOSED_BY_TEST, // Closed by test
ORDER_REASON_CLOSED_BY_TP, // Closed by take profit
ORDER_REASON_CLOSED_BY_USER, // Closed by user
ORDER_REASON_CLOSED_UNKNOWN, // Closed by unknown event
};

#ifndef __MQL5__
Expand Down Expand Up @@ -209,7 +209,8 @@ enum ENUM_ORDER_PROPERTY_INTEGER {
ORDER_MAGIC, // ID of an Expert Advisor that has placed the order.
ORDER_REASON, // The reason or source for placing an order.
ORDER_POSITION_ID, // Position identifier that is set to an order as soon as it is executed.
ORDER_POSITION_BY_ID // Identifier of an opposite position used for closing by order ORDER_TYPE_CLOSE_BY.
ORDER_POSITION_BY_ID, // Identifier of an opposite position used for closing by order ORDER_TYPE_CLOSE_BY.
__ORDER_REASON = 23, // Required, so ORDER_REASON define could work without throwing compilation error.
};

/**
Expand All @@ -219,9 +220,10 @@ enum ENUM_ORDER_PROPERTY_INTEGER {
* @see: https://www.mql5.com/en/docs/constants/tradingconstants/orderproperties
*/
enum ENUM_ORDER_PROPERTY_STRING {
ORDER_COMMENT, // Order comment.
ORDER_EXTERNAL_ID, // Order identifier in an external trading system (on the Exchange).
ORDER_SYMBOL, // Symbol of the order.
ORDER_COMMENT, // Order comment.
ORDER_EXTERNAL_ID, // Order identifier in an external trading system (on the Exchange).
ORDER_SYMBOL, // Symbol of the order.
__ORDER_EXTERNAL_ID = 20 // Required, so ORDER_EXTERNAL_ID define could work without throwing compilation error.
};
#endif

Expand Down Expand Up @@ -249,7 +251,7 @@ enum ENUM_ORDER_TYPE {
ORDER_TYPE_UNSET // A NULL value.
};
#else
#define ORDER_TYPE_UNSET NULL
#define ORDER_TYPE_UNSET NULL
#endif

/* Positions */
Expand Down
14 changes: 7 additions & 7 deletions Platform/Order.h
Original file line number Diff line number Diff line change
Expand Up @@ -931,11 +931,11 @@ class Order : public SymbolInfo {
_request.action = TRADE_ACTION_DEAL;
_request.comment = _comment != "" ? _comment : odata.GetReasonCloseText();
_request.deviation = orequest.deviation > 0 ? orequest.deviation : 40;
_request.magic = odata.Get<ulong>(ORDER_MAGIC);
_request.magic = odata.Get<unsigned long>(ORDER_MAGIC);
_request.symbol = odata.Get(ORDER_SYMBOL);
_request.type = NegateOrderType(odata.Get<ENUM_ORDER_TYPE>(ORDER_TYPE));
_request.type_filling = GetOrderFilling(odata.Get(ORDER_SYMBOL));
_request.position = odata.Get<ulong>(ORDER_PROP_TICKET);
_request.position = odata.Get<unsigned long>(ORDER_PROP_TICKET);
_request.price = SymbolInfo::GetCloseOffer(odata.Get<ENUM_ORDER_TYPE>(ORDER_TYPE));
_request.volume = odata.Get<double>(ORDER_VOLUME_CURRENT);
Order::OrderSend(_request, oresult, oresult_check);
Expand All @@ -959,12 +959,12 @@ class Order : public SymbolInfo {
if (OrderSelect()) {
Refresh(true);
if (!IsClosed()) {
ologger.Error(
StringFormat("Failed to send order request %u for position %d! Error: %d (%s)", oresult.request_id,
_request.position, fmax(oresult.retcode, oresult_check.retcode), oresult_check.comment),
__FUNCTION_LINE__);
ologger.Error(StringFormat("Failed to send order request %u for position %d! Error: %d (%s)",
oresult.request_id, _request.position,
fmax(oresult.retcode, oresult_check.retcode), C_STR(oresult_check.comment)),
__FUNCTION_LINE__);
if (ologger.GetLevel() >= V_DEBUG) {
ologger.Debug(StringFormat("Failed request: %s", ToString()), __FUNCTION_LINE__);
ologger.Debug(StringFormat("Failed request: %s", C_STR(ToString())), __FUNCTION_LINE__);
}
}
}
Expand Down
11 changes: 5 additions & 6 deletions Platform/Order.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 @@ -473,7 +473,8 @@ struct OrderData {
* Returns a comment with reason
*/
string GetCloseComment() {
string _result = StringFormat("%s (mn=%d,pips=%d)", GetReasonCloseText(), magic, Get<int>(ORDER_PROP_PROFIT_PIPS));
string _result =
StringFormat("%s (mn=%d,pips=%d)", C_STR(GetReasonCloseText()), magic, Get<int>(ORDER_PROP_PROFIT_PIPS));
return _result;
}

Expand Down Expand Up @@ -511,9 +512,7 @@ struct OrderData {
return "???";
}
// Setters.
void IncCloseTries() {
close_tries++;
}
void IncCloseTries() { close_tries++; }
template <typename T>
void Set(ENUM_ORDER_PROPERTY_CUSTOM _prop_name, T _value) {
switch (_prop_name) {
Expand Down
7 changes: 4 additions & 3 deletions Storage/ItemsHistory.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,15 @@
#pragma once
#endif

#include "../Refs.mqh"
#include "../Storage/Dict/DictStruct.h"

/**
* Direction used by ItemsHistoryItemProvider's methods.
*/
enum ENUM_ITEMS_HISTORY_DIRECTION { ITEMS_HISTORY_DIRECTION_FORWARD, ITEMS_HISTORY_DIRECTION_BACKWARD };

#include "../Indicator/IndicatorData.h"
#include "../Refs.mqh"
#include "../Storage/Dict/DictStruct.h"

/**
* Forward declaration.
*/
Expand Down
6 changes: 1 addition & 5 deletions Storage/ValueStorage.indicator.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,13 @@ class IndicatorBufferValueStorage : public HistoryValueStorage<C> {
};

// clang-format off
#include "../Indicator/IndicatorData.h"
#include "../Indicator/IndicatorBase.h"
// clang-format on

#ifndef __MQL__
template <typename C>
C IndicatorBufferValueStorage<C>::Fetch(int _rel_shift) {
IndicatorBase* _indi = THIS_ATTR indi_candle.Ptr();
#ifdef __MQL__
return _indi PTR_DEREF GetValue<C>(mode, THIS_ATTR RealShift(_rel_shift));
#else
return _indi PTR_DEREF template GetValue<C>(mode, THIS_ATTR RealShift(_rel_shift));
#endif
}
#endif
16 changes: 9 additions & 7 deletions Trade.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,8 @@ class Trade : public Taskable<DataParamEntry> {
MqlTradeRequest _request = {(ENUM_TRADE_REQUEST_ACTIONS)0};
_request.action = TRADE_ACTION_DEAL;
_request.comment = _comment;
_request.deviation = tparams.Get<uint>(TRADE_PARAM_SLIPPAGE); // The maximal price deviation, specified in points.
_request.deviation =
tparams.Get<unsigned int>(TRADE_PARAM_SLIPPAGE); // The maximal price deviation, specified in points.
_request.magic = _magic > 0 ? _magic : tparams.Get<int64>(TRADE_PARAM_MAGIC_NO);
_request.symbol = GetSource() PTR_DEREF GetSymbol();
_request.price = GetSource() PTR_DEREF GetOpenOffer(_type);
Expand Down Expand Up @@ -888,11 +889,12 @@ HistorySelect(0, TimeCurrent()); // Select history for access.
OrderMoveToHistory(_order.Ptr());
order_last = _order;
} else {
logger.Error(StringFormat("Failed to close the order: %d! Error: %d (%s)",
_order REF_DEREF Get<long>(ORDER_PROP_TICKET),
_order REF_DEREF Get<unsigned int>(ORDER_PROP_LAST_ERROR),
Terminal::GetErrorText(_order REF_DEREF Get<unsigned int>(ORDER_PROP_LAST_ERROR))),
__FUNCTION_LINE__);
logger.Error(
StringFormat("Failed to close the order: %d! Error: %d (%s)",
_order REF_DEREF Get<long>(ORDER_PROP_TICKET),
_order REF_DEREF Get<unsigned int>(ORDER_PROP_LAST_ERROR),
C_STR(Terminal::GetErrorText(_order REF_DEREF Get<unsigned int>(ORDER_PROP_LAST_ERROR)))),
__FUNCTION_LINE__);
continue;
}
} else {
Expand Down Expand Up @@ -929,7 +931,7 @@ HistorySelect(0, TimeCurrent()); // Select history for access.
StringFormat("Failed to close the order: %d! Error: %d (%s)",
_order REF_DEREF Get<long>(ORDER_PROP_TICKET),
_order REF_DEREF Get<unsigned int>(ORDER_PROP_LAST_ERROR),
Terminal::GetErrorText(_order REF_DEREF Get<unsigned int>(ORDER_PROP_LAST_ERROR))),
C_STR(Terminal::GetErrorText(_order REF_DEREF Get<unsigned int>(ORDER_PROP_LAST_ERROR)))),
__FUNCTION_LINE__);
continue;
}
Expand Down

0 comments on commit 999de5f

Please sign in to comment.