为什么 MT4 - ChartSetSymbolPeriod() - 会减慢平台速度?
Why MT4 - ChartSetSymbolPeriod() - slows down the platform?
我尝试将 ChartSetSymbolPeriod()
用于我的 [自定义指标],但是当我尝试将它与另一个 [智能交易系统] 一起使用时,该指标会减慢我的 MT4 平台].
特别是在“订单、市场深度”类型的 [Expert Advisors] 时。
//+------------------------------------------------------------------+
//| ChangeSymbol Indicator.mq4 |
//| Copyright 2016, MetaQuotes Software Corp. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2016, MetaQuotes Software Corp."
#property link "https://www.mql5.com"
#property version "1.00"
#property strict
#property indicator_chart_window
string ChangeSP = "Where I go?";
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit() {
//---
ObjectCreate ( 0, ChangeSP, OBJ_BUTTON, 0, 0, 0 );
ObjectSetInteger ( 0, ChangeSP, OBJPROP_XDISTANCE, 15 );
ObjectSetInteger ( 0, ChangeSP, OBJPROP_YDISTANCE, 100 );
ObjectSetInteger ( 0, ChangeSP, OBJPROP_XSIZE, 200 );
ObjectSetInteger ( 0, ChangeSP, OBJPROP_YSIZE, 40 );
ObjectSetString ( 0, ChangeSP, OBJPROP_TEXT, "Go to GBPUSD M15" );
ObjectSetInteger ( 0, ChangeSP, OBJPROP_COLOR, White );
ObjectSetInteger ( 0, ChangeSP, OBJPROP_BGCOLOR, Red );
ObjectSetInteger ( 0, ChangeSP, OBJPROP_BORDER_COLOR, Red );
ObjectSetInteger ( 0, ChangeSP, OBJPROP_BORDER_TYPE, BORDER_FLAT );
ObjectSetInteger ( 0, ChangeSP, OBJPROP_BACK, false );
ObjectSetInteger ( 0, ChangeSP, OBJPROP_HIDDEN, true );
ObjectSetInteger ( 0, ChangeSP, OBJPROP_STATE, false );
ObjectSetInteger ( 0, ChangeSP, OBJPROP_FONTSIZE, 12 );
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start(){
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit(){
return(0);
}
//+------------------------------------------------------------------+
void OnChartEvent( const int id,
const long &lparam,
const double &dparam,
const string &sparam
) {
if ( sparam == ChangeSP ) {
ChangeSPClick( ChangeSP );
ObjectSetInteger( 0, ChangeSP, OBJPROP_STATE, false );
}
}
//+------------------------------------------------------------------+
void ChangeSPClick( bool ChartSetSymbolPeriod ) {
bool ChangeSP_action = ChartSetSymbolPeriod( 0, "GBPUSD", 15 );
}
性能?
第一:所有 [自定义指标] 共享一个线程!
这个 New-MQL4.56789
架构特性对非阻塞的注意提出了更高的要求, [自定义指标]中以性能为中心的代码。
MQL4 文档接下来指出,对 ChartSetSymbolPeriod()
的调用不是同步的,而只是向 TaskQueue 添加了一张票。
ChartSetSymbolPeriod()
Changes the symbol and period of the specified chart. The function is asynchronous, i.e. it sends the command and does not wait for its execution completion. The command is added to chart message queue and executed only after all previous commands have been processed.
队列中可能还有什么?
MQL4 识别以下类型的 <ChartEVENT>
-s :
OnChartEvent()
is the handler of a group of ChartEvent events:
·CHARTEVENT_KEYDOWN
— event of a keystroke, when the chart window is focused;
·CHARTEVENT_MOUSE_MOVE
— mouse move events and mouse click events ( if CHART_EVENT_MOUSE_MOVE = true
is set for the chart );
·CHARTEVENT_OBJECT_CREATE
— event of graphical object creation ( if CHART_EVENT_OBJECT_CREATE = true
is set for the chart );
·CHARTEVENT_OBJECT_CHANGE
— event of change of an object property via the properties dialog;
·CHARTEVENT_OBJECT_DELETE
— event of graphical object deletion ( if CHART_EVENT_OBJECT_DELETE = true
is set for the chart );
·CHARTEVENT_OBJECT_CLICK
— event of a mouse click in a graphical object belonging to the chart;
·CHARTEVENT_OBJECT_DRAG
— event of a graphical object move using the mouse;
·CHARTEVENT_OBJECT_ENDEDIT
— event of the finished text editing in the entry box of the LabelEdit graphical object;
·CHARTEVENT_CLICK
— event of a mouse click on the chart;
·CHARTEVENT_CHART_CHANGE
— event of chart changes; <<<<<<<<<<<<<<<<<<<<
·CHARTEVENT_CUSTOM + n
— ID of the user event, where n is in the range from 0 to 65535.
·CHARTEVENT_CUSTOM_LAST
— the last acceptable ID of a custom event == ( CHARTEVENT_CUSTOM +65535 )
.
Symbol 和 Period 的变化是一项主要的图表工作,它使 [MetaTrader Terminal 4] 丢弃所有当前状态图表中描绘的工具,接下来进入后台并从 [HistoryCentre]
中获取所有历史保存的记录(尝试 F2 以查看正在运行的功能)并且它必须相应地重新绘制 GUI。
你猜怎么着,
1) 这需要 一些时间
2) 这使得 <ChartEVENT>
再次触发 OnChartEvent()
处理程序。
3) 移回 "Square No. 1"
它是否创建了一个鼠标陷阱轮布置,必须 运行 无限循环?
是的,它确实如此。
此外,人们可能已经注意到副作用
函数调用签名中的名称掩盖了 MQL4 函数的名称
//+------------------------------------------------------------------+
void ChangeSPClick( bool ChartSetSymbolPeriod ) {
bool ChangeSP_action = ChartSetSymbolPeriod( 0, "GBPUSD", 15 );
}
我尝试将 ChartSetSymbolPeriod()
用于我的 [自定义指标],但是当我尝试将它与另一个 [智能交易系统] 一起使用时,该指标会减慢我的 MT4 平台].
特别是在“订单、市场深度”类型的 [Expert Advisors] 时。
//+------------------------------------------------------------------+
//| ChangeSymbol Indicator.mq4 |
//| Copyright 2016, MetaQuotes Software Corp. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2016, MetaQuotes Software Corp."
#property link "https://www.mql5.com"
#property version "1.00"
#property strict
#property indicator_chart_window
string ChangeSP = "Where I go?";
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit() {
//---
ObjectCreate ( 0, ChangeSP, OBJ_BUTTON, 0, 0, 0 );
ObjectSetInteger ( 0, ChangeSP, OBJPROP_XDISTANCE, 15 );
ObjectSetInteger ( 0, ChangeSP, OBJPROP_YDISTANCE, 100 );
ObjectSetInteger ( 0, ChangeSP, OBJPROP_XSIZE, 200 );
ObjectSetInteger ( 0, ChangeSP, OBJPROP_YSIZE, 40 );
ObjectSetString ( 0, ChangeSP, OBJPROP_TEXT, "Go to GBPUSD M15" );
ObjectSetInteger ( 0, ChangeSP, OBJPROP_COLOR, White );
ObjectSetInteger ( 0, ChangeSP, OBJPROP_BGCOLOR, Red );
ObjectSetInteger ( 0, ChangeSP, OBJPROP_BORDER_COLOR, Red );
ObjectSetInteger ( 0, ChangeSP, OBJPROP_BORDER_TYPE, BORDER_FLAT );
ObjectSetInteger ( 0, ChangeSP, OBJPROP_BACK, false );
ObjectSetInteger ( 0, ChangeSP, OBJPROP_HIDDEN, true );
ObjectSetInteger ( 0, ChangeSP, OBJPROP_STATE, false );
ObjectSetInteger ( 0, ChangeSP, OBJPROP_FONTSIZE, 12 );
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start(){
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit(){
return(0);
}
//+------------------------------------------------------------------+
void OnChartEvent( const int id,
const long &lparam,
const double &dparam,
const string &sparam
) {
if ( sparam == ChangeSP ) {
ChangeSPClick( ChangeSP );
ObjectSetInteger( 0, ChangeSP, OBJPROP_STATE, false );
}
}
//+------------------------------------------------------------------+
void ChangeSPClick( bool ChartSetSymbolPeriod ) {
bool ChangeSP_action = ChartSetSymbolPeriod( 0, "GBPUSD", 15 );
}
性能?
第一:所有 [自定义指标] 共享一个线程!
这个 New-MQL4.56789
架构特性对非阻塞的注意提出了更高的要求, [自定义指标]中以性能为中心的代码。
MQL4 文档接下来指出,对 ChartSetSymbolPeriod()
的调用不是同步的,而只是向 TaskQueue 添加了一张票。
ChartSetSymbolPeriod()
Changes the symbol and period of the specified chart. The function is asynchronous, i.e. it sends the command and does not wait for its execution completion. The command is added to chart message queue and executed only after all previous commands have been processed.
队列中可能还有什么?
MQL4 识别以下类型的 <ChartEVENT>
-s :
OnChartEvent()
is the handler of a group of ChartEvent events:
·CHARTEVENT_KEYDOWN
— event of a keystroke, when the chart window is focused;
·CHARTEVENT_MOUSE_MOVE
— mouse move events and mouse click events ( ifCHART_EVENT_MOUSE_MOVE = true
is set for the chart );
·CHARTEVENT_OBJECT_CREATE
— event of graphical object creation ( ifCHART_EVENT_OBJECT_CREATE = true
is set for the chart );
·CHARTEVENT_OBJECT_CHANGE
— event of change of an object property via the properties dialog;
·CHARTEVENT_OBJECT_DELETE
— event of graphical object deletion ( ifCHART_EVENT_OBJECT_DELETE = true
is set for the chart );
·CHARTEVENT_OBJECT_CLICK
— event of a mouse click in a graphical object belonging to the chart;
·CHARTEVENT_OBJECT_DRAG
— event of a graphical object move using the mouse;
·CHARTEVENT_OBJECT_ENDEDIT
— event of the finished text editing in the entry box of the LabelEdit graphical object;
·CHARTEVENT_CLICK
— event of a mouse click on the chart;
·CHARTEVENT_CHART_CHANGE
— event of chart changes;<<<<<<<<<<<<<<<<<<<<
·CHARTEVENT_CUSTOM + n
— ID of the user event, where n is in the range from 0 to 65535.
·CHARTEVENT_CUSTOM_LAST
— the last acceptable ID of a custom event== ( CHARTEVENT_CUSTOM +65535 )
.
Symbol 和 Period 的变化是一项主要的图表工作,它使 [MetaTrader Terminal 4] 丢弃所有当前状态图表中描绘的工具,接下来进入后台并从 [HistoryCentre]
中获取所有历史保存的记录(尝试 F2 以查看正在运行的功能)并且它必须相应地重新绘制 GUI。
你猜怎么着,
1) 这需要 一些时间
2) 这使得 <ChartEVENT>
再次触发 OnChartEvent()
处理程序。
3) 移回 "Square No. 1"
它是否创建了一个鼠标陷阱轮布置,必须 运行 无限循环?
是的,它确实如此。
此外,人们可能已经注意到副作用
函数调用签名中的名称掩盖了 MQL4 函数的名称
//+------------------------------------------------------------------+
void ChangeSPClick( bool ChartSetSymbolPeriod ) {
bool ChangeSP_action = ChartSetSymbolPeriod( 0, "GBPUSD", 15 );
}