2026-02-03 06:42:44 -03:00
# EA expertdemo
2025-12-17 18:50:08 +00:00
2026-01-07 16:21:05 -03:00
**Expert Advisor demonstrating package reuse with KnitPkg for MetaTrader**
2025-12-17 17:05:41 -03:00
*MIT License*
---
## What is this?
2026-02-03 06:42:44 -03:00
EA `expertdemo` is a **demonstration project ** that showcases how to build a MetaTrader Expert Advisor (EA) by consuming KnitPkg packages.
2026-01-07 16:21:05 -03:00
It demonstrates best practices for structuring, packaging and compiling MQL5 code with KnitPkg – it is **not ** meant to be a production-grade
2025-12-23 17:53:13 -03:00
trading system, but rather an **educational example ** of how to reuse packages from the community or your own library.
2025-12-17 17:05:41 -03:00
## Features
- **Expert Advisor type** (`type: expert` ) – a complete, compilable EA that depends on multiple packages.
2026-02-03 06:42:44 -03:00
- **Transitive dependencies** – automatically resolves and includes `@douglasrechia/bar` and `@douglasrechia/calc` when compiled.
2025-12-17 17:05:41 -03:00
- **Flat include mode** (`include_mode: flat` ) – generates a single flattened header with all dependencies resolved.
- **MQL5 target** – works with MetaTrader 5.
2026-02-03 06:42:44 -03:00
- **Compile support** – `kp compile` compiles the EA to `.ex5` binary.
- **Bar watcher for new bar detection** - Re-calculates every new bar, not every tick.
2025-12-17 17:05:41 -03:00
## How it works
2026-01-07 16:21:05 -03:00
This EA uses two KnitPkg packages:
2025-12-17 17:05:41 -03:00
2026-02-03 06:42:44 -03:00
1. * * @douglasrechia/bar ** – provides `BarWatcher` (detects bar changes) and `Bar` (OHLCV data access)
2. * * @douglasrechia/calc ** – provides technical analysis functions like `SMA()` and `ATR()`
2025-12-17 17:05:41 -03:00
2026-02-03 06:42:44 -03:00
When you run `kp install` , KnitPkg automatically downloads both packages and resolves their transitive dependencies.
2025-12-17 17:05:41 -03:00
2026-01-01 19:56:07 -03:00
## Prerequisites
To compile and run this project, you will need:
1. [**MetaTrader 5** ](https://www.mql5.com/ ) installed.
2026-02-03 06:42:44 -03:00
2. **KnitPkg CLI ** : The KnitPkg package manager for MetaTrader. If you don't have it, you can install it by following the instructions in the [main KnitPkg repository ](https://github.com/DouglasRechia/kp ).
2026-01-01 19:56:07 -03:00
2026-02-03 06:42:44 -03:00
## Downloading and install `expertdemo` in your MetaTrader
2025-12-17 17:05:41 -03:00
2026-01-07 16:21:05 -03:00
To learn how to structure your own EA with KnitPkg packages, clone this repository:
2025-12-17 17:05:41 -03:00
```bash
# Change to your MetaTrader 'Experts' directory.
# How to find it: in the MetaEditor navigator, right‑click the `Experts` folder and select "Open Folder".
cd "C:\Users\username\AppData\Roaming\MetaQuotes\Terminal\D0E8209F77C8CF37AD8BF550E51FF075\MQL5\Experts"
# Clone the repository
2026-02-03 06:42:44 -03:00
git clone https://forge.mql5.io/DouglasRechia/expertdemo.git
cd expertdemo
2025-12-17 17:05:41 -03:00
2026-02-03 06:42:44 -03:00
# Install dependencies (downloads @douglasrechia/calc and @douglasrechia/bar automatically)
kp install
2025-12-17 17:05:41 -03:00
# Compile the EA
2026-02-03 06:42:44 -03:00
kp compile
2025-12-17 17:05:41 -03:00
2026-02-03 06:42:44 -03:00
# Close MetaTrader and launch it again (needed to refresh navigator Scripts). Open any chart you want.
# The compiled binary `KnitPkgExpertDemo.ex5` will appear in MetaTrader navigator under the Experts/expertdemo/bin entry.
# Double‑click it to run the tests. See logs in the 'Scripts' tab.
```
Alternatively, execute the `get` command to query the registry for project metadata, enabling the automatic
download and compilation of the latest stable version.
``` bash
# Change to your MetaTrader Data folder directory. This is step is required only if you have
# more than one MetaTrader instalation.
# How to find it: in the MetaTrader navigator, click on menu File/Open data folder.
cd "C:\Users\username\AppData\Roaming\MetaQuotes\Terminal\D0E8209F77C8CF37AD8BF550E51FF075"
kp get mql5 @douglasrechia/expertdemo
# Close MetaTrader and launch it again (needed to refresh navigator Scripts). Open any chart you want.
# The compiled binary `KnitPkgExpertDemo.ex5` will appear in MetaTrader navigator under the Experts/expertdemo/bin entry.
# Double‑click it to run the tests. See logs in the 'Scripts' tab.
2025-12-17 17:05:41 -03:00
```
## License
This project is released under the **MIT License ** . See the `LICENSE` file for the full text.
## Disclaimer
*The author provides this code **as‑is ** , for **educational purposes only*.
No warranty, express or implied, is given. The author assumes **no liability ** for any damages, losses, or legal consequences that may arise from using, modifying, or distributing this software. Use it at your own risk.*