DoEasy 函数库中的其他类(第七十一部分):图表对象集合事件·进阶篇
📊

DoEasy 函数库中的其他类(第七十一部分):图表对象集合事件·进阶篇

(2/3)· 手动改图表常漏掉批量变动,本篇把对象增删做成可追踪的事件流

新手友好 第 2/3 篇
手动拖指标、关子窗口时,程序往往只捕捉到最后一个动作,前面那批变动就丢了。把图表对象的增删做成事件集合,才能在单次计时器里分清谁变了、怎么变的。

图表属性枚举里的可见区域与配色钩子

在 MT5 的图表对象模型里,CHART_PROP_* 系列枚举直接暴露了图表的几何与视觉状态。做价格行为分析时,最先要盯的是可见范围类属性:CHART_PROP_VISIBLE_BARS 给出图表当前可显示的 K 线总数,CHART_PROP_FIRST_VISIBLE_BAR 标记最左侧那根可见 Bar 的编号,两者相减能反推出视窗右边界位置。 CHART_PROP_WIDTH_IN_BARS 与 CHART_PROP_WIDTH_IN_PIXELS 是一对互补量——前者以 Bar 计宽,后者以像素计宽。若你的屏幕横向分辨率为 1920 像素,而该属性返回 960,则单根 Bar 平均占用约 2 像素,这种极端压缩下裸 K 形态会严重失真,倾向误判影线。 配色类属性则是自动化标注的前提。CHART_PROP_COLOR_CHART_UP / DOWN 控制涨跌 Bar 的边框,CHART_PROP_COLOR_CANDLE_BULL / BEAR 控制实体填充;用 ChartGetInteger 读出来后,你可以在 EA 里比对当前主题是否暗色,从而切换 overlay 线条的对比色。外汇与贵金属杠杆高,视觉错位可能放大错单概率,读取后务必在 MT5 视觉回放里人工复核一次。 CHART_PROP_SHOW_TRADE_LEVELS 决定是否绘制持仓与挂单水平线。写脚本批量截图时若忘了同步这个属性,可能出现「实盘有 SL 线、回测图无 SL 线」的偏差,让形态统计失效。

MQL5 / C++
CHART_PROP_VISIBLE_BARS,                                                                     class=class="str">"cmt">// Number of bars on a chart that are available for display
CHART_PROP_WINDOWS_TOTAL,                                                                       class=class="str">"cmt">// The total number of chart windows including indicator subwindows
CHART_PROP_WINDOW_HANDLE,                                                                       class=class="str">"cmt">// Chart window handle
CHART_PROP_WINDOW_YDISTANCE,                                                                    class=class="str">"cmt">// Distance in Y axis pixels between the upper frame of the indicator subwindow and the upper frame of the chart main window
CHART_PROP_FIRST_VISIBLE_BAR,                                                                   class=class="str">"cmt">// Number of the first visible bar on the chart
CHART_PROP_WIDTH_IN_BARS,                                                                       class=class="str">"cmt">// Width of the chart in bars
CHART_PROP_WIDTH_IN_PIXELS,                                                                     class=class="str">"cmt">// Width of the chart in pixels
CHART_PROP_HEIGHT_IN_PIXELS,                                                                    class=class="str">"cmt">// Height of the chart in pixels
CHART_PROP_COLOR_BACKGROUND,                                                                    class=class="str">"cmt">// Color of background of the chart
CHART_PROP_COLOR_FOREGROUND,                                                                    class=class="str">"cmt">// Color of axes, scale and OHLC line
CHART_PROP_COLOR_GRID,                                                                          class=class="str">"cmt">// Grid class="type">class="kw">color
CHART_PROP_COLOR_VOLUME,                                                                        class=class="str">"cmt">// Color of volumes and position opening levels
CHART_PROP_COLOR_CHART_UP,                                                                      class=class="str">"cmt">// Color for the up bar, shadows and body borders of bull candlesticks
CHART_PROP_COLOR_CHART_DOWN,                                                                    class=class="str">"cmt">// Color of down bar, its shadow and border of body of the bullish candlestick
CHART_PROP_COLOR_CHART_LINE,                                                                    class=class="str">"cmt">// Color of the chart line and the Doji candlesticks
CHART_PROP_COLOR_CANDLE_BULL,                                                                   class=class="str">"cmt">// Color of body of a bullish candlestick
CHART_PROP_COLOR_CANDLE_BEAR,                                                                   class=class="str">"cmt">// Color of body of a bearish candlestick
CHART_PROP_COLOR_BID,                                                                           class=class="str">"cmt">// Color of the Bid price line
CHART_PROP_COLOR_ASK,                                                                           class=class="str">"cmt">// Color of the Ask price line
CHART_PROP_COLOR_LAST,                                                                          class=class="str">"cmt">// Color of the last performed deal&class="macro">#x27;s price line(Last)
CHART_PROP_COLOR_STOP_LEVEL,                                                                    class=class="str">"cmt">// Color of stop order levels(Stop Loss and Take Profit)
CHART_PROP_SHOW_TRADE_LEVELS                                                                    class=class="str">"cmt">// Display trade levels on the chart(levels of open positions, Stop Loss, Take Profit and pending orders)

