HomeSample Page

Sample Page Title


One of many greatest options in KnitPkg v1.0.0 is one thing I feel many severe EA/indicator builders have all the time wished in MQL5, however by no means actually had: construct‑time configuration, similar to compile‑time directives in C/C++.

What’s BuildInfo.mqh?

While you run from the CLI:

kp compile

kp construct

and your manifest knitpkg.yaml has a defines part, KnitPkg robotically generates a header at:

knitpkg/construct/BuildInfo.mqh

This header accommodates a bunch of  #outline directives that you should utilize wherever in your MQL5 code:

#embrace "../knitpkg/construct/BuildInfo.mqh"

The cool half is that these constants come from:

  • Your manifest fields ( model ,  description ,  writer , and many others.)
  • Further constants you outline within the manifest
  • Command‑line flags handed by way of ` kp compile -D …`

All of that will get become pure MQL  #outline s at compile time – no runtime parsing, no string juggling, no JSON/INI studying hacks.

It’s primarily a light-weight construct system for MQL, powered by compile‑time constants.

Why this seems like C-style compile-time directives

If you happen to’re used to C/C++ or different compiled languages, it will 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 possibly can 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

If you happen to’ve ever used -D flags in gcc/clang, it will really feel proper at house.

Key use circumstances the place BuildInfo actually helps

1. Clear, centralized EA metadata (model, writer, description, and many others.). As an alternative 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.

#embrace "../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 robotically up to date. No handbook sync, no forgotten model bumps.

2. Characteristic flags at compile time (flip options on/off with out touching code). You possibly can gate elements of your code behind function flags which are managed purely by construct configuration.

From the CLI:

kp compile -D FEATURE_RISK_MODEL_V2

In your EA:

#embrace "../knitpkg/construct/BuildInfo.mqh"

double CalculateRisk()
{
#ifdef FEATURE_RISK_MODEL_V2
   return NewRiskModel();
#else
   return LegacyRiskModel();
#endif
}

Wish to ship an experimental danger mannequin solely in “beta” builds? Simply add or take away the -D flag; the code stays the identical.

3. Completely different builds for brokers / environments / channels. You possibly can produce a number of flavors of the identical EA from the identical codebase: debug vs retailer, inner vs manufacturing, dealer‑particular variants, and many others.

For instance:


kp compile -D BUILD_CHANNEL=beta


kp compile -D BUILD_CHANNEL=manufacturing

In code:

#embrace "../knitpkg/construct/BuildInfo.mqh"

void OnInit()
{
#ifdef BUILD_CHANNEL
   Print("Construct channel: ", BUILD_CHANNEL);
#endif
}

And even atmosphere/dealer‑particular parameters:

kp compile -D ENV=prod -D BROKER_CODE=ICMARKETS
kp compile -D ENV=staging -D BROKER_CODE=OANDA

In EA:

#embrace "../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 possibly can add traditional “debug” vs “launch/retailer” habits by toggling flags at compile time.

Compile:


kp compile -D DEBUG_BUILD

EA code:

#embrace "../knitpkg/construct/BuildInfo.mqh"

#ifdef DEBUG_BUILD
   #outline LOG_LEVEL 3
#else
   #outline LOG_LEVEL 1
#endif

Find out how to begin utilizing BuildInfo

1.Initialize your mission with KnitPkg. If you happen to’re ranging from scratch, kp init already units up a smart 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 many others.). In lots of circumstances you’ll be able to simply run kp init, open the generated .mq5, and see BuildInfo in motion with out doing the rest.

2. Configure defines within the manifest

  • Use from_manifest to reveal mission metadata (model, writer, description, group, and many others.).
  • 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 robotically.

4. Embody BuildInfo.mqh in your MQL5 code

#embrace "../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 totally different variants (debug, retailer, nightly, dealer‑particular, and many others.) from the identical codebase.

If you happen to’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.

If you happen to’re curious in regards to the particulars or need extra examples, the total docs can be found within the KnitPkg documentation beneath the “Construct Data” idea and consumer information sections.

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles