Is there any way to load programmatically entire history (of a Symbol and a Period) from server?

Petr Nosek
4889

I'm looking for programmatically solution of loading entire history for a symbol and a timeframe from server. I can do it manually by opening a chart with the required symbol and the required timeframe and then (unlock Scroll the chart button) by pressing Home and multiple pressing PgUp until I get to the oldest bar in the server history. But I need doing this by code (in the best way without opening the chart). Of course I can do it by programmatically opening the chart and simulating the keystrokes by API and then close the chart in the end. I was wondering if there is any easier solution? It may not be easier, but without opening and closing the chart and without API. Any Idea?

William Roeder
25836
William Roeder  
  1. If you don't have any history, here's how you can get all available from your broker.
  2. Programmaticly, you can get the last 2K bars via by handling 4066/4073 errors.
              Download history in MQL4 EA - MQL4 and MetaTrader 4 - MQL4 programming forum
Petr Nosek
4889
Petr Nosek  

whroeder1:

Programmaticly, you can get the last 2K bars.

The last 2K bars aren't my problem. I can get that very simple.

I need to get 32K (12K or 65K, entire broker's server history ) bars of history per timeframe. I can get that manually (or programmatically by simulating keystrokes) but I'm looking for another programmatically solution.

Ashish Kulkarni
1029
Ashish Kulkarni  
Petr Nosek:

The last 2K bars aren't my problem. I can get that very simple.

I need to get 32K (12K or 65K, entire broker's server history ) bars of history per timeframe. I can get that manually (or programmatically by simulating keystrokes) but I'm looking for another programmatically solution.

Tickstory from www.tickstory.com already does that

Petr Nosek
4889
Petr Nosek  
Ashish Kulkarni:

Tickstory from www.tickstory.com already does that

Thank you for your effort but I don't need data from another broker (in this case from Dukascopy) for back testing but I need to load all available data from "my" broker's server into my terminal by MQL4 code.
Alain Verleyen
42596
Petr Nosek:

I'm looking for programmatically solution of loading entire history for a symbol and a timeframe from server. I can do it manually by opening a chart with the required symbol and the required timeframe and then (unlock Scroll the chart button) by pressing Home and multiple pressing PgUp until I get to the oldest bar in the server history. But I need doing this by code (in the best way without opening the chart). Of course I can do it by programmatically opening the chart and simulating the keystrokes by API and then close the chart in the end. I was wondering if there is any easier solution? It may not be easier, but without opening and closing the chart and without API. Any Idea?

You need to open the chart in all cases. If by API you mean WinAPI you don't need that, it can be done without it, using ChartNavigate().

Petr Nosek
4889
Petr Nosek  
Alain Verleyen:

You need to open the chart in all cases. If by API you mean WinAPI you don't need that, it can be done without it, using ChartNavigate().

Thank you Alain,

as usual, is your contribution to the matter. I'll try that and write the result here.

Petr Nosek
4889
Petr Nosek  
I can confirm that using ChartNavigate() works like a charm. I can get all availaible history from server within 2s. Pity that there is no solution without opening and closing the chart. At least I don't have to use the WinAPI because some VPS don't allow using DLLs.
ROMAN KOTOV
155
ROMAN KOTOV  
void updatehist(string sym, ENUM_TIMEFRAMES tf)
  {
   long id = ChartOpen(sym, tf);
   Sleep(1000);
   ChartRedraw(id);
   Sleep(200);
   ChartSetInteger(id, CHART_AUTOSCROLL, false);
   datetime oldest_serv = (datetime)SeriesInfoInteger(sym, tf, SERIES_SERVER_FIRSTDATE);
   while(ChartGetInteger(id, CHART_AUTOSCROLL) == true)
      Sleep(100);
   datetime current = iTime(sym, tf, iBars(sym, tf) - 1);
   LabelCreate(id, "txt1", 0, 10, 40, CORNER_LEFT_UPPER, "Loading history.. Please wait..", "Consolas", 28, clrTurquoise);
   LabelCreate(id, "txt2", 0, 10, 80, CORNER_LEFT_UPPER, "Current " + (string) current + " of " + (string)oldest_serv, "Consolas", 28, clrTurquoise);
   while((int)oldest_serv < (int)current && !IsStopped())
     {
      ChartRedraw(id);
      RefreshRates();
      ObjectSetString(id, "txt2", OBJPROP_TEXT, "Current " + (string) current + " of " + (string)oldest_serv);
      ChartNavigate(id, CHART_CURRENT_POS, -1000);
      Sleep(100);
      current = iTime(sym, tf, iBars(sym, tf) - 1);
     }
   ChartClose(id);
  }

This should work well.. LabelCreate() functions from MQL4 help