This is a plugin for MetaQuotes MetaTrader 4/5. It dynamically changes leverage for a client depend on his open positions. Each instrument type has different calculations: forex, metals and indices.

Configuration through Web UI

Recently, we run out of standard MT4/5 plugin's settings management to the very own Web-based UI portal. It is because MT4/5 has limitation of number of parameters that it can handle, to store near to infinite number of settings it needs to store it outside MT4/5 platform.

To manage it, it needs external application. The plugin has simple API (described below) to communicate with external UI using Manager API.

  1. Download, unpack and copy DLL to platform's Plugins folder,
    1. restart platform
    2. ensure it get loaded by checking logs
    3. add instance of this plugin to MT5 (in MT4 it will be listed automatically)
  2. Have a look to Cloud based web solutions to get general idea
  3. Register your company at Admin portal and change its name from default one
    1. Add your MT4/5 servers to the TradePlatforms section
    2. Ensure it gets connected: ()
  4. Navigate to and check TradePlatforms section
    1. activate () your platform to let system get connected ()
    2. search for plugin instance that it should discover automatically after being connected

Latest plugin version without GUI:

  1. Flexible Leverage (GUI-less version page from history) documentation
  2. MT4 version :
  3. MT5 version :


You need ensure that Visual C++ Redistributable for Visual Studio 2015, 2017 and 2019 is installed to the server.

A fully working time-limited version can be downloaded from here:
Download, unzip and copy CPlugin.FlexibleLeverage.dll file to your /plugins/ subfolder, then restart MT4 server.

MT5 version can be downloaded from

Download and unzip it after, you will get .dll file with short documentation, settings example and version history.

Plugin settings

Managers - manager logins who permitted to change settings remotely, using MT4/5 Telnet API / Manager API.

GUID⁣ – unique identifier to let automatic discovery run. Please do not change it, its value automatically generated when plugin started for very first time.

Settings through UI

verbose - verbosity of logging, a value of:

  • silence
  • fatal error
  • error
  • warning
  • info
  • trace – most verbosity output, best to be used during initial set up/testing.

If you use old plugin version: In MT5, maximum setting rows is 128. In that case, it suggested separating complicates settings to multiple plugin instances.

Very imporant