「图表整数属性的尾段与排序基址」

上面这段枚举收尾列出了图表窗口的交互与布局类整数属性,从鼠标拖拽交易水平线(CHART_PROP_DRAG_TRADE_LEVELS)到非停靠窗口相对虚拟屏幕的四至坐标,都属于可被 ChartGetInteger/ChartSetInteger 读写的运行时状态。其中 CHART_PROP_WINDOW_NUM 标黄项指明指标所在图表子窗口序号,多窗体 EA 定位绘图层时必用。 宏定义给出两个硬数字:整数属性总量 CHART_PROP_INTEGER_TOTAL 为 67,排序跳过量 CHART_PROP_INTEGER_SKIP 为 0,说明全部整数属性都参与后续排序逻辑,没有为 DOM 预留废弃位。 排序基址由 FIRST_CHART_DBL_PROP 与 FIRST_CHART_STR_PROP 算出,前者等于 67-0,即双精度属性从枚举值 67 起跳;字符串属性再叠加双精度总量偏移。ENUM_SORT_CHART_MODE 里 SORT_BY_CHART_ID=0 与 SORT_BY_CHART_TIMEFRAME 表明,图表集合既能按 ID 也能按周期归类,写多图表管理器时可直接套用这两个枚举值。 开 MT5 在 MetaEditor 搜 CHART_PROP_WINDOW_NUM,改一下附属窗口指标测试其返回值,能验证上面偏移计算是否与你当前终端版本一致。外汇与贵金属杠杆品种波动剧烈,脚本仅作界面状态管理,不涉及方向判断,实操请自担高风险。

MQL5 / C++
  CHART_PROP_DRAG_TRADE_LEVELS,                                           class=class="str">"cmt">// Enable the ability to drag trading levels on a chart using mouse
  CHART_PROP_SHOW_DATE_SCALE,                                             class=class="str">"cmt">// Display the time scale on a chart
  CHART_PROP_SHOW_PRICE_SCALE,                                            class=class="str">"cmt">// Display a price scale on a chart
  CHART_PROP_SHOW_ONE_CLICK,                                              class=class="str">"cmt">// Display the quick trading panel on the chart
  CHART_PROP_IS_MAXIMIZED,                                                class=class="str">"cmt">// Chart window maximized
  CHART_PROP_IS_MINIMIZED,                                                class=class="str">"cmt">// Chart window minimized
  CHART_PROP_IS_DOCKED,                                                   class=class="str">"cmt">// Chart window docked
  CHART_PROP_FLOAT_LEFT,                                                  class=class="str">"cmt">// Left coordinate of the undocked chart window relative to the class="kw">virtual screen
  CHART_PROP_FLOAT_TOP,                                                   class=class="str">"cmt">// Upper coordinate of the undocked chart window relative to the class="kw">virtual screen
  CHART_PROP_FLOAT_RIGHT,                                                 class=class="str">"cmt">// Right coordinate of the undocked chart window relative to the class="kw">virtual screen
  CHART_PROP_FLOAT_BOTTOM,                                                class=class="str">"cmt">// Bottom coordinate of the undocked chart window relative to the class="kw">virtual screen
  class=class="str">"cmt">//--- CWndInd
  CHART_PROP_WINDOW_IND_HANDLE,                                           class=class="str">"cmt">// Indicator handle in the chart window
  CHART_PROP_WINDOW_IND_INDEX,                                            class=class="str">"cmt">// Indicator index in the chart window
  CHART_PROP_WINDOW_NUM,                                                  class=class="str">"cmt">// Chart window index
  };
