Skip to content
CPlugin logo
  • Home
  • Blog
  • Store
  • Contact
  • FAQ
  • Cart
  • My account
  • Knowledge Base
CPlugin logo
  • Home
  • Blog
  • Store
  • Contact
  • FAQ
  • Cart
  • My account
  • Knowledge Base

General

  • How to obtain files

MT4 ManagerAPI .NET Wrapper

  • Installation
  • Connection pool
  • Price Helper

Standalone Apps

  • Join two MT4 Servers
  • Compress MT4 database
  • Quotes Monitor
  • Quotes Monitor (WPF)
  • MT4 Report Server extended replication
  • EMIR
  • DividenderLT
  • Tools to calculate dividends
  • CopyTrading
    • Sentiment Strategy (LMAX)
    • MT4 (ManagerAPI) to LMAX
    • MT4 Plugin
    • MT4 (ManagerAPI) to MT4

Plugins for MT4/MT5

  • Flexible Leverage
  • GapHelper plugin
  • Multi Account Manager (MAM)
  • Spread Extender
  • HedgeHelper
  • Multi-Tier IB
  • Multi-Tier IB advanced version

Cloud

  • General info
  • WebAPI
    • WebAPI
    • Authorization
    • Pricing and terms
    • RESTful
    • Web Sockets (SignalR)
  • Home
  • Docs
  • Plugins for MT4/MT5
  • HedgeHelper

HedgeHelper

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.

Installation #

  1. You need to be sure that Visual C++ Redistributable for Visual Studio 2015 has been already installed to the server.
  2. 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 #

  1. forbid BuyStop / SellStop orders for opening new position that will be unhedged;
  2. 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

  1. if there are unhedged trade
    1. clear the StopLoss / TakeProfit on unhedged positions;
    2. open additional positions to make all unhedged positions fully hedged;
  2. 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.

  1. forbid client to close hedged position(-s)  (to make position become unhedged), if (predicted) free margin would be negative;
  2. forbid updating StopLoss / TakeProfit if possible free margin would be negative;

Margin calculation formulas are:

Mode Formula 
Forex 2 * lots_hedged * margin_hedged + lots_unhedged * (initial_margin > 0 ? initial_margin : contract_size) / margin_divider / leverage
CFD Leverage2 * lots_hedged * margin_hedged + lots_unhedged * (initial_margin > 0 ? initial_margin : contract_size * open_price) / margin_devider / leverage
CFD2 * lots_hedged * margin_hedged + lots_unhedged * (initial_margin > 0 ? initial_margin : contract_size * open_price) / margin_devider
CFD Index2 * lots_hedged * margin_hedged + lots_unhedged * (initial_margin > 0 ? initial_margin : contract_size * open_price * tick_price / tick_size) / margin_devider
Futures2 * lots_hedged * margin_hedged + lots_unhedged * maintenance * (percentage / 100)

Manage 'StopLoss' orders #

  1. forbid update of StopLoss level if after this trade getting closed unhedge margin get higher than current.
  2. forbid opening new positions if there is already same direction orders (as a result, allow opening new opposite direction positions)
    1. clear StopLoss on existing order (on the same symbol) when opening opposite position for hedging.

Settings #

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=1forbid stop orders=0hedge on stopout=0unhedge margin=1manage stoploss orders=0groups=*symbols=*news count=0news time 1=01/01/1970 00:00, 0add stop order=1SO with hedged=1verbose=2

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:

  1. <day>/<month>/<year> <hour>:<minute> <duration>
  2. <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 #

0   14:43:23.702    CPlugin.HedgeHelper '1003': XAUUSD buy 0.00, sell 1.00, hedged volume 0.00, unhedged volume 1.00, avg. 1.00000, hedged position 0.00, unhedged position 125157.00, total position 125157.00, margin hedged 0, contract size 100, margin divider 1.00, margin 1251.570   14:43:23.703    CPlugin.HedgeHelper '1003' close order 'buy' 1.00 lots of 'XAUUSD' forbidden because free margin will be: -705.57, equity: 546.000000, margin: 0.00, freeMargin: 546.00, newMargin: 1251.57
Still stuck? How can we help?

How can we help?

Updated on July 24, 2023
Spread ExtenderMulti-Tier IB

Powered by BetterDocs

Table of Contents
  • What is this
  • Installation
  • Detailed information about each part
    • Forbid Stop orders
    • Hedge on StopOut
    • Unhedge margin
    • Manage 'StopLoss' orders
  • Settings
    • News mode
    • MT4 Journal examples

Copyright © 2015  - 2025 CPlugin

Telegram Email EmailLinkedinFacebookTwitter

Powered by CPlugin