#property copyright "Copyright 2025, MetaQuotes Ltd."
#property link "https://www.mql5.com"
#property version "1.00"
//+------------------------------------------------------------------+
//| 脚本程序起始函数 |
//+------------------------------------------------------------------+
void OnStart()
{
//--- 图表 ID
long chart_id=ChartID();
//--- 循环遍历所有图表图形对象
int obj_total=ObjectsTotal(chart_id);
for(int i=obj_total-1; i>=0; i--)
{
//--- 每隔一个跳过对象
if(i%2==0)
continue;
//--- 取得图形对象的名称
//--- 如果是自动交易标签, 跳过该对象
string obj_name=ObjectName(chart_id, i);
if(StringFind(obj_name, "autotrade")==0)
continue;
//--- 使用 chart_id 从图表上删除图形对象
ResetLastError();
if(ObjectDelete(chart_id, obj_name))
{
PrintFormat("[%d] Graphic object named \"%s\" removed from the chart with ID #%I64d", i, obj_name, chart_id);
}
else
{
Print("ObjectDelete() failed. Error ", GetLastError());
}
}
/*
放置了图形对象和自动交易标签(已跳过)的 6图表的结果:
[659] Graphic object named "M30 Rectangle 5636" removed from the chart with ID #128968168951083984
[657] Graphic object named "M30 Trendline 40731" removed from the chart with ID #128968168951083984
[1] Graphic object named "M30 Vertical Line 13600" removed from the chart with ID #128968168951083984
*/
}
|