#define SYMBOL "GBPUSD"
#define PERIOD PERIOD_H1
//+------------------------------------------------------------------+
//| 脚本程序起始函数 |
//+------------------------------------------------------------------+
void OnStart()
{
//--- 取得当前图表ID,交易品种和周期
long chart_id= ChartID();
string symbol = Symbol();
ENUM_TIMEFRAMES period = Period();
//--- 在日志中报告使用设置在SYMBOL和PERIOD中的值替换当前图表的交易品种和周期
PrintFormat("Change the %s symbol and the %s period of the chart %I64u to %s %s",
symbol, TimeframeDescrioption(period), chart_id, SYMBOL, TimeframeDescrioption(PERIOD));
//--- 改变图表交易品种和周期
ChartSetSymbolPeriod(chart_id, SYMBOL, PERIOD);
/*
结果:
Change the EURUSD symbol and the M1 period of the chart 133246248352168440 to GBPUSD H1
*/
}
//+------------------------------------------------------------------+
//| 返回图表周期的描述 |
//+------------------------------------------------------------------+
string TimeframeDescrioption(const ENUM_TIMEFRAMES timeframe)
{
return(StringSubstr(EnumToString(timeframe), 7));
}
|