# sibvic/mq5-templates architecture

> Architecture diagram of the GitHub repository sibvic/mq5-templates, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sibvic/mq5-templates
- Repository: https://github.com/sibvic/mq5-templates

## Overview

##### Main Components
- Templates Layer – Represented by the “templates” folder. This component contains base expert advisors and indicators (e.g., EA_Base.mq5, arrows_indicator.mq5, heatmap.mq5) that act as starting points for building custom trading algorithms.
- Snippets Library – The “snippets” folder is the heart of this project. It is subdivided into a rich collection of modular components:
- Actions: Files implementing various trade actions (e.g., entry orders, trailing stops, close orders).
- Conditions: Abstract and concrete conditions (e.g., market conditions, entry/exit criteria) that can be combined to signal when an action should occur.
- Grid, MoneyManagement, Objects, TradingMonitor, etc.: Each subfolder encapsulates functionalities like order grid management, risk/position sizing strategies, drawing objects, and monitoring active trades.
- Streams and PineScript: These folders provide functionalities related to handling data streams and adapting or working with PineScript code, respectively.
- External Dependencies – Highlight integrations such as:
- MQ4Inject: Allows injecting the code into templates.
- MT Notifications DLL: As mentioned in the README for advanced notifications (e.g., sending alerts via Telegram).
- Auxiliary Utilities – Utilities, enumerations, and routines that support standardized operations throughout the system (e.g., “snippets/Utils”, “snippets/enums”, “snippets/routines.mqh”).

##### Relationships and Data Flow
- The Templates layer uses the Snippets Library as building blocks. For instance, template EA files might include or reference multiple snippet files for executing orders, validating conditions, and performing money management.
- Actions and Conditions: Illustrate how trade entry or exit actions are triggered by specific conditions.
- MoneyManagement and Order Handling: Demonstrate how order building components rely on money management strategies to ensure risk is properly managed.
- Streams & Data: Show how data streams feed into oscillators, averages, or indicator computations to facilitate technical analysis.
- External tools (MQ4Inject, notifications DLL) act as bridges that either integrate additional code at compile-time or handle post-trade notifications.

##### Notable Architectural Patterns & Design Principles
- Modularity: The clear separation within the “snippets” folder (subdirectories for Actions, Conditions, Grid, etc.) illustrates a strong modular design.
- Extensibility: Use of abstract classes and interfaces (e.g., IAction, ICondition, ICellFactory) promote flexibility and allow further extensions.
- Reusability: Common functionalities like grid building, order iterators, and condition evaluations are abstracted into self-contained components that can be reused across different templates.
- Abstraction Layers: Templates are high-level components meant for direct user adoption, while snippets provide lower-level, reusable building blocks for technical implementation.

## Diagram (Mermaid)

```mermaid
flowchart TD
    TEMPLATES["Templates Layer"]:::templates
    SNIPPETS["Snippets Library"]:::snippets
    EXTERNAL["External Dependencies: MQ4Inject & MT Notifications DLL"]:::external

    TEMPLATES -->|"uses"| SNIPPETS
    EXTERNAL -->|"injects"| TEMPLATES

    subgraph "Snippets Components"
        ACTIONS["Actions Module"]:::module
        CONDITIONS["Conditions Module"]:::module
        GRID["Grid Module"]:::module
        MONEY["MoneyManagement Module"]:::module
        OBJECTS["Objects Module"]:::module
        MONITOR["Trading Monitor Module"]:::module
        STREAMS["Streams Module"]:::module
        PINESCRIPT["PineScript Module"]:::module
    end

    subgraph "Auxiliary Utilities"
        UTILS["Utils"]:::utility
        ENUMS["Enums"]:::utility
        ROUTINES["Routines"]:::utility
    end

    SNIPPETS --> ACTIONS
    SNIPPETS --> CONDITIONS
    SNIPPETS --> GRID
    SNIPPETS --> MONEY
    SNIPPETS --> OBJECTS
    SNIPPETS --> MONITOR
    SNIPPETS --> STREAMS
    SNIPPETS --> PINESCRIPT

    SNIPPETS --> UTILS
    SNIPPETS --> ENUMS
    SNIPPETS --> ROUTINES

    CONDITIONS -->|"triggers"| ACTIONS
    MONEY -->|"influences"| GRID
    STREAMS -->|"feeds"| PINESCRIPT
    MONITOR -->|"oversees"| ACTIONS

    UTILS ---|"assists"| SNIPPETS
    ENUMS ---|"defines"| SNIPPETS
    ROUTINES ---|"supports"| SNIPPETS

    classDef templates fill:#ffcccc,stroke:#d62728,stroke-width:2px;
    classDef snippets fill:#cce5ff,stroke:#1f77b4,stroke-width:2px;
    classDef module fill:#e2f0cb,stroke:#2ca02c,stroke-width:2px;
    classDef utility fill:#f9e79f,stroke:#f39c12,stroke-width:2px;
    classDef external fill:#d5f5e3,stroke:#27ae60,stroke-width:2px;

    click TEMPLATES "https://github.com/sibvic/mq5-templates/tree/master/templates"
    click SNIPPETS "https://github.com/sibvic/mq5-templates/tree/master/snippets"
    click ACTIONS "https://github.com/sibvic/mq5-templates/tree/master/snippets/Actions"
    click CONDITIONS "https://github.com/sibvic/mq5-templates/tree/master/snippets/Conditions"
    click GRID "https://github.com/sibvic/mq5-templates/tree/master/snippets/Grid"
    click MONEY "https://github.com/sibvic/mq5-templates/tree/master/snippets/MoneyManagement"
    click OBJECTS "https://github.com/sibvic/mq5-templates/tree/master/snippets/Objects"
    click MONITOR "https://github.com/sibvic/mq5-templates/tree/master/snippets/TradingMonitor"
    click STREAMS "https://github.com/sibvic/mq5-templates/tree/master/snippets/Streams"
    click PINESCRIPT "https://github.com/sibvic/mq5-templates/tree/master/snippets/PineScript"
    click UTILS "https://github.com/sibvic/mq5-templates/tree/master/snippets/Utils"
    click ENUMS "https://github.com/sibvic/mq5-templates/tree/master/snippets/enums"
    click ROUTINES "https://github.com/sibvic/mq5-templates/blob/master/snippets/routines.mqh"
```
