Works fine for me. Which build are you using?
2017.03.19 09:52:17.856 Test USDCHF,M1: initialized
2017.03.19 09:52:17.856 Test USDCHF,M1: New chart id: 131218835664533484, New chart symbol: EURUSD, New chart timeframe: 1440
2017.03.19 09:52:17.825 Test USDCHF,M1: Current chart id: 131218835664533483, Current chart symbol: USDCHF, Current chart timeframe: 1
2017.03.19 09:52:16.747 Custom indicator Test USDCHF,M1: loaded successfully
#property strict #property indicator_chart_window //+------------------------------------------------------------------+ //| OnInit() | //+------------------------------------------------------------------+ int OnInit() { long newChartID; long curChartID; curChartID = ChartID(); Print("Current chart id: ", curChartID, ", Current chart symbol: ", ChartSymbol(curChartID),", Current chart timeframe: ",ChartPeriod(curChartID)); newChartID = ChartOpen("EURUSD", PERIOD_D1); Print("New chart id: ", newChartID, ", New chart symbol: ", ChartSymbol(newChartID),", New chart timeframe: ",ChartPeriod(newChartID)); return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| OnCalculate() | //+------------------------------------------------------------------+ int OnCalculate(const int rates_total, const int prev_calculated, const datetime &time[], const double &open[], const double &high[], const double &low[], const double &close[], const long &tick_volume[], const long &volume[], const int &spread[]) { return(rates_total); }
Works fine for me. Which build are you using?
Build 1045. And Im using in an EA, not an indicator.
2017.03.19 23:44:22.188 GBPUSD,M15: 638846 tick events (25049 bars, 37446670 bar states) processed in 0:00:09.047 (total time 0:00:09.750)
2017.03.19 23:44:22.187 2016.03.21 00:39:03 Tester: stop button pressed
2017.03.19 23:44:13.161 2016.03.11 00:00:00 TestChartOpen GBPUSD,M15: New chart id: 0, New chart symbol: GBPUSD, New chart timeframe: 15
2017.03.19 23:44:13.161 2016.03.11 00:00:00 TestChartOpen GBPUSD,M15: Current chart id: 131344510805885545, Current chart symbol: GBPUSD, Current chart timeframe: 15
2017.03.19 23:44:13.140 2016.03.11 00:00:00 TestChartOpen test started
2017.03.19 23:44:12.524 TestGenerator: server "GKFX-Demo-1" differs from "OANDA-GMT-5 Practice" terminal connected to
2017.03.19 23:44:12.524 TestGenerator: symbol GBPUSD period 15 model 0 from 2016.03.10 to 2017.03.09
2017.03.19 23:44:12.440 TestGenerator: file "J:\OANDA-MT4\tester\history\GBPUSD15_0.fxt" is read-only
It opens the chart, BUT, does not return the chart id.
Update: I tested it on a live chart, and it returns the new chart id. In other words. ChartOpen does NOT return the new chart id in Strategy Tester.
Build 1045. And Im using in an EA, not an indicator.
2017.03.19 23:44:22.188 GBPUSD,M15: 638846 tick events (25049 bars, 37446670 bar states) processed in 0:00:09.047 (total time 0:00:09.750)
2017.03.19 23:44:22.187 2016.03.21 00:39:03 Tester: stop button pressed
2017.03.19 23:44:13.161 2016.03.11 00:00:00 TestChartOpen GBPUSD,M15: New chart id: 0, New chart symbol: GBPUSD, New chart timeframe: 15
2017.03.19 23:44:13.161 2016.03.11 00:00:00 TestChartOpen GBPUSD,M15: Current chart id: 131344510805885545, Current chart symbol: GBPUSD, Current chart timeframe: 15
2017.03.19 23:44:13.140 2016.03.11 00:00:00 TestChartOpen test started
2017.03.19 23:44:12.524 TestGenerator: server "GKFX-Demo-1" differs from "OANDA-GMT-5 Practice" terminal connected to
2017.03.19 23:44:12.524 TestGenerator: symbol GBPUSD period 15 model 0 from 2016.03.10 to 2017.03.09
2017.03.19 23:44:12.440 TestGenerator: file "J:\OANDA-MT4\tester\history\GBPUSD15_0.fxt" is read-only
It opens the chart, BUT, does not return the chart id.
Update: I tested it on a live chart, and it returns the new chart id. In other words. ChartOpen does NOT return the new chart id in Strategy Tester.
You have specified in the first post, that you ran it on the terminal rather than the tester.
I believe you may obtain reference only to the testing chart itself in the tester, to isolate the tester data from the future. Neither ChartNext() returns ID. (In fact neither the ChartFirst, which works in MT5).

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
This is on MQL4. According to documentation, ChartOpen should return the new chart id. It doesnt. Therefore its a bug. Try this code in OnInit():
Run on a demo terminal.