In this first article, I've only shown the tip of the iceberg. TickORM goes much further: the idea is to completely change the way you work with databases in MQL5. The goal is to achieve something straightforward, simple, and powerful, where opening a database, creating a repository, and manipulating entities is as natural as working with arrays. By the end of the series, usage will resemble the example below, where you save, search, update, and delete records without writing a single manual query. This is the path I'm paving with TickORM.
int OnInit(void) { IDatabaseManager *database = new CDatabaseManager(); if(database.OpenDatabase("trades.sqlite")) { //--- Instance repository AccountRepository repo(database); //--- Insert Account acc; acc.number = 10; repo.save(acc); //--- Select All Account acc[]; repo.findAll(acc); ArrayPrint(acc); //--- Select by id Account acc = repo.findById(1); Print(acc.id); Print(acc.number); //--- Update Account acc; acc.id = 1; acc.number = 10; repo.update(acc); //--- Delete by id repo.deleteById(1); } database.CloseDatabase(); delete database; return(INIT_SUCCEEDED); }
In this first article, I've only shown the tip of the iceberg. TickORM goes much further: the idea is to completely change the way you work with databases in MQL5. The goal is to achieve something straightforward, simple, and powerful, where opening a database, creating a repository, and manipulating entities is as natural as working with arrays. By the end of the series, usage will resemble the example below, where you save, search, update, and delete records without writing a single manual query. This is the path I'm paving with TickORM.
FYI: An implementation of ORM for MQL5 has been presented in the book.
- www.mql5.com
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Check out the new article: Simplifying Databases in MQL5 (Part 1): Introduction to Databases and SQL.
We explore how to manipulate databases in MQL5 using the language's native functions. We cover everything from table creation, insertion, updating, and deletion to data import and export, all with sample code. The content serves as a solid foundation for understanding the internal mechanics of data access, paving the way for the discussion of ORM, where we'll build one in MQL5.
When we talk about MQL5, most conversations revolve around indicators, Expert Advisors, trading strategies, and backtests. But at some point, every trader or developer who seriously works with automation realizes that data persistence is crucial. And this is where databases come in. You might even think: "But I already save my results in CSV or TXT files, why complicate things with a database?" The answer lies in the organization, performance, and reliability that a database provides, especially when dealing with large volumes of information or complex operations.
In the context of MQL5, talking about databases may seem like an exaggeration at first glance. After all, the language is strongly oriented towards trading, indicators, and automated execution robots. But when we start dealing with strategies that involve large volumes of data, complex backtests, or detailed order records, the simplicity of standard files quickly proves insufficient. This is where understanding how to create, access, and manipulate a database becomes a tool capable of transforming your trading workflow.
A trader starting to explore databases in MQL5 will find dozens of native functions and standalone examples. It's enough to save and query records, but the question soon arises: *how to organize all this in a clean and reusable way in real projects?* In this series of articles, we go beyond documentation. We start with the basic functions of SQLite and progress step by step to build a **mini-ORM in MQL5 (TickORM)**. The idea is to transform direct calls into well-designed layers, inspired by Java's JDBC and JPA, but adapted to the MetaTrader ecosystem.
In this article, I demonstrate the fundamentals of databases in MQL5 and SQL. This paves the way for the subsequent articles to encapsulate these functions in classes, interfaces, and, finally, the ORM.
Author: joaopedrodev