i have two charts on the screen. both representing the same currency but different timeframes 15M and H1.
below code i use to draw an arrow. works fine but problem it is getting drawn on M15 timeframe. i want to draw it on H1 timeframe. I believe the issue something to do with the chartId but whenever i try to get the ChartNext it is always returning -1
Some things spring to mind:
1) Are you using ChartNext() as per the documentation? (see the example code)
https://www.mql5.com/en/docs/chart_operations/chartnext
2) Are you changing the period to PERIOD_M15 in these calls for the next chart?
double time = iTime(Symbol(),PERIOD_H1,10); double price = iLow(Symbol(),PERIOD_H1,10);
- www.mql5.com
1)I tried it also did not work, this is my full code, whenever i call ChartNext(chartID) it returns -1 although there are two charts on the screen.
long chartID=ChartFirst(); long currChart=ChartNext(chartID); double time = iTime(Symbol(),PERIOD_H1,10); double price = iLow(Symbol(),PERIOD_H1,10); ObjectCreate(currChart, "name", OBJ_ARROW_DOWN, 0, time, price); ObjectSetInteger(currChart, "name", OBJPROP_COLOR, clrWhite);
2) no not changing anything
1)I tried it also did not work, this is my full code, whenever i call ChartNext(chartID) it returns -1 although there are two charts on the screen.
2) no not changing anything
Not sure - I tried the first 2 statements in your code, they work for me.
I also tried the code in the documentation - worked fine too...
Here is the code
long chartID=ChartFirst(); long currChart=ChartNext(chartID); //https://www.mql5.com/en/docs/chart_operations/chartnext //--- variables for chart ID long thisChart, prevChart = ChartFirst(); int i = 0, limit = 100; Print("ChartFirst =", ChartSymbol(prevChart), " ID =", prevChart); while(i < limit) // We have certainly not more than 100 open charts { thisChart = ChartNext(prevChart); // Get the new chart ID by using the previous chart ID if(thisChart < 0) break; // Have reached the end of the chart list Print(i, ChartSymbol(thisChart), " ID =", thisChart); prevChart = thisChart; // let's save the current chart ID for the ChartNext() i++;// Do not forget to increase the counter }
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
i have two charts on the screen. both representing the same currency but different timeframes 15M and H1.
below code i use to draw an arrow. works fine but problem it is getting drawn on M15 timeframe. i want to draw it on H1 timeframe. I believe the issue something to do with the chartId but whenever i try to get the ChartNext it is always returning -1