Page tree

Get started by adding some pages to this space. Create page.

Versions Compared


  • This line was added.
  • This line was removed.
  • Formatting was changed.

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 2017 (x86) has been already installed to the server.

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.


General settings

Enabled - 1|0 to enable/disable plugin.

Managers - manager logins who permitted to change settings remotely, using MT4 telnet API.

Policy settings

Policy count - number of policies that will be defined below.

Description for each policy has format:

Code Block
Policy[<policy>]=<groupMask> <enabled> <bandsCount> <marginMode> <securityGroup> <verbose> <calc mode>

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 - forbid all instruments type
3 - MARGIN_CALC_CFDINDEX (not supported yet)

securityGroup - security group index (MT4 admin → securities tab → row number). Set value -1 to disable such restriction.


Please note that you should not set both <marginMode> and <securityGroup> to the value of -1 simultaneously. Only one parameter could have the value of -1.

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: 

  • С - curreny, USD, default mode for older versions;
  • L - lots based. Suffixes like 'k', 'm', etc will not be supported to be specified within corresponding <volume> field.

Band settings

Each band should be defined using this format: 

Code Block
Policy[<policy>] Band[<band>]=<volume> <leverage>

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.



Code Block
Policy count=2
Policy[0]=* 1 5 0 -1 4
Policy[0] Band[0]=100k 100
Policy[0] Band[1]=1m 50
Policy[0] Band[2]=5m 33
Policy[0] Band[3]=10m 20
Policy[0] Band[4]=10
Policy[1]=test 1 2 1 -1 4
Policy[1] Band[0]=10k 100
Policy[1] Band[1]=100k 50
Policy[1] Band[2]=100b 20 
Policy[0] = <all groups> <enabled> <4 bands below> <MARGIN_CALC_FOREX> <any security group> <very detailed output>

Policy[0] Band[0]=100k 100
For total volume up to 100k plugin will calculate margin using leverage 1:100

Policy[0] Band[1]=1m 50
For next 900k (1m - 100k) up to 1m total position plugin will calculate margin using leverage 1:50

Policy[0] Band[2]=5m 33
For next 4m (5m - 1m) up to 5m total position plugin will calculate margin using leverage 1:33

Policy[0] Band[3]=10m 20
For next 5m (10m - 5m) up to 10m total position plugin will calculate margin using leverage 1:20

Policy[0] Band[4]=10
For any volume that are greater than 10m 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$6000 ($3m/500)
3m - 5mMax 1:200$10000 ($2m/200)
5m - 15mMax 1:100 $100000 ($10m/100)
15m - 30mMax 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,

For example:

  • 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 LeverageMargin used
0 - 250k Max1:200 (0.5%) 1250 ($250k/200)
250k - 500kMax 1:100 (1%)2500 ($250k/100)
500k - 2mMax 1:50 (2%) 30000 ($1.5m/50)
2m - 5mMax 1:20 (5%) 150000 ($3m/20)
5m + Μax1: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 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 affecting 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 server. Contact us if you want to get unlimited license.

Search this documentation


Popular Topics

Popular Labels

Featured Pages

Content by Label
cqllabel = "featured" and type = "page" and space = "FL"

Recently Updated Pages

Recently Updated