DoEasy 库中的其他类(第七十二部分):跟踪并记录集合中的图表对象参数·进阶篇
(2/3)· 当图表窗口属性被改,怎样不靠手写轮询就让集合里的对象自己上报变更信号
◍ 图表属性枚举里的显示与配色开关
在 MT5 的图表属性体系里,有一批枚举常量专门控制「画面上到底显示什么、用什么颜色画」。上面这段列出了从缩放模式到阳线配色的一串 CHART_PROP_* 常量,每个都对应 ChartGetInteger / ChartSetInteger 的一个可读写字段。 比如 CHART_PROP_SCALEFIX_11 是 1:1 比例模式,CHART_PROP_SHOW_BID_LINE 与 CHART_PROP_SHOW_ASK_LINE 分别决定买价、卖价水平线是否画出,CHART_PROP_VISIBLE_BARS 则返回当前图表能显示的 K 线数量。做价格行为分析时,关掉网格(CHART_PROP_SHOW_GRID=false)和成交量(CHART_PROP_SHOW_VOLUMES=false)往往能让裸 K 更干净。 配色类常量也别忽略:CHART_PROP_COLOR_BACKGROUND 是背景色,CHART_PROP_COLOR_CHART_UP 控制阳线的影线和实体边框色。外汇与贵金属波动剧烈、杠杆风险高,改这些属性只是视觉辅助,不改变行情本身的概率结构,实盘前请在策略测试器里先验证显示逻辑。
CHART_PROP_SCALEFIX_11, class=class="str">"cmt">// class="num">1:class="num">1 scale mode CHART_PROP_SCALE_PT_PER_BAR, class=class="str">"cmt">// The mode of specifying the scale in points per bar CHART_PROP_SHOW_TICKER, class=class="str">"cmt">// Display a symbol ticker in the upper left corner CHART_PROP_SHOW_OHLC, class=class="str">"cmt">// Display OHLC values in the upper left corner CHART_PROP_SHOW_BID_LINE, class=class="str">"cmt">// Display Bid value as a horizontal line on the chart CHART_PROP_SHOW_ASK_LINE, class=class="str">"cmt">// Display Ask value as a horizontal line on a chart CHART_PROP_SHOW_LAST_LINE, class=class="str">"cmt">// Display Last value as a horizontal line on a chart CHART_PROP_SHOW_PERIOD_SEP, class=class="str">"cmt">// Display vertical separators between adjacent periods CHART_PROP_SHOW_GRID, class=class="str">"cmt">// Display a grid on the chart CHART_PROP_SHOW_VOLUMES, class=class="str">"cmt">// Display volumes on a chart CHART_PROP_SHOW_OBJECT_DESCR, class=class="str">"cmt">// Display text descriptions of objects 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_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_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
图表属性枚举里的颜色与窗口定位项
在 MT5 的图表属性枚举中,有一组常量专门控制 K 线配色与交易相关的视觉元素。例如 CHART_PROP_COLOR_CHART_DOWN 决定阴线实体边框与影线颜色,CHART_PROP_COLOR_CANDLE_BULL 和 CHART_PROP_COLOR_CANDLE_BEAR 则分别管看涨、看跌 K 线的实体填充色,改这几个值就能让盯盘配色脱离默认绿红。 CHART_PROP_COLOR_BID、CHART_PROP_COLOR_ASK、CHART_PROP_COLOR_LAST 对应买卖价与最后一笔成交价的线色,CHART_PROP_COLOR_STOP_LEVEL 控制止损止盈水平线颜色。若你用「小布盯盘」做多品种监控,统一这几项配色能降低视觉误读概率。 窗口状态类枚举也值得注意:CHART_PROP_IS_MAXIMIZED / IS_MINIMIZED / IS_DOCKED 反映图表窗体状态,而未停靠时用 CHART_PROP_FLOAT_LEFT、FLOAT_TOP、FLOAT_RIGHT、FLOAT_BOTTOM 描述相对虚拟屏幕的四至坐标。CHART_PROP_YDISTANCE 则是指标子窗口上边框到主图表窗口上边框的 Y 轴像素距离,默认布局下常见为 0 或副图高度值,可用于校验指标窗口位置。 外汇与贵金属杠杆高、滑点跳空频繁,改图表属性只是视觉辅助,不构成任何方向判断。
CHART_PROP_COLOR_CHART_DOWN, class=class="str">"cmt">// 阴线实体边框、影线颜色 CHART_PROP_COLOR_CHART_LINE, class=class="str">"cmt">// 折线图与十字星K线颜色 CHART_PROP_COLOR_CANDLE_BULL, class=class="str">"cmt">// 看涨K线实体颜色 CHART_PROP_COLOR_CANDLE_BEAR, class=class="str">"cmt">// 看跌K线实体颜色 CHART_PROP_COLOR_BID, class=class="str">"cmt">// 买价线颜色 CHART_PROP_COLOR_ASK, class=class="str">"cmt">// 卖价线颜色 CHART_PROP_COLOR_LAST, class=class="str">"cmt">// 最后一笔成交价线颜色 CHART_PROP_COLOR_STOP_LEVEL, class=class="str">"cmt">// 止损止盈水平线颜色 CHART_PROP_SHOW_TRADE_LEVELS, class=class="str">"cmt">// 图表显示交易水平(持仓/SL/TP/挂单) CHART_PROP_DRAG_TRADE_LEVELS, class=class="str">"cmt">// 允许鼠标拖拽交易水平 CHART_PROP_SHOW_DATE_SCALE, class=class="str">"cmt">// 显示时间轴 CHART_PROP_SHOW_PRICE_SCALE, class=class="str">"cmt">// 显示价格轴 CHART_PROP_SHOW_ONE_CLICK, class=class="str">"cmt">// 显示一键交易面板 CHART_PROP_IS_MAXIMIZED, class=class="str">"cmt">// 图表窗口最大化 CHART_PROP_IS_MINIMIZED, class=class="str">"cmt">// 图表窗口最小化 CHART_PROP_IS_DOCKED, class=class="str">"cmt">// 图表窗口已停靠 CHART_PROP_FLOAT_LEFT, class=class="str">"cmt">// 未停靠窗口左坐标(虚拟屏幕) CHART_PROP_FLOAT_TOP, class=class="str">"cmt">// 未停靠窗口上坐标(虚拟屏幕) CHART_PROP_FLOAT_RIGHT, class=class="str">"cmt">// 未停靠窗口右坐标(虚拟屏幕) CHART_PROP_FLOAT_BOTTOM, class=class="str">"cmt">// 未停靠窗口下坐标(虚拟屏幕) CHART_PROP_YDISTANCE class=class="str">"cmt">// 指标子窗上边框到主图窗上边框Y像素距
「图表整数属性的枚举尾巴与排序偏移」
在 MT5 的图表属性枚举里,整数类属性收尾于像素高度、附图指标句柄与附图指标序号三项,它们紧接在前 63 个可用整数属性之后。 宏 CHART_PROP_INTEGER_TOTAL 写死为 66,代表整数属性总量;CHART_PROP_INTEGER_SKIP 为 2,表示有 2 个整数属性不参与排序索引。 排序偏移靠两个宏算出:FIRST_CHART_DBL_PROP 等于 66 减 2 得 64,即双精度属性起始位;FIRST_CHART_STR_PROP 再叠加重数属性总量与跳过数,指向字符串属性区。 ENUM_SORT_CHART_MODE 从 SORT_BY_CHART_ID = 0 起,按整数属性顺序暴露了图表 ID、周期、显隐、是否为 OBJ_CHART 对象等十余种排序键,写多图表批处理脚本时直接套这些枚举值即可。
class="macro">#define CHART_PROP_INTEGER_TOTAL(class="num">66) class=class="str">"cmt">// Total number of integer properties class="macro">#define CHART_PROP_INTEGER_SKIP(class="num">2) class=class="str">"cmt">// Number of integer properties not used in sorting 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 { 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 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 class="kw">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 class="kw">using the middle click SORT_BY_CHART_MOUSE_SCROLL, class=class="str">"cmt">// Sort by the flag of scrolling the chart horizontally class="kw">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 };
◍ 图表属性枚举的排序锚点
在 MT5 的图表对象枚举体系里,有一组以 SORT_BY_CHART_ 开头的常量,专门用来按图表状态与显示属性做排序或筛选。它们不是指标计算量,而是图表自身的可视化与控制标志。 比如 SORT_BY_CHART_MODE 对应图表类型(蜡烛/折线等),SORT_BY_CHART_SCALE 抓的是缩放级别,SORT_BY_CHART_SHOW_BID_LINE 和 SORT_BY_CHART_SHOW_ASK_LINE 则分别绑定买价、卖价水平线的显隐状态。做多图表批量扫描时,靠这些锚点能直接挑出「显示 Ask 线且未锁定比例」的图。 下面这段枚举摘出来,开 MT5 在 MetaEditor 搜 SORT_BY_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 class="kw">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 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
图表对象排序枚举的视觉与交互字段
在 MT5 的图表对象枚举体系里,SORT_BY_CHART_* 系列除了定位句柄与可见 K 线数,还覆盖了大量视觉与交互属性。上面这段枚举清单列出了从背景色、坐标轴色到买卖价线颜色的 28 个排序维度,说明图表管理器能把任意视觉特征当作索引键。 比如 SORT_BY_CHART_COLOR_BID 与 SORT_BY_CHART_COLOR_ASK 分别指向买卖价线的颜色,SORT_BY_CHART_SHOW_ONE_CLICK 对应图表上快捷交易面板的显示开关。若你写 EA 时需要批量识别开启了「一键交易」的图表,直接按这个枚举做 ChartGetInteger 过滤即可。 外汇与贵金属市场杠杆高、滑点大,用这类接口做多图监控时,任何颜色或开关的状态误读都可能让你下错单。建议先在模拟账户挂一段扫描代码跑通逻辑,再接真实品种。
SORT_BY_CHART_WINDOW_HANDLE, class=class="str">"cmt">// Sort by the chart handle 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_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 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 class="kw">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
「图表窗口排序枚举的收尾字段」
上面这组枚举把 ChartGetInteger 类排序常量收了尾,从窗口最小化、停靠状态一路列到虚拟屏幕坐标(左、上、右、下),以及子窗口与主图在 Y 轴像素间距、图表像素高度等布局属性。 紧接着以 FIRST_CHART_DBL_PROP 为界切到实数属性段:零柱相对右边界偏移百分比、左边界固定位百分比、固定最大最小值、每柱点数比例、图表实际价格上下限,共 9 个双精度排序键。 字符串段从 FIRST_CHART_STR_PROP 起头,覆盖图表注释、EA 名、脚本名、主图指标名与品种名,合计 5 个文本类排序维度。开 MT5 在 MetaEditor 搜 ENUM_CHART_SORT 可直接核对这套常量定义,写多图批量管理脚本时按这些键排序能少绕弯路。
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_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_HEIGHT_IN_PIXELS, class=class="str">"cmt">// Sort by the height of the chart in pixels class=class="str">"cmt">//--- Sort by real properties 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_INDICATOR_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 };