riskgate-ea-realcase/README.md

3.3 KiB

riskgate-ea-realcase

Risk gate EA real world use case
MIT License


What is this?

riskgate-ea-realcase is a real-world example Expert Advisor that demonstrates how to integrate the @douglasrechia/riskgate-ea client framework into a working MQL5 EA.

The EA monitors multiple currency pairs (EURUSD, GBPUSD, AUDUSD, NZDUSD), groups them by correlation magic number, and on each new bar computes an ATR-based stop loss and requests position sizing approval from an external risk management server before placing a trade.

This project is intended only as an educational example of how to build a real-case EA on top of the riskgate-ea package using KnitPkg. It is not meant to be a production-grade trading system.

Prerequisites

To use this project, you will need:

  1. MetaTrader 5 installed.
  2. KnitPkg CLI: The KnitPkg package manager for MetaTrader. If you don't have it, you can install it by following the instructions in the main KnitPkg repository.
  3. KnitPkg homepage: See https://knitpkg.dev for an overview and https://docs.knitpkg.dev for documentation.
  4. A running RiskGate server (see @douglasrechia/riskgate-service-realcase) listening on 127.0.0.1:5555.

Installation

Download and build the latest stable version in a single command via the KnitPkg registry. If MetaTrader is installed in more than one location, first change to your MetaTrader Data Folder root:

cd "C:\Users\<username>\AppData\Roaming\MetaQuotes\Terminal\<TERMINAL_ID>"
kp get mql5 @douglasrechia/riskgate-ea-realcase

If needed, restart MetaTrader afterward to refresh the Navigator. Open a chart in the timeframe/symbol of your choice and double-click to start the EA at Expert Advisors/riskgate-ea-realcase/bin/RiskgateEaRealCase.


Features

  • Expert Advisor type (type: expert) — compiled and attached to MetaTrader charts
  • ATR-based risk — stop loss is computed as ATR(14) × 4 on each new bar
  • Correlation groups — EURUSD/GBPUSD share magic 1000; AUDUSD/NZDUSD share magic 1001
  • Server-gated entries — no trade is placed without approval from the RiskGate server
  • Graceful offline handling — logs an error and skips the trade if the server is unreachable
  • KnitPkg dependencies — uses @douglasrechia/riskgate-ea, @douglasrechia/calc, and @douglasrechia/bar

How it works

On every new bar the EA:

  1. Fetches the latest 20 bars via BarMqlRates.
  2. Computes risk = ATR(14) × 4.
  3. Sends a JSON payload to the RiskGate server:
    { "symbol": "EURUSD", "sl_points": 120, "magic": 1000 }
    
  4. If the server approves the request, opens a BUY order with the returned lot size, using risk as the stop loss distance and risk × 8 as the take profit distance.

License

This project is released under the MIT License. See LICENSE for details.


Disclaimer

This code is provided as-is, for educational purposes only.
No warranty (express or implied) is provided. Use at your own risk.