Modify historical data using historical files

 

Hello

I want to update the last bars (e.g. last 200) bars on my chart of a symbol.
To do that I am trying to do updates on historical data files of the appropriate symbol.
I found a script here and adjusted it which now looks like this:

#include <WinUser32.mqh>

#define OFFLINE_HEADER_SIZE 148 // LONG_VALUE + 64 + 12 + 4 * LONG_VALUE + 13 * LONG_VALUE
#define OFFLINE_RECORD_SIZE 44  // 5 * DOUBLE_VALUE + LONG_VALUE
int __chart_file = 0; // the cache for the file handle (only used in backtesting mode)

int OnInit()
{
   writeOfflineBar("USDMXN", PERIOD_D1, 1, "00:00", 1.37356, 1.37385, 1.37335, 1.37379, 1000);
   WindowRedraw();
   ChartRedraw();
   return(INIT_SUCCEEDED);
}


void writeOfflineBar(string   symbol, 
                                              int          period, 
                                              int          bars_back, 
                                              int          time, 
                                              double    open, 
                                              double    high, 
                                              double    low, 
                                              double    close, 
                                              double    volume){

   int F = fileOpenEx(StringSubstr(symbol, 0, 12) + period + ".hst", FILE_BIN | FILE_READ | FILE_WRITE);

   int position = bars_back * OFFLINE_RECORD_SIZE;   
   FileSeek(F, -position, SEEK_END);

   if (FileTell(F) >= OFFLINE_HEADER_SIZE){
      FileWriteInteger(F, time, LONG_VALUE); 
      FileWriteDouble(F, open, DOUBLE_VALUE);
      FileWriteDouble(F, low, DOUBLE_VALUE);
      FileWriteDouble(F, high, DOUBLE_VALUE);
      FileWriteDouble(F, close, DOUBLE_VALUE);
      FileWriteDouble(F, volume, DOUBLE_VALUE);

      // refresh the chart window
      if (!IsTesting()){
         int hwnd=WindowHandle(symbol, period);
         if (hwnd != 0){
            PostMessageW(hwnd, WM_COMMAND, 33324, 0);
         }
      }
   }
   FileClose(F);
}

int fileOpenEx(string name, int mode){
   if (IsTesting()){
      if (__chart_file == 0){
         __chart_file = FileOpenHistory(name, mode);
      }
      return(__chart_file);
   }else{
      return(FileOpenHistory(name, mode));
   }
}

If calling this method I see that the appropriate history file has been changed (current "Date modified") but I don't see any changes on the chart :-(.
I also tried ChartRedraw() and WindowRedraw() but nothing happens.

What else is missing to be able to change the last historical bars (e.g. 200 bars)?

Thanks for helping.

 
int F = fileOpenEx(StringSubstr(symbol, 0, 12) + period + ".hst", FILE_BIN | FILE_READ | FILE_WRITE | 128 | 256);

why 12 ?

read more about the structure of the history files

 

Ok, I changed it to:

int F = fileOpenEx("EURUSD1440.hst", FILE_BIN | FILE_READ | FILE_WRITE);

But I still have exact the same problems as described above!

 

have you read how the new structure of the history files is and what changes has been made ?

https://www.mql5.com/en/articles/1387

and what abuot 128 | 256 ?

 

Thanks for helping.

I know that article and I also tried it with 128 | 256 but nothing changes.

After reading the article again (and the PeriodConverter scripts) I found a little script that should only change a single bar in the history:

MqlRates rate;
int       ExtHandle=-1;
rate.time = "2013.12.26 00:00";
rate.open = 1.34348;
rate.high = 1.34353;
rate.low = 1.34123;
rate.close = 1.34137;
rate.tick_volume = 1000;
rate.spread = 0;
rate.real_volume = 0;

ExtHandle=FileOpenHistory("EURUSD1440.hst",FILE_BIN|FILE_WRITE|FILE_SHARE_WRITE|FILE_SHARE_READ|FILE_ANSI);
FileWriteStruct(ExtHandle,rate);
FileFlush(ExtHandle);
FileClose(ExtHandle);

Obviously there is something missing/wrong in that script since the bar doesn't change.

 
Isn't there any chance to modify a single bar in the history programatically with immediate update on the chart (MT4 Build 610)? Unfortunatelly I could not find help anywhere.
 

this link provides you everything you need to know about the chart and how to update the chart

the onky question is if you want to spend your time to read it and understand it

 

I've read the article, tried out to produce a script which does the task. Unfortunately I still was not successful and that's why I'm asking for help in this forum.

BTW: The articles says that older scripts should still work with the new build but my script I posted first doesn't.

 
by saying the older scripts should still work Metaquotes mean this one or this one

they don't know nothing about your script

(It really works you can check for yourself)

 

You are right, the article doesn't know anything about my script which is based on their period_converter scripts which supposed to run so should by script (but it doesn't). The article you posted is talking about the period converter, offline charts and mentions the history file. Of course there is no explicit hint how to modify a single bar in the history on a live/online chart programmatically (I didn't expected it). Anyway, I've read the article (I mentioned this already before) and tried to implement some code (see my previous posts) which unfortunately does not solve the problem. I'm aware that I'm not a high-level professional programmer. For that reason I am asking this forum for help (again).

I appreciate sending the link (even three times) to that one single article (period_converter, offline charts) and opening this thread but that was not helpful so far.

It would be an additional value to this forum if we could have a look at the scripts, have some constructive discussions and try to find a good solution from which others can benefit as well.

Thank you.

 
coolex:

Of course there is no explicit hint how to modify a single bar in the history on a live/online chart programmatically (I didn't expected it).

if you would read the code, you'll understand exactly how to do it

I appreciate sending the link (even three times) to that one single article (period_converter, offline charts)

you are wrong, there is a difference between the two indicators of the links attached they are not the same


Reason: