MT4 Plugin to make client get the different scenario outcome at Stop Loss (SL), Take Profit (TP), Pendings and StopOut orders execution.
Installation #
- You need to be sure that Visual C++ Redistributable for Visual Studio 2017 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.GapHelper/versions
Unpack and copy .dll file to your /plugins/ folder and restart MT4 server.
Demo version limitations
Without license program will proceed first only 100 requests. Than you will need to restart server to reset counter.
At any time you can purchase license for unlimited usage. Our contacts: http://cplugin.com/contact
Settings #
At very first time, if you don't have settings file, plugin starts normally and generates example settings file automatically.
Example of settings file below:
CPlugin.GapHelper.ini
enable=1
ticks counting mode=satisfied
comment order=1
dealer bypass SL=1
dealer bypass Pending=0
dealer bypass Stopout=1
ticks SL=3
ticks TP=3
ticks Pending=3
ticks Stopout=3
groups=!demo*,!test*,*
symbols=,forex,*XAU*,*XAG*,
stop loss mode=last
take profit mode=order
stop order mode=first
limit order mode=last
stopout mode=worst
news count=2
news time 1=2016/08/01 01:30 30
news time 2=fri 22:00 240
verbose=2
[v2.0+]
manager=10
debug symbols=EURUSD,Forex
ticks Open=3
ticks Close=3
open mode=worst
close mode=worst
enable
- 1/0 to enable/disable plugin globally.
ticks counting mode
- any of:
satisfied
- previous n-ticks, all satisfy requirement to fire order;following
- n-ticks after first price which activates order.
ticks SL
, ticks TP
, ticks Pending, ticks Open, ticks Close
- number of ticks needed to confirm SL / TP / Pending, Open and Close order respectively.
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*,GAG*, to work only for symbols under 'forex' security group and symbols containing XAU or XAG word.
stop loss mode, take profit mode, limit order mode, stopout mode, open mode, close mode
- parameters to manage order execution mode for Stop Loss, Take Profit, limit orders and Stopout orders respectively. Value can be one of:
first
- use first tick from ticks sequence;last
- use last tick from ticks sequence;best
- best quoted price based on the tick (numbers of tick count set) in the arrayfair-worst
- between the best price in the array, we will pick the worst among themworst
- use worst price from ticks sequence;trade
- use price set by client (useful for Stop Loss, Take Profit and Pending orders).
verbose
- choose logging verbosity:
- 0 - minimal logging, only errors and warning messages;
- 1 - general messages and configuration updates;
- 2 - most verbosity, for debugging of plugin.
comment order
- enable(1)/disable(0) a feature that will mark orders that are executed by plugin with prefix [gap], both clients and broker will see this comment.
dealer bypass SL
- enable(1)/disable(0) a feature that makes SL orders to be executed with first tick came from manager/dealer (instead of regular feed). Ticks counting feature will be bypasses, it means that there will have no need to confirm ticks sequence with multiple ticks in a row.
dealer bypass Pending
- enable(1)/disable(0) very same feature for Pending orders.
StopOut does not support all modes
'fair-worst' mode and will be switched to 'best'
'order' mode and will be switched to 'first'
'fair-worst' mode limitations
Whenever fair-worst mode failed looking for best price, if all following prices will be worse than set in order, it will select worst from them.
v2.0 feature : Virtual Dealer mode #
In this mode plugin capture market order attempts like dealer does and await required number of ticks until making a decision regarding price to be used, then it execute request in accordance to settings.
additional parameters in settings file: #
manager
- login of dealer (any manager account) on behalf of which plugin will act;
debug symbols
- MQ's mask where you can specify symbol names and security group names. It let you see price stream for selected symbols right in MT4 journal, for easier debugging of execution during preferable mode selection.
Ticks counting algorithms
- not taken into account and during market orders (Open or Close)
fair-worst
mode has no meaning for Open / Close orders as well and will get switched to the worst
mode.
It does not work with Automatic execution mode (groups->security), so please set up at least manual/auto mode to let plugin get callbacks from MT4 server.
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.
Notes regarding MT4 journal #
For example, when you enable verbosity to value of 2 in MT4 journal you will see messages like this:
Order #100 'buy stop' confirmed, open price updated from 100.02 to 103.02, 'worst' from: [101.02, 103.02, 102.02] |
Buy Stop order has been confirmed by plugin, price has been adjusted from 100.02
to value of 103.02
.worst
- describes algorithm that has been chosen to calculate execution price. [101.02, 103.02, 102.02]
- last n-ticks (configurable for each order type) sequence in order they came.100.02
- Buy Stop level was set by client to that value.
Examples #
Assume that 3 ticks needed to confirm Stop Loss, Take Profit and Pending order execution.
Buy trade, Take Profit will not fire #
TP: 100.00
Ticks:
1. 99.00
2. 98.00
3. 97.00
4. 96.00
5. 101.00 ← plugin will deny TP execution because tick 3 price is less than 100.00
6. 102.00 ← plugin will deny TP execution because tick 4 price is less than 100.00
7. 95.00 ← order remain open
Buy trade, Take Profit will fire #
TP: 100.00
Ticks:
1: 99.00
2: 98.00
3: 97.00
4: 96.00
5: 101.00 ← plugin will deny TP execution because tick 3 price is less than 100.00
6: 103.00 ← plugin will deny TP execution because tick 4 price is less than 100.00
7: 102.00 ← TP will fire at level 100.00, as it was set up by client
Buy trade, Stop Loss will not fire
SL: 100.00
Ticks:
1. 101.00
2. 102.00
3. 103.00
4. 104.00
5. 99.00 ← plugin will deny SL execution because tick 3 price is greater than 100.00
6. 98.00 ← plugin will deny SL execution because tick 4 price is greater than 100.00
7. 105.00 ← order remain open
Buy trade, Stop Loss will fire #
SL: 100.00
Ticks:
1. 101.00
2. 102.00
3. 103.00
4. 104.00
5. 99.00 ← plugin will deny SL execution because tick 3 price is greater than 100.00
6. 97.00 ← plugin will deny SL execution because tick 4 price is greater than 100.00
7. 98.00 ← SL will fire at level 98.00, last confirmed price
Buy Stop will not fire #
Price: 100.00
Ticks:
1. 96.00
2. 97.00
3. 98.00
4. 99.00
5. 101.00 ← plugin will deny executing BuyStop order because tick 3 price is less than 100.00
6. 102.00 ← plugin will deny executing BuyStop order because tick 4 price is less than 100.00
7. 95.00 ← order remain pending
Buy Stop will fire #
Price: 100.00
Ticks:
1. 96.00
2. 97.00
3. 98.00
4. 99.00
5. 101.00 ← plugin will deny executing BuyStop order because tick 3 price is less than 100.00
6. 103.00 ← plugin will deny executing BuyStop order because tick 4 price is less than 100.00
7. 102.00 ← order opened at price 102.00
Buy trade, Stop Loss will fire using tick thrown by dealer #
SL: 100.00
Assume that: dealer bypass SL=1
Ticks:
1. 101.00
2. 102.00
3. 103.00
4. 104.00
5. 99.00 ← this tick was thrown by manager. plugin will execute this order using price of 99.00
More complex example: Buy trade, Stop Loss will fire normally #
SL: 100.00
Assume that: dealer bypass SL=0
Ticks:
1. 104.00
2. 103.00
3. 102.00
4. 101.00
5. 99.00 ← this tick was thrown by (manager), plugin will deny SL execution because tick 3 price is greater than 100.00. Last 3 ticks sequence: 102.00 101.00 99.00
6. 100.5 ← tick from regular (feed), price is better than SL. Sequence interrupted
7. 98.90 ← (manager) plugin will deny SL execution because tick 6 price is greater than 100.00. Last 3 ticks sequence: 99.00 100.5 98.90
8. 100.4 ← (feed), price is better than SL. Sequence interrupted
7. 98.80 ← (manager) plugin will deny SL execution because tick 8 price is greater than 100.00. Last 3 ticks sequence: 98.90 100.4 98.80
7. 97.00 ← (manager) plugin will deny SL execution because tick 8 price is greater than 100.00. Last 3 ticks sequence: 100.4 98.80 97.00
8. 98.00 ← (manager) SL will be fired at level 98.00, last confirmed price from sequence: 98.80 97.00 98.00
If we set dealer bypass SL=1
than order be executed at price 99.00 when tick 5 comes.
Buy limit order fired #
Price: 100.00
Ticks:
1. 104.00
2. 103.00
3. 102.00
4. 101.00
5. 99.50
6. 100.50 ← plugin will deny executing Buy Limit order because tick 4 price is less than 100.00. Last 3 ticks sequence: 101.00 95.00 100.50
7. 102.50 ← plugin will deny executing Buy Limit order because tick 4 price is less than 100.00. Last 3 ticks sequence: 99.50 100.50 102.50
8. 101.50 ← order opened at price 101.50.Last 3 ticks sequence: 100.50 102.50 101.50
Buy trade, Stopout will not fire #
For instance, we have 'Buy' order opened, when price goes down under level of 100.00 MT4 will try to close it because margin level became critically low.
Ticks:
1. 101.00
2. 102.00
3. 103.00
4. 104.00
5. 99.00 ← plugin will deny Stopout execution because only one (99.00) of last three ticks were used to execute stopout order.
6. 98.00 ← plugin will deny Stopout execution because only two (99.00 and 98.00) of last three ticks were used to execute stopout order.
7. 105.00 ← order remain open. MT4 did not try to fire stopout order.
In MT4 journal you can notice messages like:
0 17:36:50.738 '1000': reach stopout ml 40.49%, equity: 158.45, margin: 391.29 ← MT4 noticed a moment for executing stopout
0 17:36:50.739 CPlugin.GapHelper Stopout skipped, last ticks: [1.11722, 1.11720, 1.10958], stopout prices: [1.10962, 1.10960, 1.10958] ← plugin prevents this, order remains open
Buy trade, Stopout will fire #
For instance, we have 'Buy' order opened, when price goes down under level of 100.00 MT4 will try to close it because margin level became critically low.
'Last' price algorithm has been used in this example.
Ticks:
1. 101.00
2. 102.00
3. 103.00
4. 104.00
5. 99.00 ← plugin will deny Stopout execution because only one (99.00) of last three ticks were used to execute stopout order.
6. 97.00 ← plugin will deny Stopout execution because only two (97.00) of last three ticks were used to execute stopout order.
7. 98.00 ← Stopout will fire at level 98.00, last confirmed price. All three ticks (99.00, 97.00 and 98.00) in a row were used by MT4 to execute stopout order.
All execution modes in one scheme. #
BUY, TP = 100 incoming ticks:102 first103 best101 fair-worst98 worst99 last | SELL, TP = 100 incoming ticks:98 first97 best99 fair-worst102 worst101 last | BUY STOP @ 100 incoming ticks:101 first97 best99 fair-worst102 worst98 last | SELL STOP @ 100 incoming ticks:99 first103 best101 fair-worst98 worst102 last |
BUY, SL = 100 incoming ticks:99 first102 best101 fair-worst97 worst98 last | SELL, SL = 100 incoming ticks:102 first98 best99 fair-worst103 worst101 last | BUY LIMIT @ 100 incoming ticks:101 first97 best99 fair-worst102 worst98 last | SELL LIMIT @ 100 incoming ticks:99 first103 best101 fair-worst98 worst102 last |
BUY, StopOut incoming ticks:99 first102 best97 worst98 last order => firstfair-worst => best | SELL, StopOut incoming ticks:102 first98 best103 worst101 last order => firstfair-worst => best |