-->

Expert Advisors • Indicators • Scripts • Libraries

MQL.RobotFX.org is the biggest collection of MetaTrader expert advisors (MT5 & MT4), indicators, scripts and libraries that can be used to improve trading results, minimize risks or simply automate trading tasks

Metatrader 5 Expert Advisor | RiskManagement kit | Trading Tool Update

New free code from MQL5: indicators, EAs, and scripts for traders.

RiskManagementKit.mq5 is an MQL5 Expert Advisor (EA) for risk control and position management. It is not a signal generator and it does not open trades by strategy logic. The EA is designed to run on any symbol and any timeframe as a protective layer for manual trading or other entry systems.




Program structure (MQL5):

Event handlers: OnInit(), OnTick()
Main class: CRiskManagementKit
Core methods: StartOfDay(), RefreshDayState(), CheckDailyLock(), CalcLotSizeByRisk(), ApplyBreakEven(), RoundVolume()


What the EA does on each tick (OnTick):

Refreshes daily state using TimeCurrent(), TimeToStruct(), StructToTime().
Checks daily equity lock using AccountInfoDouble(ACCOUNT_EQUITY).
If not locked, applies break-even logic to open positions.
Calculates recommended lot size from risk settings.
Shows current status on chart using Comment().


Risk Based Calculation:


Uses AccountInfoDouble(ACCOUNT_BALANCE), SymbolInfoDouble(SYMBOL_TRADE_TICK_VALUE), SymbolInfoDouble(SYMBOL_TRADE_TICK_SIZE), and SymbolInfoDouble(SYMBOL_POINT).
Normalizes volume to broker constraints with SymbolInfoDouble(SYMBOL_VOLUME_MIN), SYMBOL_VOLUME_MAX, SYMBOL_VOLUME_STEP.
Returns normalized lot size from CalcLotSizeByRisk().


Daily Lock system/logic:


Stores day-start equity and monitors intraday equity change in percent.
If equity change <= -InpDailyLossLimitPercent or >= InpDailyProfitTargetPercent, trading state is locked for the day.
State is reset at new day boundary.


Break-even logic:


Scans positions with PositionsTotal(), PositionGetTicket(), PositionSelectByTicket().
Reads position data with PositionGetDouble()/PositionGetInteger()/PositionGetString().
For BUY/SELL positions on current chart symbol, when floating profit in points reaches InpBreakEvenTriggerPoints, modifies SL to break-even +/- InpBreakEvenBufferPoints using CTrade::PositionModify().



External input parameters:

input double InpRiskPercent
input int InpStopLossPoints
input bool InpEnableDailyLock
input double InpDailyLossLimitPercent
input double InpDailyProfitTargetPercent
input bool InpEnableBreakEven
input int InpBreakEvenTriggerPoints
input int InpBreakEvenBufferPoints


Recommended usage:
Attach EA to the symbol you want to manage. It provides risk sizing and protective management only; entry and exit strategy rules are expected to be handled separately.

Note: This EA does not open positions automatically; it is intended for risk control and position management only.



Trade Renko charts automatically using the advanced Renko Expert Advisors. Clean trends, better entries. Discover them here.

Build better strategies with RobotFX professional tools – check them out.

69586

Best MetaTrader Indicators + Profitable Expert Advisors