如何向 MQL5 中的内置结构添加新项?

How to add a new item to the builtin struct in MQL5?

我有以下示例 MQL5 代码(用于演示问题):

// PositionSelectByTicket is missing in older MQL5 builds.
#ifndef PositionSelectByTicket
#define PositionSelectByTicket(ticket) OrderSelect(ticket)
#endif 

void CheckOrder(const MqlTradeRequest &Request) {

  if (Request.action == TRADE_ACTION_SLTP) {
    ulong pos = PositionSelectByTicket(Request.position); // error 130: 'position' - struct member undefined
  }

}

void OnStart() { }

它在最新版本的 Metaeditor 5(版本 1495)上编译良好,但是在版本 1162(使用较旧的 mql 编译器)中我遇到了以下错误:

$ wine mql /s /mql5 MQL_Test.mq5
MQL4/MQL5 Compiler build 1162 (02 Jul 2015)
MQL_Test.mq5 : information: Checking 'MQL_Test.mq5'
MQL_Test.mq5(9,17) : error 130: 'position' - struct member undefined
MQL_Test.mq5(9,17) : warning 60: possible use of uninitialized variable ''
 : information: Result 1 error(s), 1 warning(s)
Time: 11 ms

我想改进代码以实现向后兼容,并且我已经为 PositionSelectByTicket 添加了上述定义以避免未定义的函数。

尽管如何修复上述错误以在两个编译器上工作?

documentation page of MqlTradeRequest struct 中存在 position 结构项,因此它很可能是在最近的构建中添加的。

那么,有什么方法可以将缺少的变量项添加到现有的内置结构中,以便旧的编译器能够通过语法检查?

您知道 PositionBySelect() 是自 Build 1325(一种新的对冲模式)以来可用的新功能吗?

new MetaTrader 5 Terminal release notes

12: Added PositionSelectByTicket function — select an open position for further work by a specified ticket.

bool  PositionSelectByTicket(ulong ticket );    // position ticket