Net Dynamic Leverage
Overview
The Net Dynamic Leverage plugin is designed to automatically increase margin requirements during important macroeconomic events and news releases (the High Margin Requirement or HMR period). This helps brokers protect against client fraud (e.g., abuse of negative balance protection) during high market volatility without affecting positions opened before the HMR period activation.
Key Features:
- Web Interface for Configuration and Control (Brokerpilot) – The plugin can be configured through a web interface where you can also control its operation: enabling/disabling, modifying rules/thresholds/time intervals, monitoring account events.
- Fraud Protection – Increased margin requirements only for new positions opened during the HMR period
- Optional Old Position Handling – Rules can be configured to either account for positions opened before HMR or exclude them from calculations and only count new volume opened inside HMR (exception: lock unwinding)
- Time Periods – Precise HMR interval settings (day of week + start/end time, intraday intervals)
- Multi-tier Rules – Different leverage thresholds based on position volume (e.g., 0-5 lots: 1:200, 5-10 lots: 1:100)
- Netting and Hedging Mode Support – No restrictions on account type
- Smart Lock Handling – Flexible handling of hedged volume, including partial lock unwinding.
- New Net Volume Inside HMR – Ability to work only with new volume opened inside HMR with any configuration of previously opened positions.
- Optional Account Group Customization Processing – When enabled, the plugin takes into account symbol settings at the account group rules level, allowing different base margins/settings for different account groups.
- Optional Issues Sending to Brokerpilot UI – Option to send margin change events for display in UI (account card).
- Account Leverage Change Adaptation – Automatically tracks account leverage changes and recalculates margin coefficients to keep monetary margin unchanged.
- Optional HMR Leverage Limiting by Account Leverage – If the rule specifies leverage higher than the current account leverage, the plugin limits HMR leverage to account leverage. Only applies in "through leverage" calculation mode (not in percentage mode).
- Leverage Change for Fixed Leverage Symbols – Plugin allows changing margin requirements for symbols with fixed leverage (e.g., CFD).
- Tiered margin mode – Configurable strategies for calculating volume-based tier "ladder".
-
DirectTotal (one tier for entire volume)
- Plugin first selects one tier by
effectiveLotsvalue. - Then applies parameters of that tier to entire volume at once.
- In other words: "entire volume is calculated by one level".
- Plugin first selects one tier by
-
CumulativeMarginal (marginally by segments)
-
Plugin divides volume into parts by tier ranges (segments).
-
For each segment applies parameters of its tier, and the result is summed.
-
In other words: "first N lots — by one level, next ones — by next level, etc."
-
-
Plugin Deployment and Configuration on Trading Server (MT5)
1. Deployment
- Copy the plugin DLL to the MT5 trading server in the
Pluginsfolder. - Restart the MT5 server (or perform the server's plugin reload procedure) for the server to load the DLL.
2. Enabling and Configuration in Administrator Console
- Open MT5 Administrator → Plugins section.
- Add/enable the Net Dynamic Leverage (MT5) plugin.
- ⚠️ MANDATORY: Ensure the plugin is one of the first in the plugin list. Plugin execution order is critical for proper operation, as the plugin must process margin changes before other plugins.
- Configure plugin parameters in the administrator console UI (parameter list is provided below in the "Plugin Parameters" section).
- Apply changes.
See official MetaQuotes instruction for configuring MT5 plugins:
https://support.metaquotes.net/en/docs/mt5/api/serverapi_configure_plugin.
⚠️ IMPORTANT WARNING:
We do not guarantee proper plugin operation when third-party developer plugins that change account leverage or margin on open positions are installed on the server. Such plugins may conflict with Net Dynamic Leverage logic and lead to incorrect margin calculations.
Plugin Parameters (Global Settings)
| Parameter Name | Type | Default | Description |
|---|---|---|---|
| CheckAccountGroupRules | bool | false | Consider account group trading instrument customization rules |
| SendIssues | bool | true | Enables sending Issues (margin/leverage change events on positions) to Brokerpilot system for UI display (account card). In MT5 state is saved in ApiData (server memory). |
| Limit HMR By Account Leverage | bool | false | Limits HMR leverage by current account leverage only for LeverageParameter=Leverage. Not applied for Percentage. |
| TieredMarginCalcMode | string | DirectTotal | Tiered margin calculation mode: DirectTotal (one tier for entire volume) or CumulativeMarginal (marginally by segments). Last threshold is treated as LotsTo=+inf (for tier selection in both modes). |
| Use debug logs | bool | false | Enables detailed logging of all plugin operations for diagnostics and debugging. ⚠️ Attention: creates large volume of logs, use only for troubleshooting. |
| Check Account (0 = log all accounts) | int | 0 | Logging filter: 0 = log all accounts, N = log only account with Login=N. Useful for debugging specific account. |
Important (config):
TieredMarginCalcModeis parsed strictly (DirectTotal/CumulativeMarginal), otherwise plugin will not start and writes[STARTUP_CONFIG_ERROR].
Startup Errors due to Config ([STARTUP_CONFIG_ERROR])
If invalid TieredMarginCalcMode value is set in plugin parameters, plugin will not start.
- Where to look:
- plugin log (plugin's own log):
...\\logs\\Brokerpilot_netleverages\\daily_YYYY-MM-DD.txt(logsfolder is one level abovepluginsfolder where DLL resides)
- MT server log (message with
bp_netleveragesprefix)
- plugin log (plugin's own log):
- Example message:
[STARTUP_CONFIG_ERROR] Invalid TieredMarginCalcMode='...'. Allowed values: 'DirectTotal' | 'CumulativeMarginal'. Plugin will not start.
- How to fix:
- In plugin settings set:
TieredMarginCalcMode=DirectTotal(default)- or
TieredMarginCalcMode=CumulativeMarginal
- In plugin settings set:
Editing Rule Settings

Rules are created and edited in Brokerpilot web interface.
The plugin on the trading server stores its copy of the current rule configuration (periods, filters, thresholds) and applies it to trading events.
Main Rule Parameters

| Parameter Name | Description |
|---|---|
| RuleName | Unique name for the rule (e.g., "NFP Friday", "ECB News", "Weekend Protection"). |
| Enabled | Enable or disable the rule. Disabled rules are not applied to positions. |
| Account Groups | Specify account groups for rule application. You can include or exclude specific groups. |
| Accounts | Select individual accounts for rule application. Both included and excluded accounts can be specified. |
| Agents | Select agents (IB — Introducing Broker, introducing broker/partner) for rule application. IB attracts clients and receives commission. In MT5 each account is linked to IB through Agent field. You can filter accounts by IB membership or exclude them. |
| Symbol Groups | Specify instrument groups (e.g., "Forex", "Metals", "Crypto CFD") for rule application. |
| Symbols | Select specific instruments (e.g., "EURUSD", "XAUUSD") for rule application. |
| Active Accounts Only | Recommended: Enabled. If enabled, rule applies only to new positions opened inside HMR period. Old positions (opened before HMR) do not participate in Net Volume calculation. |
| Leverage Parameter | Method for specifying HMR leverage: "Leverage" — sets specific target leverage value (e.g., 1:200 means leverage 200) or "Percentage" — sets percentage of current account leverage (e.g., 50 means 50% of current leverage, i.e., reduction by 2 times). |
| Thresholds | Configure volume ranges and corresponding leverage values. Each threshold represents one level in the "leverage ladder". |
Threshold Configuration
Each threshold defines leverage level based on Net Volume range (net position volume):
| Parameter | Description |
|---|---|
| LotsFrom | Lower bound of Net Volume range in lots (inclusive). |
| LotsTo | Upper bound of Net Volume range in lots. Boundary inclusion depends on TieredMarginCalcMode strategy: for DirectTotal — not inclusive [LotsFrom, LotsTo), for CumulativeMarginal — inclusive [LotsFrom, LotsTo]. |
| Leverage | Target HMR leverage for this range (e.g., 200 for 1:200). Important: Lower value means higher margin requirements. |
| Percentage | Alternative parameter for "Percentage" mode (can be used for all symbol types). Set in percentage (e.g., 10 = 10% margin). Important: Lower value means higher margin requirements. |
| TimeFrom / TimeTo | Define HMR period: Day From / Time From → Day To / Time To (e.g., Friday 13:30 → Friday 15:00 for NFP). |
| Enabled | Enable or disable threshold. Disabled thresholds are not applied to positions. |
Configuration Example
Standard NFP (Non-Farm Payrolls) Configuration:
| Lots From | Lots To | HMR Leverage | HMR Period |
|---|---|---|---|
| 0.01 | 5.00 | 1:200 | Friday 13:30 - Friday 15:00 |
| 5.00 | 10.00 | 1:100 | Friday 13:30 - Friday 15:00 |
| 10.00 | 50.00 | 1:50 | Friday 13:30 - Friday 15:00 |
This creates a leverage ladder where HMR strengthens as position volume inside HMR period grows.
Weekend Protection Configuration Example:
| Lots From | Lots To | HMR Leverage | HMR Period |
|---|---|---|---|
| 0.01 | 100.00 | 1:100 | Friday 21:00 - Sunday 21:00 |
This applies fixed HMR leverage 1:100 to all new positions opened on weekends.
Note on thresholds:
LotsToupper boundary inclusion depends onTieredMarginCalcModestrategy:
- For
DirectTotal:LotsFrom <= volume < LotsTo(not inclusive)- For
CumulativeMarginal:LotsFrom <= volume <= LotsTo(inclusive)
Last threshold (last tier) is treated asLotsTo = +inf(no upper boundary):LotsFrom_last <= volume.
This affects tier selection in bothTieredMarginCalcMode=DirectTotalandTieredMarginCalcMode=CumulativeMarginalmodes (and inCumulativeMarginalalso affects segment construction).
Terms and Key Concepts
| Term | Description |
|---|---|
| HMR | High Margin Requirement - period of increased margin requirements |
| Net Volume | Net position volume by symbol (BUY sum minus SELL sum) |
| V_hmr | Volume of positions opened inside HMR period (HMR Net Volume) |
| V_out | Volume of positions opened outside HMR period (Outside Net Volume) |
| V_lock | Hedged volume (Hedged Volume) - pairs of opposite positions |
| InitialSnapshot (Zero Point) | "Zero point" - Net Volume at HMR period entry, used for tracking increase |
| K-coefficient | Transformation coefficient applied to margin_rate of all positions to achieve target margin |
| M_out | Margin for 1 lot outside HMR (base margin by current account leverage) |
| M_hmr | Margin for 1 lot inside HMR (margin considering HMR rule) |
| M_lock | Margin for 1 lot in lock, calculated as M_out × (MarginHedged / ContractSize) |
| OriginalMarginRate | Original position margin_rate (usually 1.0), saved in ApiData for restoration after HMR |
| OriginalAccountLeverage | Original account leverage at position opening, saved for correct recalculation on leverage change |
| IB (Introducing Broker) | Introducing broker/agent — broker partner who attracts clients and receives commission. In MT5 each account is linked to IB through Agent field (agent_account). Used for filtering accounts in rules. |
Plugin Logic
"Zero Point" Concept (InitialSnapshot)
Plugin uses "zero point" concept for precise tracking of volume increase inside HMR period:
1. HMR period entry (e.g., Friday 13:30):
├─ Current EURUSD Net Volume: +5.00 lots (5 BUY)
├─ Plugin saves InitialSnapshot = +5.00
└─ This is "zero point" - positions opened BEFORE HMR
2. Client opens new position inside HMR:
├─ Opens: Buy 2 lots EURUSD
├─ New Net Volume = +7.00
├─ Plugin calculates increase: 7.00 - 5.00 = +2.00 lots
└─ V_hmr = 2.00 (only new volume inside HMR)
3. Volume components calculation:
├─ V_hmr = 2.00 (new positions inside HMR)
├─ V_out = 5.00 (old positions outside HMR)
└─ V_lock = 0.00 (no locks)
4. K-coefficient calculation:
├─ M_out = 110 USD (1 lot with account leverage 1:1000)
├─ M_hmr = 550 USD (1 lot with HMR leverage 1:200)
├─ M_lock = 55 USD (1 lot in hedge, 50% of M_out)
├─ K = (V_hmr × M_hmr + V_out × M_out + V_lock × M_lock) / (Total Volume × M_out)
└─ K = (2 × 550 + 5 × 110 + 0 × 55) / (7 × 110) = 2.144
5. K-coefficient application:
└─ Plugin sets margin_rate = 2.144 for ALL EURUSD positions
Result:
- ✅ Old 5 lots get margin_rate = 2.144 (instead of 1.0)
- ✅ New 2 lots also get margin_rate = 2.144
- ✅ Total margin = 7 lots × 110 USD × 2.144 = 1650 USD
- ✅ Equivalent to: (5 lots × 110 USD) + (2 lots × 550 USD) = 550 + 1100 = 1650 USD ✅
Monitoring Process
Net Dynamic Leverage plugin continuously tracks positions and monitors the following server hooks:
HookTradeRequestAdd()
HookTradeRequestProcess()
3. Check on plugin startup
- Performed at MT5 Server start
- Restores margin_rate from
ApiDatafor all positions with saved state - Adjusts values if account leverage changed since last check
Decision Algorithm
For each tracked position plugin executes the following logic:
1. Rule compliance check:
├─ Does account belong to tracked groups/accounts/agents?
├─ Does symbol belong to tracked groups/symbols?
├─ Is rule enabled?
└─ Is HMR period active?
2. Time context determination:
├─ If time OUTSIDE HMR period:
│ └─ Action: RESTORE original margin_rate = 1.0
│
├─ If time INSIDE HMR period:
│ └─ Action: APPLY HMR (proceed to step 3)
│
└─ If HMR ENTRY moment:
└─ Action: SAVE InitialSnapshot (zero point)
3. Volume components calculation (if inside HMR):
├─ Determine account mode: Netting or Hedging
│ └─ isNettingGroup = (group->MarginMode() == MARGIN_MODE_RETAIL)
│
├─ Get current Net Volume
│ └─ In Netting: pos->Volume() (already net)
│ └─ In Hedging: CalculateNetVolume(allOrders)
│
├─ Get InitialSnapshot (if exists)
├─ V_hmr = CalculateVolumeIncrease(currentNet, zeroPoint)
├─ V_out = |currentNet| - V_hmr
└─ V_lock = (Netting: 0) | (Hedging: CalculateHedgedVolume(orders))
4. Applicable threshold search:
├─ Find threshold where: LotsFrom ≤ V_hmr < LotsTo (for DirectTotal) or LotsFrom ≤ V_hmr ≤ LotsTo (for CumulativeMarginal)
├─ If `TieredMarginCalcMode=DirectTotal` and V_hmr doesn't fit any threshold → consider we are **outside HMR** (rule not applied)
├─ If `TieredMarginCalcMode=DirectTotal` or `TieredMarginCalcMode=CumulativeMarginal` → last threshold treated as `LotsTo=+inf` (no upper boundary).
│ - In `CumulativeMarginal` tail is calculated by last tier (segments).
│ - In `DirectTotal` this affects tier selection when `effectiveLots > LotsTo_last`.
├─ If V_hmr below all boundaries → use minimum threshold
└─ If no thresholds → skip
5. Base margin requirements calculation:
├─ M_out = CalculateBaseMargin(symbol, accountLeverage, user)
├─ M_hmr = CalculateHMRMargin(symbol, hmrLeverage, user)
└─ M_lock = M_out × (margin_hedged / contract_size)
6. K-coefficient calculation:
├─ If only V_hmr (no V_out and V_lock):
│ └─ K = null (apply M_hmr directly to margin_rate)
├─ If mix of V_hmr + V_out + V_lock:
│ └─ K = (V_hmr×M_hmr + V_out×M_out + V_lock×M_lock) / (TotalVol×M_out)
└─ K is used as multiplier for margin_rate
7. Application and saving:
├─ For each position: pos->RateMargin(K or direct value)
├─ Save OriginalMarginRate in ApiData (if not saved yet)
├─ Save OriginalAccountLeverage in ApiData
└─ m_api->PositionUpdate(pos)
Lock Handling (Hedged Positions)
Plugin intelligently processes hedged positions (locks) considering hedging margin:
Example: Account with lock
├─ Buy 5 lots EURUSD (opened outside HMR)
├─ Sell 5 lots EURUSD (opened outside HMR)
└─ Net Volume = 0 (full lock)
Symbol settings:
├─ ContractSize = 100,000
├─ MarginHedged = 50,000 (50% of contract)
└─ Account leverage = 1:1000
Calculation:
├─ M_out = 110 USD (1 lot base margin)
├─ hedgeCoefficient = 50,000 / 100,000 = 0.5
├─ M_lock = 110 × 0.5 = 55 USD per 1 lot in lock
└─ V_lock = 5 lots (lock volume)
Result:
└─ Lock margin = 5 × 55 × margin_rate = 275 USD (instead of 550 USD without lock)
Lock unwinding inside HMR:
Continuing example:
├─ Client closes Sell 5 lots
├─ New Net Volume = +5.00 (Buy only)
├─ InitialSnapshot = 0.00 (was set at HMR entry)
├─ V_hmr = 5.00 - 0.00 = 5.00 ✅
Logic:
├─ Plugin treats unwinding as "Net Volume increase"
├─ V_hmr = 5.00 (entire volume now considered HMR)
├─ V_out = 0.00
├─ V_lock = 0.00
└─ HMR leverage applied to all 5 lots
Result:
├─ HMR Rule: 1:200 for 0-10 lots
├─ M_hmr = 550 USD
└─ Margin = 5 × 550 = 2750 USD (5 times more than lock!) ⚠️
Important: Lock unwinding inside HMR period significantly increases margin requirements. This is part of fraud protection.
margin_rate Restoration After HMR
When HMR period ends, plugin automatically restores original margin rates
Critical importance of OriginalAccountLeverage:
If account leverage was changed (e.g., by "Leverage by Equity" plugin) during HMR, plugin must account for this change during restoration, otherwise margin will be calculated incorrectly.
Interaction with Account Leverage Change (HookUserUpdate)
Plugin automatically tracks account leverage changes and adjusts margin_rate to preserve monetary margin:
Scenario: Leverage changed from 1:1000 to 1:500
1. HookUserUpdate() detects change
2. adjustmentRatio = 500 / 1000 = 0.5
3. For each position:
├─ currentMarginRate = 2.0
├─ newMarginRate = 2.0 × 0.5 = 1.0
└─ pos->RateMargin(1.0)
4. Update OriginalAccountLeverage = 500
Result:
├─ margin_rate reduced proportionally to leverage reduction
└─ Margin in USD remains unchanged ✅
Usage Examples
Example 1: NFP (Non-Farm Payrolls) Friday
Scenario: Broker wants to protect from fraud during US employment data release (first Friday of each month, 13:30 trading server time).
Configuration:
Rule: "NFP Protection"
Account Groups: "real-standard", "real-cent"
Symbols: EURUSD, GBPUSD, USDJPY, AUDUSD, USDCAD (majors)
ActiveAccountsOnly: Enabled
Thresholds:
0.01 - 5.00 lots: Leverage 1:200 (Friday 13:25 - 13:40)
5.00 - 10.00 lots: Leverage 1:100 (Friday 13:25 - 13:40)
10.00 - 50.00 lots: Leverage 1:50 (Friday 13:25 - 13:40)
Parameters:
TieredMarginCalcMode: DirectTotal
CheckAccountGroupRules: false
Results:
- ✅ 70% reduction in fraud trade losses
- ✅ Old positions (opened before 13:25) unaffected
- ✅ New positions get margin × 2.5-10 times (depending on volume)
- ✅ After 13:40 all margin_rate automatically restored
Example 2: ECB Announcement (European Central Bank)
Scenario: Protection from volatility during ECB interest rate decision announcement.
Configuration:
Rule: "ECB Rate Decision"
Symbols: EURUSD, EURJPY, EURGBP, EURCHF
ActiveAccountsOnly: Enabled
Thresholds:
0.01 - 10.00 lots: Leverage 1:300 (Thursday 12:40 - 14:00)
10.00 - 30.00 lots: Leverage 1:150 (Thursday 12:40 - 14:00)
30.00+ lots: Leverage 1:75 (Thursday 12:40 - 14:00)
Parameters:
TieredMarginCalcMode: DirectTotal
Results:
- ✅ 80% reduction in stop-outs during spikes
- ✅ Clients with existing positions can continue trading
- ✅ Broker protection from negative balances
Example 3: Weekend Protection
Scenario: Broker offers cryptocurrency and index trading on weekends, high volatility at market opening.
Configuration:
Rule: "Weekend High Margin"
Symbol Groups: "Crypto CFD", "Indices Weekend"
ActiveAccountsOnly: Enabled
Thresholds:
0.01 - 100.00 lots: Leverage 1:50 (Friday 21:00 - Sunday 21:00)
Parameters:
TieredMarginCalcMode: DirectTotal
CheckAccountGroupRules: true (different settings for VIP groups)
Results:
- ✅ 50% reduction in weekend losses
- ✅ Automatic HMR application all weekend
- ✅ VIP groups can have milder conditions (via Account Group Customization)
Best Practices
1. HMR Period Design
✅ Good practice: Time buffer
Event: NFP (13:30 trading server time)
HMR period: 13:25 - 13:40 (5 minutes before, 10 minutes after)
Reason:
├─ Clients may try to open positions at last minute
├─ Volatility often continues after release
└─ Time buffer reduces risk
❌ Bad practice: Exact time
HMR period: 13:30 - 13:31 (only 1 minute)
Problem: Volatility can last 5-15 minutes
2. Volume Threshold Settings
✅ Good practice: Gradual tightening
0-5 lots: 1:200 (moderate HMR)
5-10 lots: 1:100 (medium HMR)
10-30 lots: 1:50 (strict HMR)
30+ lots: 1:25 (very strict HMR)
❌ Bad practice: Sharp transitions
0-10 lots: 1:500 (almost normal)
10-11 lots: 1:50 (10x sharp jump!)
Problem: Client with 10 lots may get margin call when opening 11th
3. ActiveAccountsOnly Usage
Recommendation: enable ActiveAccountsOnly parameter
ActiveAccountsOnly: true ✅
Reasons:
├─ Protects clients' existing positions
└─ Applies HMR only to "fraud" positions (new during news)
Exceptions (when can be disabled):
ActiveAccountsOnly: false ❌ (only in special cases!)
Scenarios:
├─ Weekend protection (clients warned in advance)
├─ Emergency risk reduction (crisis situation)
└─ Testing (only on test accounts!)
4. TieredMarginCalcMode Configuration
TieredMarginCalcMode: DirectTotal # default, one tier for entire effectiveLots
TieredMarginCalcMode: CumulativeMarginal # cumulatively/marginally by segments, last tier = +inf
5. Recommended Implementation Phases
Phase 1: Demo testing (Days 1-7)
- Configure rules on demo accounts
- Simulate NFP/ECB events
- Check logs and calculations
Phase 2: Test group (Days 8-14)
- 5-10 real accounts with minimum balance
- Enable
Use debug logs = true - Monitor each event
Phase 3: Pilot (Days 15-30)
- 50-100 accounts
- Use CheckAccount for log focusing
- Gather client feedback
Phase 4: Production (Day 31+)
- Full rollout
Use debug logs = false(performance)- Continuous metrics monitoring
6. Monitoring and Audit
Key metrics:
1. Number of HMR applications per event
2. Average K-coefficient
3. Number of margin calls during HMR vs outside HMR
4. Client complaints
5. Stop-out losses (before/after HMR)
Logs for analysis:
7. Client Communication
✅ Mandatory information:
- Publication of HMR event schedule (economic news calendar)
- Email notifications 24 hours before event
- Pop-up warnings in terminal when trying to trade during HMR
- FAQ on website about HMR policy
❌ Don't do:
- Sudden HMR enabling without warning
- Rule changes during active HMR period
- Hiding HMR information
Frequently Asked Questions
Q1: Why did my old positions get HMR when ActiveAccountsOnly = true?
Answer:
If you unwound a lock inside HMR period, this is considered Net Volume increase and leads to HMR application. This is not a bug, but fraud protection.
Example:
Before HMR: Buy 5 + Sell 5 = Net 0 (lock)
Inside HMR: Close Sell 5
Result: Net = +5 → Plugin sees increase from 0 to 5 → HMR applied ✅
Solution:
If you want to avoid HMR, close locks BEFORE HMR period starts.
Q2: Why didn't plugin restore margin_rate after HMR?
Possible reasons:
-
Plugin was restarted during HMR:
- ApiData clears on server restart
- Solution: Plugin must be enabled permanently
-
Manual margin_rate change by dealer:
- Plugin doesn't restore manual changes
- Solution: Don't change margin_rate manually during HMR
Q3: What happens if client has open positions at HMR entry?
Answer:
If ActiveAccountsOnly = true (recommended):
1. Plugin saves InitialSnapshot = current Net Volume
2. Old positions DO NOT get HMR
3. Only NEW positions (opened after HMR entry) get HMR
4. K-coefficient calculated for correct margin distribution
If ActiveAccountsOnly = false:
1. ALL positions get HMR immediately
2. Margin increases for all positions
3. May cause margin calls for highly loaded clients
Technically:
- For threshold/ladder calculation entire symbol volume is taken: `effectiveLots = |net|` (not increase from ZeroPoint).
Q4: How does plugin work with Account Group Customization?
Answer:
If CheckAccountGroupRules = true, plugin uses symbol settings from account group configuration instead of global:
Example:
Global EURUSD settings:
├─ Initial Margin: 1.0
└─ Maintenance Margin: 1.0
"real-vip" group settings for EURUSD:
├─ Initial Margin: 0.5 (2 times less!)
└─ Maintenance Margin: 0.5
Result for VIP client:
├─ M_out = 55 USD (instead of 110 USD)
├─ M_hmr calculated from 55 USD
└─ VIP client gets "preferential" base margin ✅
Q5: How often does plugin check positions?
Answer:
Periodic check:
- Every 60 seconds for all open positions
Event-based check:
- Immediately on new position opening
- Immediately on position closing
- Immediately on modification
On server startup:
- Plugin restores all saved states from ApiData
Q6: Can I use different HMR rules for different symbols?
Yes, three methods:
- Separate rules for symbols:
Rule 1: "NFP Majors"
Symbols: EURUSD, GBPUSD, USDJPY
Leverage: 1:200
Rule 2: "NFP Minors"
Symbols: EURCHF, AUDNZD
Leverage: 1:300
- Symbol groups:
Rule: "NFP Forex"
Symbol Groups: "Forex Majors", "Forex Minors"
- Combination:
Rule: "NFP All"
Symbol Groups: "Forex"
Excluded symbols: USDTRY, USDZAR (exotic)
Q7: What to do if client complains about increased margin?
Solution steps:
- Check plugin logs:
Find records for this Login and Symbol:
- [CHECK] CheckSymbolOpenPositions
- [ACCUMULATOR] / [ACCUM_PRE_OPEN] InitialSnapshot (zero point) state
- [K_COEFFICIENT] Calculated K
- [UPDATE] / [LEVERAGE_ADJUST] / [HMR_LIMIT] margin rate changes (depends on scenario)
- Explain to client:
- HMR applied for protection from excessive risks
- Only new positions get HMR
- Broker policy (link to Terms & Conditions)
- Offer solutions:
- Close new positions before HMR ends
- Wait for HMR period end (margin_rate will restore)
- Avoid trading during news
- If exceptional case:
- Add account to Excluded accounts for rule
- Document exclusion reason
Q8: Is it safe to change rule settings during active HMR?
⚠️ NOT recommended!
What happens:
1. Plugin receives new configuration
2. Immediately applies new rules
3. Recalculates K-coefficient for all positions
4. May cause unexpected margin changes
Recommendation:
- Change settings ONLY outside HMR periods
- Test on demo before applying
- Plan changes in advance
Emergency cases:
If MUST change during HMR:
1. `Use debug logs = true`
2. CheckAccount = <specific login for test>
3. Monitor logs in real time
4. Be ready to rollback configuration
Permissions
Since this trigger requires our plugin to be installed on the trading server, all permissions are managed by the plugin and cannot be overridden.
📘 Example: Margin Calculations with Net Dynamic Leverage
This example demonstrates how margin requirements are calculated based on position volume and trigger-defined leverage rules.
🔧 Account & Symbol Setup
- Account Leverage: 1:1000
- Symbol: USDJPY
- Initial Margin Rate (BUY): 1.0
- Initial Margin Rate (SELL): 1.0
- Hedged Margin: 50,000 (per 1 lot)
- Contract Size: 100,000 (per 1 lot)
⚙️ Trigger Rule Settings
| Volume Range (lots) | Leverage |
|---|---|
| 0.01 – 2.00 | 100 |
| 2.01 – 15.00 | 10 |
▶️ Action Sequence & Margin Calculations
✅ 1. Open BUY 0.2 lot
- Calculation:
0.2 * 100,000 / 100 = 200 - Expected Margin: 200
- Actual Margin: ✅ 200
✅ 2. Open additional BUY 0.5 lot
- Total Volume: 0.2 + 0.5 = 0.7 lot
- Calculation:
0.7 * 100,000 / 100 = 700 - Expected Margin: 700
- Actual Margin: ✅ 700
✅ 3. Open SELL 0.3 lot
- Hedged Volume: 0.3 lot
- Net BUY Volume: 0.7 - 0.3 = 0.4 lot
- Calculation:
0.3 * 50,000 / 100 + 0.4 * 100,000 / 100 = 150 + 400 = 550 - Expected Margin: 550
- Actual Margin: 🔒 700 (Fact remains unchanged while margin decreases)
✅ 4. Open additional SELL 1.1 lot
- Total SELL Volume: 0.3 + 1.1 = 1.4 lot
- Total BUY Volume: 0.7 lot
- Hedged Volume: 0.7 lot
- Net SELL Volume: 1.4 - 0.7 = 0.7 lot
- Calculation:
0.7 * 50,000 / 100 + 0.7 * 100,000 / 100 = 350 + 700 = 1050 - Expected Margin: 1050
- Actual Margin: ✅ 1050
✅ 5. Close SELL 1.1 lot
- Remaining SELL Volume: 0.3 lot
- Net BUY Volume: 0.7 - 0.3 = 0.4 lot
- Calculation:
0.3 * 50,000 / 100 + 0.4 * 100,000 / 100 = 150 + 400 = 550 - Expected Margin: 550
- Actual Margin: ✅ 550
✅ 6. Close SELL 0.3 lot and Open BUY 1.3 lot (Total = 2 lots)
- Total BUY Volume: 0.2 + 0.5 + 1.3 = 2.0 lots
- Trigger edge case – leverage changes to 10
- Calculation:
2.0 * 100,000 / 10 = 20,000 - Expected Margin: 20,000
- Actual Margin: ✅ 20,000
✅ 7. Open SELL 0.1 lot
- Hedged Volume: 0.1 lot
- Net BUY Volume: 2.0 - 0.1 = 1.9 lot
- Leverage returns to 100 (volume < 2.01)
- Calculation:
0.1 * 50,000 / 100 + 1.9 * 100,000 / 100 = 50 + 1900 = 1950 - Expected Margin: 1950
- Actual Margin: ✅ 1950
📌 Notes
- Margin is calculated dynamically based on net exposure and the applicable leverage from the volume range.
- Hedged positions use a reduced margin based on the hedged margin value.
- Leverage rules are applied at the moment the volume threshold is crossed.
Conclusion
Net Dynamic Leverage plugin is a powerful tool for broker protection from fraud operations and excessive risks during high volatility:
✅ Protects broker from negative balance protection abuse
✅ Preserves client positions opened before HMR (ActiveAccountsOnly)
✅ Flexible configuration for various events and instruments
✅ Smart lock handling with hedged margin settings
✅ Automatic restoration of margin_rate after HMR
✅ Detailed logging for audit and troubleshooting
Recommended implementation path:
- Study existing configurations and examples
- Define events for HMR (NFP, ECB, FOMC, etc.)
- Develop rules considering your client base
- Test on demo and test group (2-4 weeks)
- Gradual rollout to production with monitoring
- Inform clients about HMR policy
- Monitor effectiveness and adjust settings
Critical parameters to check:
✅ ActiveAccountsOnly = true (existing position protection)
✅ SendIssues = true (Issues displayed in Brokerpilot account card UI)
✅ TieredMarginCalcMode (DirectTotal / CumulativeMarginal)
✅ Time periods (time buffer before/after event)
✅ Volume thresholds (gradual tightening, avoid sharp jumps)
Support: For questions or problems contact Brokerpilot support or enable Use debug logs = true for detailed diagnostics.