What is this #
This is a plugin for MT4 to adjust its logic to manage StopOut execution with automatic hedging. In addition it manage StopLoss / TakeProfit orders to avoid clients go negative free margin if order get executed.
- You need to be sure that Visual C++ Redistributable for Visual Studio 2015 has been already installed to the server.
- Fully working time limited version can be downloaded from here: http://nuget.cplugin.com/feeds/apps/CPlugin.MT4Plugin.HedgeHelper/versions
Unpack and copy .dll file to your /plugins/ folder and restart MT4 server.
Demo version limitations
Without license program will proceed only first 100 requests. Than you will need to restart server to reset counter.
At any time you can purchase license for unlimited usage. Our contacts: https://cplugin.com/contact/
Important to know
Plugin needs "Manual only" execution mode set up on security group you are going to use with plugin.
Further more, "StopOut" automation in dealer's terminal might cancel plugin's logic and bypass its responses to avoid closing orders on stop out. You have to disable this automation if you have it enabled.
Detailed information about each part #
Forbid Stop orders #
- forbid BuyStop / SellStop orders for opening new position that will be unhedged;
- allow BuyStop / SellStop that will hedge other positions (which maximum volume limited to unhedged volume).
simply saying, here we forbid client to increase his unhedged position using BuyStop / SellStop.
Only hedging (making unhedged volume get lesser) allowed.
Hedge on StopOut #
Interrupt attempts made by MT4 to close clients’ positions when StopOut happened
- if there are unhedged trade
- clear the StopLoss / TakeProfit on unhedged positions;
- open additional positions to make all unhedged positions fully hedged;
- if all trades already hedged then close most unprofitable hedged position.
Be aware entering right settings
If you have enabled dealers' automation be sure that it will not intercept StopOut orders before plugin.
So, un-tick Stop Out field.
Unhedge margin #
Here we calculate possible free margin if any order get executed.
- forbid client to close hedged position(-s) (to make position become unhedged), if (predicted) free margin would be negative;
- forbid updating StopLoss / TakeProfit if possible free margin would be negative;
Margin calculation formulas are:
|Forex||2 * lots_hedged * margin_hedged + lots_unhedged * (initial_margin > 0 ? initial_margin : contract_size) / margin_divider / leverage|
|CFD Leverage||2 * lots_hedged * margin_hedged + lots_unhedged * (initial_margin > 0 ? initial_margin : contract_size * open_price) / margin_devider / leverage|
|CFD||2 * lots_hedged * margin_hedged + lots_unhedged * (initial_margin > 0 ? initial_margin : contract_size * open_price) / margin_devider|
|CFD Index||2 * lots_hedged * margin_hedged + lots_unhedged * (initial_margin > 0 ? initial_margin : contract_size * open_price * tick_price / tick_size) / margin_devider|
|Futures||2 * lots_hedged * margin_hedged + lots_unhedged * maintenance * (percentage / 100)|
Manage 'StopLoss' orders #
- forbid update of StopLoss level if after this trade getting closed unhedge margin get higher than current.
- forbid opening new positions if there is already same direction orders (as a result, allow opening new opposite direction positions)
- clear StopLoss on existing order (on the same symbol) when opening opposite position for hedging.
At very first time, if you don't have settings file, plugin starts normally and generates example settings file automatically.
After restarting MT4 you will notice plugin and its settings
enable - 1|0 to enable|disable plugin entirely.
forbid stop orders - 1|0 to enable|disable blocking of Stop orders routine if client does not have open positions.
hedge on stopout - 1|0 to enable|disable automatic hedge positions routine when stop out happen.
unhedge margin - 1|0 to enable|disable unhedge blocking routine, to avoid client's free margin go negative value as a possible result.
forbid stop orders - 1|0 to enable|disable managing of StopLoss routines.
groups - groups filter, standard format used, like
,!demo*,*, to exclude *demo* groups.
symbols - symbols filter. Even security name can be used as well. For example: ,forex,*XAU*,XAG*, to work only for symbols under 'forex' security group and symbols containing XAU or XAG word.
news count - count of new records below.
news time <n> - news period definition.
verbose - verbosity of logging:
- 0 - minimal logging, only errors and warning messages
- 1 - general messages and configuration updates
- 2 - most verbosity, for debugging of plugin
News mode #
If none of news time has been set up plugin will work all the time. Or it will work only during those periods.
news count - number of news that will be defined below
news time <news index>=<news value> - each news period should use this form.
news index - index of record, counting from 1.
news value - can be one of these format:
<day>/<month>/<year> <hour>:<minute> <duration>
<day of week> <hour>:<minute> <duration>
Use first format if you want to set exact date and time.
If you want to repeat every week chose second variant.
<duration> - how long (in minutes) plugin should work.
MT4 Journal examples #