Fixing MQLRates

 

I am importing data from Websocket :

            MqlRates rates[1];
            ArrayResize(rates,1);
            rates[0].open = open;
            rates[0].high = high;
            rates[0].low  = low;
            rates[0].close= close;
            rates[0].time= time/1000;
            CustomRatesReplace(_Symbol,rates[0].time,rates[0].time,rates);
            ZeroMemory(rates);

all is working fine except the 2021.hcc file under bases> Custom > history folder is too big almost 1GB if system keep receiving data for 12 hours

I am using this code to fix hcc file size

 MqlRates rates[];
      int candlecount = iBars(_Symbol, PERIOD_M1);
      candlecount = candlecount>100000? 100000 : candlecount;
      if(candlecount == CopyRates(_Symbol, PERIOD_M1, 0, candlecount, rates)) {
         if(candlecount == CustomRatesDelete(_Symbol, rates[0].time, rates[candlecount-1].time)) {
            CustomRatesUpdate(_Symbol, rates);
         }
      }

this code immediately reduce size of hcc from 1GB  to 20MB

To prevent misuse of disk, I am looking for how can i fix code so hcc file always remains low size.

I appreciate and thank you for any help

Websockets for MetaTrader 5
Websockets for MetaTrader 5
  • www.mql5.com
Before the introduction of the network functionality provided with the updated MQL5 API, MetaTrader programs have been limited in their ability to connect and interface with websocket based services. But of course this has all changed, in this article we will explore the implementation of a websocket library in pure MQL5. A brief description of the websocket protocol will be given along with a step by step guide on how to use the resulting library.