# Expert Advisor riskgate-ea-example **Risk gate EA example** *MIT License* --- ## What is this? `riskgate-ea-example` is a minimal **Expert Advisor** that demonstrates how to integrate the [`@douglasrechia/riskgate-ea`](https://forge.mql5.io/DouglasRechia/riskgate-ea) client into an EA. On every signal, the EA asks an external risk management server for approval and position size before placing any order. This project is intended **only as an educational example** of how to use the `riskgate-ea` package. It is **not** meant to be a production-ready trading system. ## Prerequisites To use this project, you will need: 1. [**MetaTrader 5**](https://www.mql5.com/) 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](https://github.com/knitpkg-dev/knitpkg-mt.git). 3. A running **RiskGate server** (provided by [`@douglasrechia/riskgate`](https://forge.mql5.io/DouglasRechia/riskgate)) listening on `127.0.0.1:5555`. **KnitPkg homepage**: See [https://knitpkg.dev](https://knitpkg.dev) for an overview and [https://docs.knitpkg.dev](https://docs.knitpkg.dev) for documentation. --- ## Features - **Expert Advisor type** (`type: expert`) — ready to attach to a MetaTrader 5 chart - **MQL5 target** — designed for MetaTrader 5 - **Risk gate integration** — requests position size approval from an external server before acting on a signal - **JSON communication** — sends signal data (symbol, side, stop loss) and reads back approval, lot size, and rejection reason --- ## Getting started ### 1) Clone into MetaTrader `Experts` folder ```bash # Go to your MetaTrader 'Experts' directory. # Tip: in MetaEditor, right-click the `Experts` folder and choose "Open Folder". cd "C:\Users\username\AppData\Roaming\MetaQuotes\Terminal\\MQL5\Experts" git clone https://forge.mql5.io/DouglasRechia/riskgate-ea-example.git cd riskgate-ea-example ``` ### 2) Install dependencies ```bash kp install ``` ### 3) Compile ```bash kp compile ``` ### 4) Run the EA 1. Restart MetaTrader so the Navigator refreshes. 2. Attach the compiled EA to any chart. 3. Make sure the RiskGate server is running on `127.0.0.1:5555`. 4. Check the MetaTrader console (Experts tab) for approval responses. --- ## How it works On every 30th tick, the EA builds a JSON signal and calls `RequestPositionSize`: ```mql5 CJAVal signal, response; signal["symbol"] = _Symbol; signal["side"] = "BUY"; signal["stop_loss"] = 12.34; bool online = client.RequestPositionSize(signal, response); Print("approved: ", response["approved"].ToBool(), " lot: ", response["lot"].ToDbl(), " reason: ", response["reason"].ToStr()); ``` If the server is offline, the EA logs an error and skips the order. --- ## 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.