Metatrader offline chart data update .hst file last candelst

All posts which do not fit into any other sections of the forum.

Moderator: admin

Metatrader offline chart data update .hst file last candelst

Postby Codebaseuser » Fri Nov 26, 2021 6:53 pm

J have a Metatrader EA script which does create a .hst file. This .hst file contains candelstick market data, it is used to display custom offline charts with metatrader. My scripts work so that it does save around 1000 candeelsticks into the .hst file and i need to change it to make just a update of the last candelstick without deleting the other candelsticks market data which is saved in the .hst file.

But the only idea which i did have was to change the for loop to make only 1 or 2 runs, but if i do that, then i have later just 1 or 2 candelsticks in the chart, because it looks like the complete .hst file is overwritten.

I dont know if you need to open the .hst file with different parameters or if you need to make something else to get it just updateing the last candelstick, if somebody know how to do it correctly your help would be appricated.

Here is my current EA script code, i just show the part of the code which does create the candelstick .hst file:

Code: Select all
     //+------------------------------------------------------------------+
     //| Save HST File                                                    |
     //+------------------------------------------------------------------+

ExtHandle=FileOpenHistory(NewFileName,FILE_BIN|FILE_WRITE|FILE_SHARE_WRITE|FILE_SHARE_READ|FILE_ANSI);
        if(ExtHandle<0) return;
   
   
        //--- write history file header
        c_copyright="(C)opyright 2003, MetaQuotes Software Corp.";
        ArrayInitialize(i_unused,0);
        FileWriteInteger(ExtHandle,file_version,LONG_VALUE);
        FileWriteString(ExtHandle,c_copyright,64);
        FileWriteString(ExtHandle,c_symbol,12);
        FileWriteInteger(ExtHandle,i_period,LONG_VALUE);
        FileWriteInteger(ExtHandle,i_digits,LONG_VALUE);
        FileWriteInteger(ExtHandle,0,LONG_VALUE);
        FileWriteInteger(ExtHandle,0,LONG_VALUE);
        FileWriteArray(ExtHandle,i_unused,0,13);
   
                int BarsBack=1000; // when i change this to 1 or 2 then i have just 1 or 2 candelsticks data in the file
   
                for(int i=BarsBack; i>=1; i--)
                {
                   //--- write history file
                   if(date>0)
                   {
                    start_pos=BarsBack;
                    rate.open=open;
                    rate.low=low;
                    rate.high=high;
                    rate.close=close;
                    rate.tick_volume=(long)volume;
                    rate.spread=0;
                    rate.real_volume=0;
                    rate.time=date;
         
                    if(IsStopped()) break;
         
                    last_fpos=FileTell(ExtHandle);
                    last_volume=(long)volume;
                    FileWriteStruct(ExtHandle,rate);
                   }
               }//for
   
      //---
      FileFlush(ExtHandle);
      FileClose(ExtHandle);
Codebaseuser
 
Posts: 2
Joined: Fri Nov 26, 2021 6:46 pm

Re: Metatrader offline chart data update .hst file last cand

Postby Codebaseuser » Tue Nov 30, 2021 10:19 am

Somebody told me that the function FileSeek() can help, have somebdy experience with that?
Codebaseuser
 
Posts: 2
Joined: Fri Nov 26, 2021 6:46 pm


Return to General Discussions

Who is online

Users browsing this forum: No registered users and 7 guests