A library that allows you to run workflows in an MT5 bot. Both asynchronous and synchronous jobs that require OnTimer\OnChartEvent to function... all through a YAML file where the user defines each step of the flow.
- MQL5 100%
| Images | ||
| Src | ||
| Test/First | ||
| dependencies.json | ||
| LICENSE | ||
| README.md | ||
| WorkflowsByLeo.mqproj | ||
A lightweight workflow engine for MQL5 that lets you define and run multi-step automation sequences from a simple YAML file.
Main Features
Define workflows in YAML
name: "my workflow"
env:
my_var: "hello"
steps:
- name: "RunEA"
module: "Generic"
with:
fixed:
name: "Experts\\MyEA.ex5"
symbol: _Symbol
timeframe: _Period
run_flags: "DLL|AutoTrading"
ms_sincronizacion: 500
timeout_segundos: 300
ea_params:
- InpNum: ["TYPE_UINT", "${{internal.number}}"]
- name: "PowerShellCommand"
module: "Generic"
with:
run: |
echo 'done'
timeout_segundos: 30
Run from MQL5
#resource "my_workflow.yml" as const string yml_workflow
TSN::CWorkflow flow;
TSN::CWfCallBack* callback = new TSN::CWfCallBack();
flow.AddCallBack(callback);
// Inject runtime variables
flow.Variables().Set("internal.number", string(GetTickCount()));
if(!flow.Init(yml_workflow))
return INIT_PARAMETERS_INCORRECT;
flow.First();
Callbacks
class CMyCallback : public TSN::IWorkflowCallback
{
public:
inline uint8_t FlagsCall() const override { return WORKFLOWBYLEO_CALLBACK_ALL_FLAGS; }
bool OnWorkflowStart() override
{
Print("Workflow started");
return true;
}
void OnWorkflowStep(int code, int step_index) override
{
PrintFormat("Step %d finished with code %d", step_index, code);
}
void OnWorkflowEnd(int code, int step_index) override
{
Print("Workflow ended, code: ", code);
}
};
Variable interpolation
Reference any variable inside the YAML using ${{key}}:
ea_params:
- InpMagic: ["TYPE_INT", "${{env.magic}}"]
- InpSymbol: ["TYPE_STRING", "${{env.symbol}}"]
Built-in steps
| Module | Name | Description |
|---|---|---|
Generic |
RunEA |
Opens a chart and runs an Expert Advisor with custom parameters, waits for it to finish |
Generic |
PowerShellCommand |
Executes a PowerShell command and waits for completion |
Generic |
SendMessage |
Sends a message (Telegram, etc.) |
Generic |
File |
File operations |
Repository Structure
WorkflowsByLeo/
├── Src/
│ ├── Core/ # Core definitions: CWorkflow, CWorkflowStep, IWorkflowCallback, factory
│ ├── Steps/ # Built-in steps (RunEA, RunProcess, Messages, File)
│ └── Final/ # Orchestrator — workflow execution engine
├── Test/
│ └── First/ # Basic usage example (sync workflow: RunEA + PowerShell)
└── Images/ # Repository assets
License
By downloading or using this repository, you accept the license terms.
Requirements
See dependencies.json for the full list of dependencies.
Some dependencies are private or require a purchase. Check each entry's
commentfield for access instructions.
Installation
cd "C:\Users\YOUR_USER\AppData\Roaming\MetaQuotes\Terminal\YOUR_ID\MQL5\Shared Projects"
tsndep install "https://forge.mql5.io/nique_372/WorkflowsByLeo.git"
- Requires the
tsndeppackage — available on PyPI. It automatically downloads and installs all declared dependencies. - If any dependency is private or paid, the install will fail for that package — check dependencies.json and contact me for access.
Quick Start
1. Define your workflow — create a .yml file and embed it as a resource:
#resource "my_workflow.yml" as const string yml_workflow
2. Include the library:
// TSN Ecosystem file include
#include <TSN\\WFlows\\Orquestador.mqh>
#include <TSN\\WFlows\\AllSteps.mqh>
// Or relative at your project
#include "..\\WorkflowsByLeo\\Src\\Steps\\All.mqh"
3. Instantiate, configure and run:
TSN::CWorkflow flow;
flow.Variables().Set("internal.number", string(GetTickCount()));
if(!flow.Init(yml_workflow))
return INIT_PARAMETERS_INCORRECT;
flow.First();
4. Clean up on deinit:
void OnDeinit(const int reason)
{
TSN::CWorflowsFactory::Deinit(reason);
}
See
Test\First\Generic.mq5andTest\First\test.ymlfor a complete working example.
Contact
- Platform: MQL5 Community
- Profile: https://www.mql5.com/es/users/nique_372
- Articles: https://www.mql5.com/es/users/nique_372/publications