Modify historical data using historical files - page 2

 
writeOfflineBar("USDMXN", PERIOD_D1, 1, "00:00", 1.37356, 1.37385, 1.37335, 1.37379, 1000);

its declared as an int not a string (but actually its supposed to be a datetime)

int position = bars_back * OFFLINE_RECORD_SIZE;   

change to

int position = (bars_back * OFFLINE_RECORD_SIZE) + OFFLINE_RECORD_SIZE;   

what exactly is it ? a indicator script or EA ?

 

I updated my code but the appropriate historical file becomes empty.

This should be an EA.

This is the current code based on your input above:

#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()
{
   datetime dt = "2013.12.26 00:00";
   writeOfflineBar("USDMXN", PERIOD_D1, 1, dt, 86.72, 87.78, 86.7, 87.78, 1000);
   WindowRedraw();
   ChartRedraw();
   return(INIT_SUCCEEDED);
}

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


   int F = fileOpenEx(symbol + period + ".hst", FILE_BIN|FILE_WRITE|FILE_SHARE_WRITE|FILE_SHARE_READ|FILE_ANSI);

   //int position = bars_back * OFFLINE_RECORD_SIZE;
   int position = (bars_back * OFFLINE_RECORD_SIZE) + 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
      // this won't work in backtesting mode
      if (!IsTesting()){
         int hwnd=WindowHandle(symbol, period);
         if (hwnd != 0){
            PostMessageA(hwnd, WM_COMMAND, 33324, 0);
         }
      }
   }
   //FileFlush(F);
   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));
   }
}
 
PostMessageA(hwnd, WM_COMMAND, 33324, 0);

change to

PostMessageW(hwnd, WM_COMMAND, 33324, 0);
 

No change to the result :-( and the file size go to 0kb.

 

then can you explain to me how this script works just fine for me (i used it on USDCHF)


#include <WinUser32.mqh>
#import "user32.dll"
   int RegisterWindowMessageW(string lpString);
#import

#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)

void OnStart()
{
   datetime Tm = Time[1];
   writeOfflineBar(Symbol(), Period(), 1, Tm, 0.87356, 0.85385, 0.88335, 0.87379, 1000);
   WindowRedraw();
   ChartRedraw();
   return;//(INIT_SUCCEEDED);
}


void writeOfflineBar(string   symbol, 
                                              int          period, 
                                              int          bars_back, 
                                              datetime          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 | 128 | 256);

   int position = (bars_back * OFFLINE_RECORD_SIZE) + 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);
      FileFlush(F);
      int hwnd=WindowHandle(symbol, period);
      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));
   }
}
 

I tried the same way but still doesn't work. No change for the bar. To demonstrate what I did I created a screen video:

>
 
i used B625
 

I've just tried on a fresh installed B625 version but no change. Here is the video to show it:

>
 

@qjol: Have you done it the same way as in the last video (on Build 625) ?

 
I am afraid that refresh event applied to an online chart forces data synchronization with the server.