Watch how to download trading robots for free
Interesting script?
So post a link to it -
let others appraise it
You liked the script? Try it in the MetaTrader 5 terminal
Libraries

Database Wrapper - library for MetaTrader 5

MoT

Published by:
iyumot
Views:
719
Rating:
votes: 6
Published:
2021.01.30 09:28
Updated:
2021.02.02 06:57
\MQL5\Include\
Database.mqh (65.59 KB) view
test.mq5 (1.51 KB) view

Introduction

SQLite locks are coarse-grained file locks. If multiple tables share a database, you need to pay attention to synchronization issues.
a. It is not recommended to define global variables for the classes in this class, otherwise 5605 errors will easily occur
b. After the query, the data should be retrieved and released as soon as possible to prevent other connections from being unable to obtain the reserved lock
c. Try to Execute in the transaction to avoid some 5605 errors

example:

// Open the database

CDatabase db(mDbPath);

if(!db.IsAvaliable()) //check is avaliable

   return false;

// There is a form check

if(!db.HasTable("Terminal"))
      db.Execute("CREATE TABLE Terminal (Id TEXT);");


// Query

CDatabaseRequest *req = db.Query("select count(*) from Terminal;");

if(req.IsAvaliable() && req.Read()) // check and read

     {

      int val = req.GetInteger("count(*)",-1);//with value -1 for an error

      if(val == 0) //execute

         db.Execute("insert into Terminal (Id) values('aaaa');");

     }

The request and database will be automatically closed at the following location   Destructor  

// Execute

   db.Execute(sql);//完整的sql

   CDatabaseSentece *s = db.BeginExecute("insert int xxx values(?,?,?);");//模式赋值,个人觉得没什么用

   s.Bind(1);

   s.Bind(2);

   s.Bind("abc");

   s.Execute();

事务

   db.BeginTransaction();

   db.Rollback();

   db.Commit();

    


// CDatabaseTable supports migration

class csampletable:CDatabaseTable

{

.......

}

csampletable :: csampletable (void)

  {

   Table = "Strategy";

   ArrayResize(SqlCreateTable,2);

   ArrayResize(SqlMoveRecord,2);


//0 for initial ddl then for every update, fill sqlcreatetable and moverecord like following, the adding field cannot be uniqe!!!

   SqlCreateTable[0] = "CREATE TABLE Strategy(Id INTEGER PRIMARY KEY ON CONFLICT IGNORE );";

   SqlCreateTable[1] = "CREATE TABLE Strategy(Id INTEGER PRIMARY KEY ON CONFLICT IGNORE, Ticket INTEGER);";

   SqlMoveRecord[1] = "INSERT INTO Strategy (Id, Ticket) SELECT Id FROM sqlitestudio_temp_table;";

   OnMiggrate();

  }



Sell using amount instead of lots Sell using amount instead of lots

I find the lot calculation tedious so I just use this script and tell it the dollar amount to use. It then does the rest. This works for any currency.

Buy using amount instead of lots Buy using amount instead of lots

I find the lot calculation tedious so I just use this script and tell it the dollar amount to use. It then does the rest. This works for any currency.

Spread data collector Spread data collector

This EA collects information about the spreads and Shows the number of spreads in the specified range based on the ticks that occur each year.

INDICATOR Breakout Strength Meter - MT5 INDICATOR Breakout Strength Meter - MT5

The breakout strength meter is a trading tool that is used to identify which currencies are the strongest to breakout, and which currencies are the weakest to breakout