One of many largest options in KnitPkg v1.0.0 is one thing I feel many severe EA/indicator builders have all the time needed in MQL5, however by no means actually had: construct‑time configuration, similar to compile‑time directives in C/C++.
What’s BuildInfo.mqh?
If you run from the CLI:
kp compile
kp construct
and your manifest knitpkg.yaml has a defines part, KnitPkg routinely generates a header at:
knitpkg/construct/BuildInfo.mqh
This header accommodates a bunch of #outline directives that you need to use wherever in your MQL5 code:
#embody "../knitpkg/construct/BuildInfo.mqh"
The cool half is that these constants come from:
- Your manifest fields ( model , description , writer , and so on.)
- Additional constants you outline within the manifest
- Command‑line flags handed by way of ` kp compile -D …`
All of that will get was pure MQL #outline s at compile time – no runtime parsing, no string juggling, no JSON/INI studying hacks.
It’s basically a light-weight construct system for MQL, powered by compile‑time constants.
Why this seems like C-style compile-time directives
When you’re used to C/C++ or different compiled languages, this may really feel very acquainted:
- You declare constants as soon as in a central place (the manifest).
- KnitPkg turns them into #defines in BuildInfo.mqh.
- You employ #ifdef, #else, #endif and string/quantity constants in your MQL5 code.
- You’ll be able to inject or override constants from the CLI similar to you’d cross -D flags to a C compiler.
Instance from the manifest (knitpkg.yaml):
defines:
from_manifest:
MANIFEST_VERSION: model
MANIFEST_ORG: group
MANIFEST_AUTHOR: writer
MANIFEST_DESCRIPTION: description
additional:
MQL_STORE_VERSION: '2.1'
MAX_BARS: 500
FEATURE_X_ENABLED: true
Generates one thing like:
#outline MANIFEST_VERSION "2.0.1" #outline MANIFEST_ORG "douglasrechia" #outline MANIFEST_AUTHOR "Douglas Rechia" #outline MANIFEST_DESCRIPTION "KnitPkg for Metatrader - Knowledgeable Demo" #outline MQL_STORE_VERSION "2.1" #outline MAX_BARS 500 #outline FEATURE_X_ENABLED true
When you’ve ever used -D flags in gcc/clang, this may really feel proper at house.
Key use instances the place BuildInfo actually helps
1. Clear, centralized EA metadata (model, writer, description, and so on.). As a substitute of hardcoding model, writer and outline in a number of locations, you outline them as soon as within the manifest and let KnitPkg preserve your EA properties in sync.
#embody "../knitpkg/construct/BuildInfo.mqh"
#property copyright "Copyright © 2026 " + MANIFEST_AUTHOR + ". All rights reserved."
#property hyperlink "https://knitpkg.dev"
#property model (string)MQL_STORE_VERSION
#property description ""
#property description "Model: " + MANIFEST_VERSION
#property description ""
#property description "Description: " + MANIFEST_DESCRIPTION
#property description "Group: " + MANIFEST_ORG
#property description "Writer: " + MANIFEST_AUTHOR
#property description ""
#property description "Powered by KnitPkg for MetaTrader"
#property description "https://knitpkg.dev"
Change model or description in knitpkg.yaml, run kp compile, and the EA “Frequent” tab is routinely up to date. No guide sync, no forgotten model bumps.
2. Function flags at compile time (flip options on/off with out touching code). You’ll be able to gate elements of your code behind function flags which might be managed purely by construct configuration.
From the CLI:
kp compile -D FEATURE_RISK_MODEL_V2
In your EA:
#embody "../knitpkg/construct/BuildInfo.mqh" double CalculateRisk() { #ifdef FEATURE_RISK_MODEL_V2 return NewRiskModel(); #else return LegacyRiskModel(); #endif }
Need to ship an experimental danger mannequin solely in “beta” builds? Simply add or take away the -D flag; the code stays the identical.
3. Totally different builds for brokers / environments / channels. You’ll be able to produce a number of flavors of the identical EA from the identical codebase: debug vs retailer, inside vs manufacturing, dealer‑particular variants, and so on.
For instance:
kp compile -D BUILD_CHANNEL=beta kp compile -D BUILD_CHANNEL=manufacturing
In code:
#embody "../knitpkg/construct/BuildInfo.mqh" void OnInit() { #ifdef BUILD_CHANNEL Print("Construct channel: ", BUILD_CHANNEL); #endif }
And even surroundings/dealer‑particular parameters:
kp compile -D ENV=prod -D BROKER_CODE=ICMARKETS kp compile -D ENV=staging -D BROKER_CODE=OANDA
In EA:
#embody "../knitpkg/construct/BuildInfo.mqh" void OnInit() { Print("Surroundings: ", ENV); Print("Dealer code: ", BROKER_CODE); #ifdef ENV if (ENV == "prod") { } else { } #endif }
4. Debug vs retailer builds (logging, assertions, additional checks). You’ll be able to add basic “debug” vs “launch/retailer” conduct by toggling flags at compile time.
Compile:
kp compile -D DEBUG_BUILD
EA code:
#embody "../knitpkg/construct/BuildInfo.mqh" #ifdef DEBUG_BUILD #outline LOG_LEVEL 3 #else #outline LOG_LEVEL 1 #endif
Methods to begin utilizing BuildInfo
1.Initialize your undertaking with KnitPkg. When you’re ranging from scratch, kp init already units up a wise default configuration for you: it creates the manifest with a defines part and generates an EA/indicator/utility skeleton that’s wired to BuildInfo.mqh, together with the #property directives for the “Frequent” tab (model, description, writer, and so on.). In lots of instances you may simply run kp init, open the generated .mq5, and see BuildInfo in motion with out doing anything.
2. Configure defines within the manifest.
- Use from_manifest to reveal undertaking metadata (model, writer, description, group, and so on.).
- Use additional for arbitrary constants like MQL_STORE_VERSION, MAX_BARS, or function flags.
3. Compile with KnitPkg CLI. Run:
kp compile
kp construct
KnitPkg will generate knitpkg/construct/BuildInfo.mqh routinely.
4. Embrace BuildInfo.mqh in your MQL5 code.
#embody "../knitpkg/construct/BuildInfo.mqh"
5. Optionally add per‑construct flags. Use kp compile -D NAME or kp compile -D NAME=worth in your native workflow or CI to provide completely different variants (debug, retailer, nightly, dealer‑particular, and so on.) from the identical codebase.
When you’re constructing severe EAs or indicators and also you miss the extent of construct management you get in C/C++ initiatives, BuildInfo in KnitPkg v1.0.0 brings that have a lot nearer to MQL5 – with centralized metadata, compile‑time function flags, and clear, reproducible construct variants from a single codebase.
When you’re curious concerning the particulars or need extra examples, the complete docs can be found within the KnitPkg documentation below the “Construct Information” idea and consumer information sections.

