After MT4 FL v1.26+ and MT5 FL v1.16 there is no more ability to manage settings from MT4/5 Admin, because there is a (platform's) limit of rows specified, it limited number of policies you can specify, so customers complained about that limit and only the way was to switch for external storage of settings, outside of MT4/5 platform.

So now the limit is 1024 policies. If you still need more – contact us.

To manage settings from any remote system (custom GUI) plugin has its own API built on top of ManagerAPI, ExternalCommand in MT4 and CustomCommand in MT5.

To send anything to plugin, you have to follow a generic type of payload test:


Always use ANSI code page.

Square brackets mean optional data.

ID – unique identifier of plugin which can be found in plugin settings, when it starts it generate unique value.

CMD has a value of {​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​ get, set, discovery }​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​

payload - pure json data as is.

Each call to plugin, when plugin accept it (ID if valid, data validated) will return value of format shown below:

{​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​ ​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​"success": true|false,  "description" : "any text or null", "payload": "JSON structure" }​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​


Get settings

Request current settings from server.

Request example:


Will return current plugin settings

Response example is:

  "success": true,
  "description": "any meaningful text, especially during failure",
  "payload": {​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​
    "enabled": true,  - here and below - data from plugin settings file as is
    "verbose": 5,
    "policies": [
          <policy definition>

Set settings

Push settings back to server.

Request example

Response will be like this:

Response example
{​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​"success": true|false, "description" : "any text or null"}​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​

Discovery mechanism

To get all known plugin form server there is magic packet to be sent to MT4/5 server and if plugin not in list of specified IDs, it will reply. So, we can one by one collect information about all plugins (which supported that featue) installed on server.

Discovery request body format

Square brackets means that argiment is optional. So, once you send only keyword discovery for very first time it wil reply:

Disovery response example

which has format of:


So, step by step:

  1. send 'discovery' keyword and check response.
    1. check ResultCode of ExternalCommand in MT4 and CustomCommand in MT5 call
      1. OK - means that we get reply from plugin
      2. not OK - stop, no mo plugin will reply
    2. parse response, store ID
  2. send discovery request with known ID like a: discovery;{​​​​guid1}​​​​​​​​​​​
    1. check ResultCode of ExternalCommand in MT4 and CustomCommand in MT5 call
      1. OK - means that we get reply from plugin
      2. not OK - stop, no mo plugin will reply
    2. parse response, store ID
  3. send discovery request with known ID like a: discovery;{​​​​guid1}​​​​​​​​​​​;{guid2} etc until it return not OK result code


Each policy declare:

groups - masks of groups, separated by comma. example: !demo,*

enabled - flag to enable(1) or disable(0) that policy.

marginMode - proceed only specified margin calculation mode, a value from MT4 server API:

disabled - use <securitiesMasks> parameter instead
3 - MARGIN_CALC_CFDINDEX (not supported yet)

securities - masks of securities (MT4 admin → securities tab). Empty value - disables such restriction.

<marginMode> and <securitiesMasks> is third priority search filter.

Policy search routine

In other words, policy search routine is logical operation:

<logins> OR <symbols> OR <security group>

OR - logical OR operation, means that if parameter is TRUE, whole expression is TRUE.

Policy Bands

Currency - 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

Bands Type = percent | leverage

By default, if Bands Type not specified, leverage will be used (back compatibility with old settings file and plugin version)
Having percent means that you set band values in percentage (1 = 1%). Plugin then will ignore MT4 symbol's percentage value and use value from plugin settings instead.

Policy search by logins

This is very first and highest priority search filter.

<logins mask> can have list of logins and masks separated by comma like: 1000,2000*,!20005

Policy search by symbols

Second priority search filter.

<symbols mask> can have list of symbols and masks separated by comma like: !EUR*,*USD*

If any symbol name passed by this mask, then securitiesMasks filter will be skipped from being checked, does not matter what mask specified there.

Policy band settings

Each band has:
limit - bottom line of volume (specified in currency).
value - leverage|percentage to be within this band. 100 means 1:100, 1 = 1%, respectively.

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.

"Reject after NOP" feature

Plugin can reject further attempts to open more orders after getting over total net open position.

Clients will get 'Too Many Orders' erorr in their trade terminal. Limit orders will be deleted with comment 'deleted[NOP Achieved]'.

<verbosity> - from silence till verbosity output to journal.

<group mask and/or logins/mask> - you can specify masks of groups and logins separated by comma (spaces not allowed). Example: 5000*,!50001,real* 100k 1 EUR

<NOP> - net open position.

<enable> - flag to enable(1) or disable(0) that rule.

<currency> - optional field to specify currency we assume secified in <NOP> field.

"Recalc margin rates" feature

Recalculate margin rates after symbol settings change.

<now> - request plugin to recalculate rates as soon as possible. When plugin done with recalculations, it will reset this parameter back to off. You should monitor this parameter (GUI will not fetch updates until you explicitly request it). Once it set back to off, you need to restart MTx platform, to apply those rates. Without restart - MT4 will not take into consideration any changes made by plugin.

<monitor> - monitor symbol settings update, when found - it will run recalculate feature.

<SO disable> - Forbid executing of StopOut if so. To be disabled manually after process done!

<logins masks> - list of logins to work with. (better to specify to reduce running time).

<groups masks> - list of masks of groups separated by comma. (better to specify to reduce running time).


for all groups starting from 'demo', symbols that use 'forex' margin calculation formula, accounts with login started from 1000 and 2000 use two bands: until 100k USD leverage will be 1:50, for rest volume leverage will be 1:10.


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 LeverageMargin used
0 - 3mMax 1:500$6,000 ($3m/500)
3m - 5mMax 1:200$10,000 ($2m/200)
5m - 15mMax 1:100 $100,000 ($10m/100)
15m - 30mMax 1:50 $300,000 ($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,

For example:

  • 1 lot USDJPY = 100k USD (no conversion needed)
  • 1 lot EURUSD @ 1.1350= 113500 USD (multiply 100k by 1.1350)
  • 2 lot EURJPY = 227k USD (multiply 200k by 1.1350 EURUSD VALUE AT THE TIME OF OPENING)
  • 30 lots USDCAD = 3m USD

Therefore total volume: 100000 + 113500 + 227000 +3,000,000 = 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= 1.5m USD
  • Sell 15 lots USDJPY= 1.5m USD
  • But 10 lots USDCAD= 1m USD

Total volume 4m 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 LeverageMargin used
0 - 250k Max1:200 (0.5%) 1,250 ($250k/200)
250k - 500kMax 1:100 (1%)2,500 ($250k/100)
500k - 2mMax 1:50 (2%) 30,000 ($1.5m/50)
2m - 5mMax 1:20 (5%) 150,000 ($3m/20)
5m + Μax1:10 (10%)

GOLD price $1250

40 lots Gold at $1250 is $5m (125010040)
Used Margin is 183,750 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 LotsMargin Requirement
0-30Standard Margin Per Instrument
30-50Margin * 2
50-100Margin * 5
100-200Margin * 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 impacting this. 1 Buy lot and 1 Sell lot equals 2 lots.
Hedge positions need NEW 100% margin.

Example 1:

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

Example 2:

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
42000 USD
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/5 server. Contact us to purchase full license.

Search this documentation

Popular Topics

Featured Pages

There is no content with the specified labels

Recently Updated Pages