28.3 C
San Juan
Wednesday, March 18, 2026

Introducing BuildInfo in KnitPkg v1.0.0 – Actual Compile‑Time Constants for MQL5 – Buying and selling Methods – 17 March 2026


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

Notice: if you happen to’re not but acquainted about what KnitPkg is, check out this text or the documentation web page.

What’s BuildInfo.mqh?

Whenever 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 incorporates a bunch of  #outline directives that you should utilize anyplace in your MQL5 code:

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

The cool half is that these constants come from:

  • Your manifest fields ( model ,  description ,  creator , and so on.)
  • Additional constants you outline within the manifest
  • Command‑line flags handed through ` 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 to be like C-style compile-time directives

In the event you’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 utilize #ifdef, #else, #endif and string/quantity constants in your MQL5 code.
  • You possibly can inject or override constants from the CLI identical to you’d move -D flags to a C compiler.

Instance from the manifest (knitpkg.yaml):

defines:
  from_manifest:
    MANIFEST_VERSION: model
    MANIFEST_ORG: group
    MANIFEST_AUTHOR: creator
    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 - Skilled Demo"
#outline MQL_STORE_VERSION "2.1"
#outline MAX_BARS 500
#outline FEATURE_X_ENABLED true

In the event you’ve ever used -D flags in gcc/clang, it will really feel proper at dwelling.

Key use instances the place BuildInfo actually helps

1. Clear, centralized EA metadata (model, creator, description, and so on.). As a substitute of hardcoding model, creator and outline in a number of locations, you outline them as soon as within the manifest and let KnitPkg maintain 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 “Widespread” tab is robotically up to date. No handbook sync, no forgotten model bumps.

2. Function flags at compile time (flip options on/off with out touching code). You possibly can gate components 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:

#embrace "../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 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 so on.

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("Atmosphere: ", 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

How you can begin utilizing BuildInfo

1.Initialize your undertaking with KnitPkg. In the event 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 “Widespread” tab (model, description, creator, and so on.). In lots of instances you’ll be able to 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 show undertaking metadata (model, creator, 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 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 supply totally different variants (debug, retailer, nightly, dealer‑particular, and so on.) from the identical codebase.

In the event you’re constructing critical EAs or indicators and also you miss the extent of construct management you get in C/C++ tasks, 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.

In the event you’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 person information sections.

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Stay Connected

0FansLike
0FollowersFollow
0SubscribersSubscribe
- Advertisement -spot_img

Latest Articles