class="macro">#define CHART_PROP_INTEGER_TOTAL(class="num">67)                                     class=class="str">"cmt">// Total number of integer properties
class="macro">#define CHART_PROP_INTEGER_SKIP(class="num">0)                                      class=class="str">"cmt">// Number of integer DOM properties not used in sorting
class=class="str">"cmt">//+------------------------------------------------------------------+
class=class="str">"cmt">//+------------------------------------------------------------------+
class=class="str">"cmt">//| Possible chart sorting criteria                                  |
class=class="str">"cmt">//+------------------------------------------------------------------+
class="macro">#define FIRST_CHART_DBL_PROP(CHART_PROP_INTEGER_TOTAL-CHART_PROP_INTEGER_SKIP)
class="macro">#define FIRST_CHART_STR_PROP(CHART_PROP_INTEGER_TOTAL-CHART_PROP_INTEGER_SKIP+CHART_PROP_DOUBLE_TOTAL-CHART_PROP_DOUBLE_SKIP)
enum ENUM_SORT_CHART_MODE
  {
class=class="str">"cmt">//--- Sort by integer properties
  SORT_BY_CHART_ID = class="num">0,                                                   class=class="str">"cmt">// Sort by chart ID
  SORT_BY_CHART_TIMEFRAME,                                                class=class="str">"cmt">// Sort by chart timeframe

◍ 图表对象枚举里的排序锚点

在 MQL5 里用 ChartGetInteger 或 ChartSetInteger 遍历多图表时,这组 SORT_BY_CHART_* 枚举决定了你按哪个属性把图表对象排进列表。它们不是指标参数,而是图表自身状态开关的索引标签。 比如 SORT_BY_CHART_SHOW 对应价格图是否绘制的属性,SORT_BY_CHART_IS_OBJECT 区分该条目是不是 OBJ_CHART 类型的图表对象,SORT_BY_CHART_BRING_TO_TOP 则看图表是否被设为置顶显示。 交互类开关也在这里:SORT_BY_CHART_CONTEXT_MENU 管右键菜单权限,SORT_BY_CHART_CROSSHAIR_TOO 管中键十字光标,SORT_BY_CHART_MOUSE_SCROLL 管左键横向滚动。事件转发类如 SORT_BY_CHART_EVENT_MOUSE_WHEEL、SORT_BY_CHART_EVENT_OBJECT_DELETE,决定鼠标滚轮或图形对象销毁事件是否广播给图表上所有 MQL5 程序。 开 MT5 按 F4 进 MetaEditor,搜 ENUM_CHART_PROPERTY_INTEGER 就能看到完整清单;写多图表管理器时,挑 SORT_BY_CHART_MODE 和 SORT_BY_CHART_SCALE 做排序键,可能比按窗口序号更稳。外汇与贵金属图表多开时杠杆风险高,先用模拟盘验证枚举读取逻辑。

MQL5 / C++
  SORT_BY_CHART_SHOW,                                           class=class="str">"cmt">// Sort by the price chart drawing attribute
  SORT_BY_CHART_IS_OBJECT,                                        class=class="str">"cmt">// Sort by chart object(OBJ_CHART) identification attribute
  SORT_BY_CHART_BRING_TO_TOP,                                     class=class="str">"cmt">// Sort by the flag of displaying a chart above all others
  SORT_BY_CHART_CONTEXT_MENU,                                     class=class="str">"cmt">// Sort by the flag of enabling/disabling access to the context menu using the right click
  SORT_BY_CHART_CROSSHAIR_TOO,                                    class=class="str">"cmt">// Sort by the flag of enabling/disabling access to the Crosshair tool using the middle click
  SORT_BY_CHART_MOUSE_SCROLL,                                     class=class="str">"cmt">// Sort by the flag of scrolling the chart horizontally using the left mouse button
  SORT_BY_CHART_EVENT_MOUSE_WHEEL,                                class=class="str">"cmt">// Sort by the flag of sending messages about mouse wheel events to all MQL5 programs on a chart
  SORT_BY_CHART_EVENT_MOUSE_MOVE,                                 class=class="str">"cmt">// Sort by the flag of sending messages about mouse button click and movement events to all MQL5 programs on a chart
  SORT_BY_CHART_EVENT_OBJECT_CREATE,                              class=class="str">"cmt">// Sort by the flag of sending messages about the graphical object creation event to all MQL5 programs on a chart
  SORT_BY_CHART_EVENT_OBJECT_DELETE,                              class=class="str">"cmt">// Sort by the flag of sending messages about the graphical object destruction event to all MQL5 programs on a chart
  SORT_BY_CHART_MODE,                                             class=class="str">"cmt">// Sort by chart type
  SORT_BY_CHART_FOREGROUND,                                       class=class="str">"cmt">// Sort by the "Price chart in the foreground" flag
  SORT_BY_CHART_SHIFT,                                            class=class="str">"cmt">// Sort by the "Mode of shift of the price chart from the right border" flag
  SORT_BY_CHART_AUTOSCROLL,                                       class=class="str">"cmt">// Sort by the "The mode of automatic shift to the right border of the chart" flag
  SORT_BY_CHART_KEYBOARD_CONTROL,                                 class=class="str">"cmt">// Sort by the flag allowing the chart management using a keyboard
  SORT_BY_CHART_QUICK_NAVIGATION,                                 class=class="str">"cmt">// Sort by the flag allowing the chart to intercept Space and Enter key strokes to activate the quick navigation bar
  SORT_BY_CHART_SCALE,                                            class=class="str">"cmt">// Sort by scale
  SORT_BY_CHART_SCALEFIX,                                         class=class="str">"cmt">// Sort by the fixed scale flag
  SORT_BY_CHART_SCALEFIX_11,                                      class=class="str">"cmt">// Sort by the class="num">1:class="num">1 scale flag
  SORT_BY_CHART_SCALE_PT_PER_BAR,                                 class=class="str">"cmt">// Sort by the flag of specifying the scale in points per bar
  SORT_BY_CHART_SHOW_TICKER                                       class=class="str">"cmt">// Sort by the flag displaying a symbol ticker in the upper left corner

图表属性枚举的排序维度清单

在 MT5 的图表对象枚举体系里,有一组以 SORT_BY_CHART_ 开头的常量,专门用来按图表可视属性做排序或检索。它们覆盖了从 OHLC 文字显示、买卖价水平线,到周期分隔符、网格、成交量模式等界面元素。 下面这段枚举定义给出了可直接抄进 EA 或脚本的常量名与含义,注意每个都对应 ChartGetInteger/ChartSetInteger 的一类属性标识: SORT_BY_CHART_SHOW_OHLC 控制左上角 OHLC 数值的显示开关;SORT_BY_CHART_SHOW_BID_LINE 对应图表上 Bid 水平线;SORT_BY_CHART_SHOW_ASK_LINE 对应 Ask 水平线;SORT_BY_CHART_SHOW_LAST_LINE 则是 Last 成交价水平线。 继续往下看,SORT_BY_CHART_SHOW_PERIOD_SEP 管周期竖线分隔,SORT_BY_CHART_SHOW_GRID 管网格,SORT_BY_CHART_SHOW_VOLUMES 管成交量显示模式,SORT_BY_CHART_SHOW_OBJECT_DESCR 管对象文字描述是否显示。 窗口类属性也在这组里:SORT_BY_CHART_VISIBLE_BARS 是可显示 bar 数,SORT_BY_CHART_WINDOWS_TOTAL 含指标子窗口的总数,SORT_BY_CHART_WINDOW_HANDLE 是图表句柄,SORT_BY_CHART_WINDOW_YDISTANCE 是子窗口与上边框的 Y 像素距离。 还有第一可见 bar 序号、以 bar 或像素计的宽高:SORT_BY_CHART_FIRST_VISIBLE_BAR、SORT_BY_CHART_WIDTH_IN_BARS、SORT_BY_CHART_WIDTH_IN_PIXELS、SORT_BY_CHART_HEIGHT_IN_PIXELS。颜色类则包括背景、前景轴色、网格、成交量、阳线阴线实体与影线色,共 7 个 COLOR_ 后缀常量。 开 MT5 新建脚本,把这些常量打印出来对照 ChartGetInteger 返回值,就能确认当前图表状态。外汇与贵金属波动剧烈,用脚本批量读图表属性时务必先开模拟盘验证。

MQL5 / C++
  SORT_BY_CHART_SHOW_OHLC,                                                                     class=class="str">"cmt">// Sort by the flag displaying OHLC values in the upper left corner
  SORT_BY_CHART_SHOW_BID_LINE,                                                                   class=class="str">"cmt">// Sort by the flag displaying Bid value as a horizontal line on the chart
  SORT_BY_CHART_SHOW_ASK_LINE,                                                                   class=class="str">"cmt">// Sort by the flag displaying Ask value as a horizontal line on the chart
  SORT_BY_CHART_SHOW_LAST_LINE,                                                                  class=class="str">"cmt">// Sort by the flag displaying Last value as a horizontal line on the chart
  SORT_BY_CHART_SHOW_PERIOD_SEP,                                                                 class=class="str">"cmt">// Sort by the flag displaying vertical separators between adjacent periods
  SORT_BY_CHART_SHOW_GRID,                                                                       class=class="str">"cmt">// Sort by the flag of displaying a grid on the chart
  SORT_BY_CHART_SHOW_VOLUMES,                                                                    class=class="str">"cmt">// Sort by the mode of displaying volumes on a chart
  SORT_BY_CHART_SHOW_OBJECT_DESCR,                                                               class=class="str">"cmt">// Sort by the flag of displaying object text descriptions
  SORT_BY_CHART_VISIBLE_BARS,                                                                    class=class="str">"cmt">// Sort by the number of bars on a chart that are available for display
  SORT_BY_CHART_WINDOWS_TOTAL,                                                                   class=class="str">"cmt">// Sort by the total number of chart windows including indicator subwindows
  SORT_BY_CHART_WINDOW_HANDLE,                                                                   class=class="str">"cmt">// Sort by the chart handle
  SORT_BY_CHART_WINDOW_YDISTANCE,                                                                class=class="str">"cmt">// Sort by the distance in Y axis pixels between the upper frame of the indicator subwindow and the upper frame of the chart main window
  SORT_BY_CHART_FIRST_VISIBLE_BAR,                                                               class=class="str">"cmt">// Sort by the number of the first visible bar on the chart
  SORT_BY_CHART_WIDTH_IN_BARS,                                                                   class=class="str">"cmt">// Sort by the width of the chart in bars
  SORT_BY_CHART_WIDTH_IN_PIXELS,                                                                 class=class="str">"cmt">// Sort by the width of the chart in pixels
  SORT_BY_CHART_HEIGHT_IN_PIXELS,                                                                class=class="str">"cmt">// Sort by the height of the chart in pixels
  SORT_BY_CHART_COLOR_BACKGROUND,                                                                class=class="str">"cmt">// Sort by the class="type">class="kw">color of the chart background
  SORT_BY_CHART_COLOR_FOREGROUND,                                                                class=class="str">"cmt">// Sort by class="type">class="kw">color of axes, scale and OHLC line
  SORT_BY_CHART_COLOR_GRID,                                                                      class=class="str">"cmt">// Sort by grid class="type">class="kw">color
  SORT_BY_CHART_COLOR_VOLUME,                                                                    class=class="str">"cmt">// Sort by the class="type">class="kw">color of volumes and position opening levels
  SORT_BY_CHART_COLOR_CHART_UP,                                                                  class=class="str">"cmt">// Sort by the class="type">class="kw">color for the up bar, shadows and body borders of bull candlesticks
  SORT_BY_CHART_COLOR_CHART_DOWN                                                                 class=class="str">"cmt">// Sort by the class="type">class="kw">color of down bar, its shadow and border of body of the bullish candlestick

「图表对象枚举里的排序锚点」

在 MQL5 的图表批量管理逻辑里,SORT_BY_CHART_* 系列枚举决定了你用 ChartGetInteger/ChartSetInteger 遍历或排序图表时,到底按哪个属性做键。上面这段列出了从颜色类到窗口布局类的全部可用锚点,其中 SORT_BY_CHART_WINDOW_NUM 是定位子窗口指标最常用的索引依据。 颜色类里 SORT_BY_CHART_COLOR_CANDLE_BULL 与 SORT_BY_CHART_COLOR_CANDLE_BEAR 分别对应阳线实体与阴线实体的配色,做多周期视觉一致性脚本时可直接读这两个值;SORT_BY_CHART_COLOR_STOP_LEVEL 则锁定止损止盈线的颜色,方便在 EA 里统一风控线样式。 窗口状态类值得注意:SORT_BY_CHART_IS_DOCKED 配合 SORT_BY_CHART_FLOAT_LEFT / TOP / RIGHT / BOTTOM 四个浮窗坐标枚举,能在多屏交易环境下精确还原未停靠图表的位置。开 MT5 按 F4 把这些枚举粘进一段 ChartGetInteger 循环,就能列出当前终端所有图表的停靠与坐标状态。

MQL5 / C++
  SORT_BY_CHART_COLOR_CHART_LINE,                                                    class=class="str">"cmt">// Sort by the class="type">class="kw">color of the chart line and the Doji candlesticks
  SORT_BY_CHART_COLOR_CANDLE_BULL,                                                    class=class="str">"cmt">// Sort by the class="type">class="kw">color of a bullish candlestick body
  SORT_BY_CHART_COLOR_CANDLE_BEAR,                                                    class=class="str">"cmt">// Sort by the class="type">class="kw">color of a bearish candlestick body
  SORT_BY_CHART_COLOR_BID,                                                            class=class="str">"cmt">// Sort by the class="type">class="kw">color of the Bid price line
  SORT_BY_CHART_COLOR_ASK,                                                            class=class="str">"cmt">// Sort by the class="type">class="kw">color of the Ask price line
  SORT_BY_CHART_COLOR_LAST,                                                           class=class="str">"cmt">// Sort by the class="type">class="kw">color of the last performed deal&class="macro">#x27;s price line(Last)
  SORT_BY_CHART_COLOR_STOP_LEVEL,                                                     class=class="str">"cmt">// Sort by the class="type">class="kw">color of stop order levels(Stop Loss and Take Profit)
  SORT_BY_CHART_SHOW_TRADE_LEVELS,                                                    class=class="str">"cmt">// Sort by the flag of displaying trading levels on the chart
  SORT_BY_CHART_DRAG_TRADE_LEVELS,                                                    class=class="str">"cmt">// Sort by the flag enabling the ability to drag trading levels on a chart using mouse
  SORT_BY_CHART_SHOW_DATE_SCALE,                                                      class=class="str">"cmt">// Sort by the flag of displaying the time scale on the chart
  SORT_BY_CHART_SHOW_PRICE_SCALE,                                                     class=class="str">"cmt">// Sort by the flag of displaying the price scale on the chart
  SORT_BY_CHART_SHOW_ONE_CLICK,                                                       class=class="str">"cmt">// Sort by the flag of displaying the quick trading panel on the chart
  SORT_BY_CHART_IS_MAXIMIZED,                                                         class=class="str">"cmt">// Sort by the "Chart window maximized" flag
  SORT_BY_CHART_IS_MINIMIZED,                                                         class=class="str">"cmt">// Sort by the "Chart window minimized" flag
  SORT_BY_CHART_IS_DOCKED,                                                            class=class="str">"cmt">// Sort by the "Chart window docked" flag
  SORT_BY_CHART_FLOAT_LEFT,                                                           class=class="str">"cmt">// Sort by the left coordinate of the undocked chart window relative to the class="kw">virtual screen
  SORT_BY_CHART_FLOAT_TOP,                                                            class=class="str">"cmt">// Sort by the upper coordinate of the undocked chart window relative to the class="kw">virtual screen
  SORT_BY_CHART_FLOAT_RIGHT,                                                          class=class="str">"cmt">// Sort by the right coordinate of the undocked chart window relative to the class="kw">virtual screen
  SORT_BY_CHART_FLOAT_BOTTOM,                                                         class=class="str">"cmt">// Sort by the bottom coordinate of the undocked chart window relative to the class="kw">virtual screen
  SORT_BY_CHART_WINDOW_IND_HANDLE,                                                    class=class="str">"cmt">// Sort by the indicator handle in the chart window
  SORT_BY_CHART_WINDOW_IND_INDEX,                                                     class=class="str">"cmt">// Sort by the indicator index in the chart window
  SORT_BY_CHART_WINDOW_NUM,                                                           class=class="str">"cmt">// Sort by chart window index
class=class="str">"cmt">//--- Sort by real properties

◍ 枚举图表排序维度与指标窗口类骨架

在 MT5 的图表集合管理逻辑里,排序枚举把双精度属性和字符串属性分开锚定:双精度部分从 FIRST_CHART_DBL_PROP 起算,涵盖零柱右边界偏移百分比、左边界固定位置百分比、固定最大最小值、每柱点数比例以及图表实际价格上下沿;字符串部分从 FIRST_CHART_STR_PROP 起算,覆盖图表注释、EA 名、脚本名、主窗口指标名与品种名。 这些枚举值直接决定你用 ChartGetSortedBy() 一类接口批量巡检多图表时的比对键。比如按 SORT_BY_CHART_SYMBOL 排,能快速把同品种图表聚拢;按 SORT_BY_CHART_EXPERT_NAME 排,则便于定位挂了特定 EA 的图表。 紧随其后的 CWndInd 类只搭了最小骨架:私有成员存图表 ID、指标短名、列表序号、子窗口序号与指标句柄,公有方法先给了一个 GetObject() 返回自身指针。这个类后续若扩展,大概率要接 ChartIndicatorGet() 拿句柄、WindowIndicatorName() 验子窗口,外汇与贵金属图表多周期叠加时高风险,句柄失效要先判 ERR_INVALID_HANDLE。 开 MT5 新建 EA 把下面枚举和类头抄进项目,编译过一遍就能确认这些成员偏移量是否和你用的终端版本一致。

MQL5 / C++
  SORT_BY_CHART_SHIFT_SIZE = FIRST_CHART_DBL_PROP,   class=class="str">"cmt">// Sort by the shift size of the zero bar from the right border in %
  SORT_BY_CHART_FIXED_POSITION,                       class=class="str">"cmt">// Sort by the chart fixed position from the left border in %
  SORT_BY_CHART_FIXED_MAX,                            class=class="str">"cmt">// Sort by the fixed chart maximum
  SORT_BY_CHART_FIXED_MIN,                            class=class="str">"cmt">// Sort by the fixed chart minimum
  SORT_BY_CHART_POINTS_PER_BAR,                       class=class="str">"cmt">// Sort by the scale value in points per bar
  SORT_BY_CHART_PRICE_MIN,                            class=class="str">"cmt">// Sort by the chart minimum
  SORT_BY_CHART_PRICE_MAX,                            class=class="str">"cmt">// Sort by the chart maximum
class=class="str">"cmt">//--- Sort by class="type">class="kw">string properties
  SORT_BY_CHART_COMMENT = FIRST_CHART_STR_PROP,       class=class="str">"cmt">// Sort by a comment text on the chart
  SORT_BY_CHART_EXPERT_NAME,                          class=class="str">"cmt">// Sort by a name of an EA launched on the chart
  SORT_BY_CHART_SCRIPT_NAME,                          class=class="str">"cmt">// Sort by a name of a script launched on the chart
  SORT_BY_CHART_WINDOW_IND_NAME,                      class=class="str">"cmt">// Sort by a name of an indicator launched in the chart window
  SORT_BY_CHART_SYMBOL,                               class=class="str">"cmt">// Sort by chart symbol
  };
