how to draw an arrow on multiple timeframes

 

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

double time = iTime(Symbol(),PERIOD_H1,10);
double price = iLow(Symbol(),PERIOD_H1,10);
ObjectCreate(0, "name", OBJ_ARROW_DOWN, 0, time, price);
ObjectSetInteger(0, "name", OBJPROP_COLOR, clrWhite);


 

Documentation on MQL5: Chart Operations / ChartNext
Documentation on MQL5: Chart Operations / ChartNext
  • www.mql5.com
ChartNext - Chart Operations - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
ansar9h:

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);
Documentation on MQL5: Chart Operations / ChartNext
Documentation on MQL5: Chart Operations / ChartNext
  • www.mql5.com
ChartNext - Chart Operations - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 

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

 
ansar9h #:

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
     }
 
is there  something else i should do before i could run on multiple timeframe charts?
 
ansar9h #:
is there  something else i should do before i could run on multiple timeframe charts?

If this is not working, can't you run the code separately on two different charts?

 
the idea is i want to backtest on multiple timeframes at the same time. thx for help
 
ansar9h #:
the idea is i want to backtest on multiple timeframes at the same time. thx for help

ok good luck

Reason: