MQLArticles/RM/README.md
2026-09-06 11:15:27 -05:00

52 lines
1.5 KiB
Markdown

[← MQLArticles](../README.md)
# RM
Risk management library: position sizing, SL/TP calculation, OCO orders and account-level loss/profit limits.
## Main features
- Lot size and SL/TP calculation based on account risk (`CRiskManagemet`).
- Personal and prop-firm risk profiles (`CRiskManagemetPersonal`, `CRiskManagemetPropFirm`).
- Max loss / max profit limits (daily, weekly, monthly, since peak) with automatic position closing — see [LossProfit](./LossProfit/README.md) for the full inheritance model.
- OCO (one-cancels-other) order linking.
- Per-account order/position tracking (`COrderGestor`, `CTicketsTable`).
## Basic usage
### Risk management
```mql5
CRiskManagemet rm;
// Note: "rm" requires the lot, type, max profit and max loss to be reset (etc.)
// before calling functions like GetSL, GetLote, etc.
// Check if a limit was hit
if(g_loss_profit_manager.MaxLossIsSuperated())
{
risk.CloseAllPositions();
CanTrade = false;
}
// Lot size
double entry_price = 1000.0;
double l = risk.GetLote(ORDER_TYPE_BUY, entry_price, 100, 0);
// Stop loss
long sl = risk.GetSL(ORDER_TYPE_BUY, entry_price, 100, 0);
// And more: GetPositionsTotal, SetStopLoss, CloseAllOrders, GetPositions...
```
### OCO order
```mql5
COcoOrder oco;
void Function()
{
unsigned long ticket1 = trade.ResultOrder();
unsigned long ticket2 = trade.ResultOrder();
oco.AddOrders(ticket1, ticket2);
}
```
> Only the most representative classes are shown here. See [LossProfit/README.md](./LossProfit/README.md) for the max loss/profit inheritance structure.