Melhorar código inserir TICKS no SQLITE

 

Boa noite amigos. 

Tenho esse código que hoje pude testar no WINZ21 o qual travou 1 vez no período da manhã. Objetivo é armazenas os dados dos TICKS em uma arquivo do SQLITE.

Nâo sei se pode ter algo que possa ser adicionado que melhore a velocidade além da confiabilidade dos dados. 

Pensei também em inserir o campo SYMBOL.

Quem puder ajudar podemos disponibilizar o código para quem interessar.

//+------------------------------------------------------------------+
//|                                                       sqlite.mq5 |
//|                        Copyright 2020, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2020, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"

string filename="ibov.sqlite";
int db=DatabaseOpen(filename, DATABASE_OPEN_READWRITE | DATABASE_OPEN_CREATE |DATABASE_OPEN_COMMON);

int OnInit()
  {   
   if(db==INVALID_HANDLE)
     {
      Print("DB: ", filename, " open failed with code ", GetLastError());
     }
   Print("DB: ", filename, " open with code ");  
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
   DatabaseClose(db);
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {  
   MqlTick last_tick;
   if(SymbolInfoTick(Symbol(),last_tick))
     {
      //Print(last_tick.time,": Bid = ",last_tick.bid,
      //      " Ask = ",last_tick.ask,"  Volume = ",last_tick.volume,"  Flags = ",last_tick.flags);
     }
   else Print("SymbolInfoTick() falhou, erro = ",GetLastError());
      
   //string strTIME=StringFormat("D'%s",TimeToString(last_tick.time,TIME_DATE|TIME_MINUTES|TIME_SECONDS));
   string strTIME          =  StringFormat("%s",IntegerToString(last_tick.time));
   string strBID           =  StringFormat("%s",DoubleToString(last_tick.bid,2));
   string strASK           =  StringFormat("%s",DoubleToString(last_tick.ask,2));
   string strLAST          =  StringFormat("%s",DoubleToString(last_tick.last,2));
   string strTIME_MSC      =  StringFormat("%s",IntegerToString(last_tick.time_msc));
   string strFLAGS         =  StringFormat("%s",IntegerToString(last_tick.flags));
   //string strFLAGS = EnumToString((FLAGS_TYPES) TrateType(last_tick));
   string strVOLUME_REAL   =  StringFormat("%s",DoubleToString(last_tick.volume_real,0));
   
   string sql=StringFormat("INSERT INTO ibov (time,bid,ask,last,volume,time_msc,flags,volume_real)"
                                    "VALUES (%s, %s, %s, %s, %d, %s, '%s', %s)",
                                    strTIME, strBID, strASK, strLAST, last_tick.volume, strTIME_MSC, strFLAGS, strVOLUME_REAL); 
   Print(strTIME, ",", strBID, ",", strASK, ",", strLAST, ",", last_tick.volume, ",", strTIME_MSC, ",", strFLAGS, ",", strVOLUME_REAL);
   
   //--- insere dados na tabela 
   if(!DatabaseExecute(db, sql))
     {
      Print("DB: ", filename, " insert failed with code ", GetLastError());
     }   
  }
//+------------------------------------------------------------------+
Razão: