Risk % of Free Margin - sometimes calculates incorrectly
-
Hi,
I am currently testing my ea on live account and for one of the weekly currency pairs (USDCHF) it has twice now set the SL at twice the range than it should have but the TP was correct.
Interestingly, the TP is set as a % of SL, so it know what SL should have been used but got it wrong regardless.
This happened twice when the markets reopened - the ea is programmed to check once per weekly bar and if signal is present open one trade at 5pips SL (50 for 5-decimal account) and a 6.4pip TP (130% of SL to be precise).
On another instance, a USDCHF weekly trade was correctly placed with a 5pip SL and a 6.4pip TP - I cannot tell why sometimes it does correctly and sometimes it does incorrectly.
The risk is set as 1% of free margin, so the two times it set double the SL it lost roughly 2% of my free margin instead of the cap that I wanted of 1%.
I have this ea running on multiple time frames and currencies and only the USDCHF seems to be making this error and only on the weekly time frame.
The only explanation I have (and I've double and triple checked the blocks) is that the slippage causes the failed trade to close a whole additional 5pips in the red which then gets recorded as a 10pip SL when in reality it was set at 5 pips.
Does anyone know if MT4 records a close triggered by a SL at the value after slippage or before?
All three USDCHF SL triggers happened during the night after market open (I live in Sydney Australia).
Unless slippage is that fast that USDCHF can move past a 5pip SL to a 10pip SL, then I don't know why it got the SL wrong those two times.
Sam
P.s. I'm happy to share my ea and it's been profitable all up just a bit scary when it blows 2% in one trade when my absolute max is supposed to be 1%.
-
What do you have in the logs?
-
I checked that after disputing with ICM and indeed the log says that the SL was set at 10 pips and 9.2 pips respectively (should have been 5 pips) while the TP was correctly set for both at 6.4 pips (TP is supposed to be 130% of SL and so 6.4 is correct amount of a 5 pip SL so I'm confused why the TP is calculated correctly on an incorrectly set SL).
I can provide the logs if you wish to verify.
-
Check if the EA modified the stop itself. First, the EA calculates the future stops and sends them to the server as absolute values. If the SL should be at 1.2345, that value is sent to the server, not something like 5 pips. But I programmed it to correct the stop if slippage occurs. The problem is that sometimes the trade is opened at price that is different than the requested price (slippage), but SL and TP remain at the requested levels - as a result the open price is shifted towards SL or TP a little bit. So I programmed the EA to modify the stops if that happens, so that if you wanted to have for example SL at 10 pips relative to the open price, to be 10 pips and not 8 pips for example. Take a look at the logs for such "modify" action right after the trade is opened, maybe this can explain the confusion.
-
Hi again,
I'm a bit upset because the EA did the same thing again this morning - I even delayed the trading for the first hour after open (I will delay for 4 hours next week - it's costly to lose $130 just on testing).
Again, this mornings trade exactly the same error - it opened and set SL at 10 pips not 5 and TP at 6.4 pips (i checked the setting and it's set to 128% of SL so the 6.4 pips TP are accurate).
There was no modifying of stops - it literally opened the position at 1hr and 2 seconds after market open (remember I programmed a 1 hour market open dealy) which was immediately 10 pips in loss and closed immediately at a $130 loss (2% of account) - is this an early market open slippage issue?
Like I've said, this has happened three out of the four weeks it has traded the USDCHF weekly and the fourth time it also lost the trade but didn't open it until 3 hours after market open (I was late to start up the trading platform) and so it set the 5 pip SL correctly - I am suspecting that market open conditions for USDCHF in particular are way too slow (high slippage, low liquidity) that somehow it wacks out the EA.
Can I send you the mq4 file for viewing - it's only about 25 blocks...
Other trades opened at the same time 1 hour after market open this morning (AUDUSD 1W, GBPUSD 1D, NZDUSD 1Mo, USDCAD 1D and USDCAD 1W) all set up correclty using the same EA and while some of them opened in relative high loss positions (again assuming because of low liquidity and high slippage; some one was 33% of SL in loss and one about 25%), their SL were wide enough that this didn't trigger their SL and they have since recovered nicely and I'm sitting at a $122 profit across the 5 trades.
So the algorithm works just I need to know why the USDCHF at 5 pips at market open on a Monday morning gets almost always triggered in loss - should I set to delay for 4 hours and see if that fixes it?
Lastly, if I set the 'Hours' and 'Days' filter block to 'Server Time', can I set it to not trade Monday between 00:00 and 04:00 to successfully stop trades at Sydney market open (I'm currently using GMT Sunday and GMT 21:00-23:59 which converts to 8am-10:50am Sydney time but will using Server time as described work)? More directly, will using Server Time (Monday and 00:00 onward) work for all brokers and MT4 platforms regardless of where the server/platform/broker operates from - I chose GMT time so that anyone can use my EA around the world but I suspect that Server Time does the same (all servers will record 00:00 at market open on a Monday even if the server is technically located in, say, NY which is a different time to both Sydney and GMT).
-
What is the name of the project? I can see it directly.
In MT you can get the server's time - the time of the candles. I guess that this time depends on where the broker is located. You also have local time, which comes from the clock of your PC. That GMT time is linked to your PC clock as well.
-
It sometimes calculates 'incorrectly' on purpose.
The % risk trade sizing code does have undocumented but apparently intentional situations where it violates the user's selected setting and trades above the stated percentage. (A somewhat dangerous prospect.)
Perhaps that is involved in this problem.
Would be nice if such things were documented and/or user selectable.