This is a plugin for MetaQuotes MetaTrader 4. It dynamically changes leverage for a client depend on his open positions. Each instrument type has different calculations: forex, metals and indices.
You need to be sure that Visual C++ Redistributable for Visual Studio 2015, 2017 and 2019 has been already installed to the server.
Fully working time limited version can be downloaded from here: https://nuget.cplugin.com/feeds/apps/CPlugin.MT4Plugin.FlexibleLeverage
Download, unzip and copy CPlugin.FlexibleLeverage.dll file to your /plugins/ subfolder, then restart MT4 server.
Enabled - 1|0 to enable/disable plugin.
Managers - manager logins who permitted to change settings remotely, using MT4 telnet API.
Policy count - number of policies that will be defined below.
Description for each policy has format:
policy - numeric index starting from 0.
groupMask - mask of client group. It can be any MT4 standard mask, like: !demo, *
enabled - flag to enable|disable some band.
bandsCount - count of volume ranges that will be described below.
marginMode - proceed only specified margin calculation mode, a value from MT4 server API:
-1 - use
<securityGroup> parameter instead
0 - MARGIN_CALC_FOREX
1 - MARGIN_CALC_CFD
2 - MARGIN_CALC_FUTURES
3 - MARGIN_CALC_CFDINDEX (not supported yet)
4 - MARGIN_CALC_CFDLEVERAGE
securityGroup - restrict to security group index (MT4 admin → securities tab → row number). Set value -1 to disable such restriction.
Please note set both
<securityGroup> to the value of -1 simultaneously is forbidden.
One paramete must always be -1, second can have any other value.
Two parameters cannot be filled simultaneously.
verbose - verbosity of logging, a value of:
- 0 - silent mode
- 1 - fatal error
- 2 - error
- 3 - warning
- 4 - info
- 5 - trace, most verbosity output
calc mode - you can specify how each band size must be calculated, a value of:
- if none entered - the account's currency, the default mode;
- or any currency code can be entered like: USD or GBP
Each band should be defined using this format:
band - band index starting from 0.
volume - bottom line of volume. Suffixes like: k K m M b B can be used to specify thousands, millions and billions respectively.
leverage - leverage to be within this band. 100 means 1:100, etc.
For each band plugin uses minimal value between band's setting and actual user's leverage. So if user has leverage 1:200 and in band you put 1:500 plugin will use 1:200.
To provide leverage for rest volume you can set last line using format:
<leverage> So, you able to set leverage for volume that are higher than your previous line volume.
Bands use client's group currency.
Here and below, USD is just for example.
Policy = <all groups> <enabled> <4 bands below> <MARGIN_CALC_FOREX> <any security group> <very detailed output>
Policy Band=100k 100
For total volume up to 100k (of account's currency) plugin will calculate margin using leverage 1:100
Policy Band=1m 50
For next 900k (1m - 100k) up to 1m total position plugin will calculate margin using leverage 1:50
Policy Band=5m 33
For next 4m (5m - 1m) up to 5m total position plugin will calculate margin using leverage 1:33
Policy Band=10m 20
For next 5m (10m - 5m) up to 10m total position plugin will calculate margin using leverage 1:20
For any volume that are greater than 10m leverage will be 1:10
has same logic, but it will use USD for following bands description
Policy Band=10k 100
10k USD is a limit for first band
Flexible leverage model will automatically be adapted to clients trading positions and total USD volume they keep open. As the total open USD volume per Instrument of a client increases, the maximum leverage offered decreases accordingly.
Open Volume USD
|Maximum Leverage||Margin used|
|0 - 3m||Max 1:500||$6000 ($3m/500)|
|3m - 5m||Max 1:200||$10000 ($2m/200)|
|5m - 15m||Max 1:100||$100000 ($10m/100)|
|15m - 30m||Max 1:50||$300000 ($4m/50)|
|30m +||max 1:20|
Actual leverage for 30m is 1:72
Note where the account leverage is less the account leverage will be used instead.
The sum of the total positions volume in USD is calculated in the following way:
1 lot is 100000 units of the base currency (first currency) so we transform it in USD using the current applicable rate if required,
- 1 lot USDJPY = 100000 USD (no conversion needed)
- 1 lot EURUSD @ 1.1350= 113500 USD (multiply 100k by 1.1350)
- 2 lot EURJPY = 227000 USD (multiply 200k by 1.1350 EURUSD VALUE AT THE TIME OF OPENING)
- 30 lots USDCAD = 3000000 USD
Therefore total volume: 100000 + 113500 + 227000 +1000000 = 1440500 USD
Every time a new position is open the USD value of the new trades is added and the margin calculations are perform based on above table.
Note BUY or SELL direction is not affecting this. Hedge positions need NEW 100% margin
- Buy 15 lots USDJPY= 1500000 USD
- Sell 15 lots USDJPY= 1500000 USD
- But 10 lots USDCAD= 1000000 USD
Total volume 4000000 USD
Assuming the account has 1:500
First 3m are in first band 1:500 needs $6000
Extra 1 m are in second band 1:200 so needs another $5000
Total margin required 11000 USD
In the above example if account has 1:200
First 3m are in first band 1:500 but account leverage is 1:200 so overcomes needs 15000
Extra 1 m are in second band 1:200 same as account’s so 5000
Total margin required 20000 USD
Metals valued USD will be calculated separately on EACH metal any forex exposure will be ignored. For example, if a trader has 30 lots Buy on EURUSD, and then starts trading SILVER, his/her margin requirement for SILVER (FOREX), will not be affected by the existing FOREX positions. If client now choses opens GOLD is also not affected by the existing positions (SILVER and EURUSD) but if he opens new SILVER positions dynamic leverage rules starts to apply.
|Open Volume (USD)||Maximum Leverage||Margin used|
|0 - 250k Max||1:200 (0.5%)||1250 ($250k/200)|
|250k - 500k||Max 1:100 (1%)||2500 ($250k/100)|
|500k - 2m||Max 1:50 (2%)||30000 ($1.5m/50)|
|2m - 5m||Max 1:20 (5%)||150000 ($3m/20)|
|5m + Μax||1:10 (10%)|
GOLD price $1250
40 lots Gold at $1250 is $5000000 (125010040)
Used Margin is 183750 USD (table above)
Note BUY or SELL direction is not affecting this. Hedge positions need NEW extra 100% margin
INDICES margin are calculated per lot per single instrument. As the trading volume per Instrument of a client increases, the maximum leverage offered decreases accordingly; as per the following table.
|Open Lots||Margin Requirement|
|0-30||Standard Margin Per Instrument|
|30-50||Margin * 2|
|50-100||Margin * 5|
|100-200||Margin * 8|
|200||Margin * 10|
For INDICES this is done per Trading Instrument, so if a client has positions open across multiple indices Instruments, the leverage will be calculated separately on each Index instrument. For example, if a trader has a position in EURUSD and Gold, and wants to trade DAX his/her margin requirement for DAX will not be affected by any other existing trades, unless if the existing trades are DAX.
Note BUY or SELL direction is not affecting this. 1 Buy lot and 1 Sell lot equals 2 lots.
Hedge positions need NEW 100% margin
Client with USD account 1:500
OPEN 15 LOTS buy DAX (for 1 lot is 1000 USD)
Required margin is 15000 USD
Opens extra 20 lots Sell DAX. TOTAL lots 35 (15 Buy+ 20 Sell)
Required margin is 30000 USD for the first 30 lots (first band)
and the remaining 5 needs 10000 (510002 second band)
Total margin used 40000 USD
Client with USD account 1:500
Has open USDJPY 10 lots (1 million USD first band)
Required margin for this 2000 USD
Open 2 lot DAX (for 1 lot is 1000 USD)
Required margin for this 2000 USD
Total margin requirements 2000 + 2000 = 4000 USD
Now client opens 1 lot HSI (for 1 lot is 7000 USD)
Required margin for this 7000 USD
New Total margin requirements 4000+7000 = 11000 USD
Now client opens another 35lots of DAX (for 1 lot is 1000 USD)
Total DAX lots = 2(existing) + 35(new) = 37 lots
New Margin for the extra 35 DAX 281000 +71000*2
TOTAL for all trades
10 lots USDJPY = 2000 USD
2 lots DAX = 2000 USD
1 lots HIS = 7000 USD
35 lots DAX (new) = 42000 USD
Total: 53000 USD
Demo version limitations
Free demo version functionality is limited to first 100 trades to be processed. To continue testing you could restart your MT4 server. Contact us if you want to get unlimited license.