SL and trailing SL in the middle of the candlestick
-
Hello,
I am building and EA that opens a trade with a SL and adds a trailing SL to this trade. Here is the simple version of the EA: https://fxdreema.com/shared/2GfqteQ1e
I want both the SL and the trailing SL to only activate at the closing of the last candlestick or the opening of the new candlestick, this is why I am using the 'once per bar' block. However, in the strategy tester I see that they activate when the SL price is reached, even if it is in the middle of the candlestick. Here is a screenshot:

Why is this happening and what is the solution?
Thank you.
-
What you need is a new tree of blocks in wich you define those closing conditions and then you end up adding a 'close trades' block. Additionally you shouldn't use a SL price in your 'buy now' block.
On the other hand, your trailing stop strategy cannot be implemented with that usual trailing block. You will need to create a new tree of conditions like this (look a 2nd pic):
-
@tns Looks like your spread is extremely high. Maybe you used current spread in tester and it is extremely high because of weekend? Just a guess.
-
@l-andorrà Thank you for the reply.
I have created a new tree of conditions following the example you sent to me but I do not think I can use this as a trailing SL because when I backtest it I see that the trailing SL is never activated. It actually trails the SL both upwards and downwards. Here is what i did: https://fxdreema.com/shared/VgSIeDYrdAlso, I do not understand why you say that I should not use a SL price in the 'buy now' block, what is the problem with doing that? And why is the 'trailing stop' block not appropriate for my strategy?
To clarify, the first EA that I had shared was doing what I wanted, the only problem was that it was not activating the SL at the correct timing...
@trader-philipps Thanks for the suggestion. I am indeed using current spread in the tester but all these examples are not on weekend and it is in the EURUSD so i doubt the spread was that huge that many times...
-
@tns I think this doesn't work with ATR as it is a price fraction.

I use a custom mql block on the onInit tab to get the digits for pips multiplication like that ..

where vd_to_pips_multi you would multipli the ATR result with.
Maybe that function also works in a modify variables block. haven't tried, yet!
-
@trader-philipps Ok, testet with modify variables block and works as well.

-
@trader-philipps Thank you, this is a good workaround but I do not think it provides a solution to what i want to do.
The problem I see with NOT using the block 'Trailing SL' and instead using the blocks: 'Pips away from SL' --> 'Modify Stops' is that it will modify the SL not only as a trailing SL that follows the price upwards, but it will also follow the price downwards...Also it does not have the 'trailing start' option that the 'Trailing SL' has.
This is why i would like to stick to the initial EA that I shared but I do not understand why the SL does not activate at the right timing. Maybe @fxDreema can explain?
-
@tns In that case you might calculate the SL value by yourself and compare if it's above (buy trade) your current SL and only modify the order if that is the case.