ChartClose
ChartClose
关闭指定图表。
bool ChartClose(
long chart_id=0 // 图表 ID
);参量
- chart_id=0
[in] 图表 ID. 0 意味着当前图表。
返回值
若成功,返回true,否则false。
示例:
//+------------------------------------------------------------------+
//| 脚本程序起始函数 |
//+------------------------------------------------------------------+
void OnStart()
{
//--- 打开一个与当前图表具有相同交易品种和周期的新图表
long chart_id=ChartOpen(_Symbol, _Period);
if(chart_id==0)
{
Print("ChartOpen() failed. Error ", GetLastError());
return;
}
//--- 在日志中打印打开图表的参数
PrintFormat("A new chart of the %s symbol has been opened with a period of %s and ChartID %I64u",
_Symbol, StringSubstr(EnumToString(_Period), 7), chart_id);
//--- 等待三秒再关闭新打开的图表
PrintFormat("Waiting 3 seconds before closing a newly opened chart with ID %I64d ...", chart_id);
Sleep(3000);
ResetLastError();
if(!ChartClose(chart_id))
{
Print("ChartClose() failed. Error ", GetLastError());
return;
}
//--- 在日志中打印成功关闭图表的消息
PrintFormat("The chart with ID %I64d was successfully closed", chart_id);
/*
结果:
A new chart of the GBPUSD symbol has been opened with a period of M1 and ChartID 133346697706632016
Waiting 3 seconds before closing a newly opened chart with ID 133346697706632016 ...
The chart with ID 133346697706632016 was successfully closed
*/
}