Creating .hst files without Metatrader

Email Account
59

I am using currently the periodconverter script example to create custom offline chart files but it looks like the metatrader is using to much CPU for creating this files.

Is it possible to create this files without metatrader and save them just in the right folder?

If i open the files in a texteditor then i see directly it is not easy format like json, so the questions is here how to format the date and save it correctly into this .hst files.

Or is it maybe also possible to connect somethink like a own created datafeed into metatrader where i just send the data to metatrader and he create the files without using script or EA?

William Roeder
26403
William Roeder  
Email Account: Is it possible to create this files without metatrader and save them just in the right folder?
  1. The terminal won't know when they change, therefor indicators and EA won't work.

  2. If your indicator(s) take too long to compute, reduce Tools → Options (control+O) → Charts → Max bars in chart to something reasonable (like 1K.)

Email Account
59
Email Account  

Hello William Roeder,

i very appreciate your support, as i know you are a long term supporter of the mql community and it is also sometimes hard to find support for a special software like metatrader.

I am currently testing simple ideas how to create offline charts for crypto currencys from exchanges like binance, the concept is not so difficult, i have use the simple Wenrequest function from Metatarder to get crypto currency data and i have make some different test to find out which functions are costing currently the most cpu.

I have finaly find out that the following code part is using the most cpu, it is the part where my EA does save the market data into the .hst file, i am currently not sure if also the problem is that in my code i am running a for loop with 1000 runs or if generally the high cpu comes because i do this on around 20-50 offline charts at same time. I know of course the the cpu useage will be smaller when i dont open so many charts, but sometimes you can also try to optimize your code to get better results.

I think i also need to make this for loop to make 1000 runs because i always save 1000 candelsticks into the files and i dont know if i can just save the last candelstick or in other word the newest candelstick into the already existings file, i have at least not find a code example for that. In my current code you can see the idea is very easy, if the string variable "str" have data then the data will be save into the .hst file and this part of the code is running on 20 - 50 offline charts every few seconds and is costing most of the cpu.

 //+------------------------------------------------------------------+
 //| Save HST File                                                    |
 //+------------------------------------------------------------------+

   if(StringLen(str)>10)
   {
    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;

            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);
  }//StringLen(str)>10


//+------------------------------------------------------------------+
//| Update Chart                                                     |
//+------------------------------------------------------------------+

   if(chart_id==0)
     {
        long id=ChartFirst();
        while(id>=0)
        {
            //--- find appropriate offline chart
            if(ChartSymbol(id)==c_symbol && ChartPeriod(id)==i_period && ChartGetInteger(id,CHART_IS_OFFLINE))
              {
                chart_id=id;
                ChartSetInteger(chart_id,CHART_AUTOSCROLL,true);
                ChartSetInteger(chart_id,CHART_SHIFT,true);
                ChartNavigate(chart_id,CHART_END);
                ChartRedraw(chart_id);
                PrintFormat("Chart window [%s,%d] found",c_symbol,i_period);
                break;
              }
            //--- enumerate opened charts
            id=ChartNext(id);
         }
       }
    //--- refresh window 
    if(chart_id!=0)
      { 
        ChartSetSymbolPeriod(chart_id,Symbol(),i_period);

        Print("Chart refresh call");
      }

Now my idea was if i just create this .hst files with something else and save them into the folder it would save a lot of cpu but your comment abouth charts and indicators update is of course a additional problem, if that is the behavior of metatrader, i have not try it out because i dont know how to create correct .hst files without metatrader, but i have such a feeling that this function "ChartSetSymbolPeriod" is doing the update and it could work, i can try that out of course but that will again not slove the question how to create myself .hst files without metatrader to save some cpu.

The other tips from you abouth settings and candelsticks in chart i also know and i have already setup small numbers.

Maybe if i just can change my for loop to save just the newest candelstick into the .hst files that could also save a lot of cpu, do you know if that is possible? Because currently i am saveing always all 1000 candelsticks into the .hst file.

William Roeder
26403
William Roeder  

Your code is writing a thousand bars each tick.

Go find an offline chart generator that doesn't. Only updates the last bar, and does a refresh once every few seconds.

Vladimir Perervenko
5074
William Roeder #:

Your code is writing a thousand bars each tick.

Go find an offline chart generator that doesn't. Only updates the last bar, and does a refresh once every few seconds.

Посмотрите здесь. Там есть ответы на Ваши вопросы.

Удачи 

GitHub - dingmaotu/mql4-lib: MQL4/5 Foundation Library For Professional Developers
GitHub - dingmaotu/mql4-lib: MQL4/5 Foundation Library For Professional Developers
  • github.com
MQL4/5 Foundation Library For Professional Developers - GitHub - dingmaotu/mql4-lib: MQL4/5 Foundation Library For Professional Developers
Email Account
59
Email Account  
William Roeder #:

Your code is writing a thousand bars each tick.

Go find an offline chart generator that doesn't. Only updates the last bar, and does a refresh once every few seconds.

Thats is good to know that you can just update the last bar, i will search for such a script, if you want to share a link woul be also apprecated, thanks for your help.

Email Account
59
Email Account  
Vladimir Perervenko #:

Посмотрите здесь. Там есть ответы на Ваши вопросы.

Удачи 

Thank you also for your help, i will check your links

Email Account
59
Email Account  
William Roeder #:

Your code is writing a thousand bars each tick.

Go find an offline chart generator that doesn't. Only updates the last bar, and does a refresh once every few seconds.

If you look to my code example do you know how the code or the for loop or the FileOpenHistory function must be changed to make it updateing just the last candelstick without rewirteing the complete .hst file, because in my testings i see that the .hst file have later just 1 or 2 candelstick data if i change the for loop to make just 1 or 2 runs? I dont find a period converter which works so that it updates just the last candelsticks and you know maybe yourself how difficult it is to find right exxample for metatrader because it is not so much coder community for mql language.