class CWndInd : class="kw">public CObject
  {
class="kw">private:
   class="type">long            m_chart_id;                        class=class="str">"cmt">// Chart ID
   class="type">class="kw">string          m_name;                            class=class="str">"cmt">// Indicator class="type">class="kw">short name
   class="type">int             m_index;                           class=class="str">"cmt">// indicator index in the list
   class="type">int             m_window_num;                      class=class="str">"cmt">// Indicator subwindow index
   class="type">int             m_handle;                          class=class="str">"cmt">// Indicator handle
class="kw">public:
class=class="str">"cmt">//--- Return itself
   CWndInd        *GetObject(class="type">void)                    { class="kw">return &this;    }
交给小布盯盘看盘口
这些图表对象事件的监听逻辑,小布盯盘的 AIGC 已内置,打开对应品种页即可看到对象变动的实时标注,你只需判断要不要跟。

常见问题

程序化一次性改多个对象可能在单次计时器里触发竞态,库里只记录最后一个事件,前面变动的对象索引可能被错认,本篇用特殊列表存已删对象副本来规避。
库给指标对象加了所在窗口索引属性,删除的对象会进特殊列表,随时能从副本里取原窗口索引,不必实时遍历活对象。
可以,小布盯盘对应品种页已内置对象变动的 AIGC 标注,不用自己写监听代码就能看到增删轨迹。
发送含事件类型的自定义事件,类型对应枚举常量,控制程序图表收到后按代码分支处理,不混淆手动与程序改动。