Help on Trailing stop block appreciated (SOLVED)
-
I know it can be done but I'm afraid I'm so stuck I can't simply see it before me. I want to specify a trailing stop equivalent to a percentage of open price. Then the trailing step will be a different percentage of that same open price. This second part I can do but I can't see how to implement the first one considering the options available in the block.
Let me put a numerical example. Let's imagine I choose the TS to be triggered at an accumulative 11% of open price and then the trailing step is specified as a 4% of open price. This means that when price hits 11% of open price in profit SL is moved to 4% of open price. When price hits 22% then SL is moved to 8% of open price and so on. Considering that 4 is a 36.6% of 11, this is the trailing step to be inserted here:

What I can't find is how to insert the first percentage as a price level, price fraction, pips or something else.
Any help will be much appreciated.
-
@l-andorrà Don't know if I get the issue right, but I'd start like that

-
Didn't consider that option. I'll try it. Thank you.
-
@l-andorrà Let me know if it works.
-
I'm afraid it doesn't work. The first move is done correctly. The first stop is moved at 4% when 11% is hit. However, 11+4 = 15. so when price hits 15% of open price a new move of SL is done when I need it to be a 22% (11+11).
Any other hint?

-
@l-andorrà So your trailing step is wrong?
-
No, the trailing step is correct. The problem is that the trailing stop should be applied to specific % levels (11, 22, 33, etc.) and not as soon as the SL has moved. Your configuration will look for an 11% profit as soon as the SL was moved to the 4% level whereas I need the TS to be triggered at those concrete levels.
-
I see there is a nice option called 'Multiple levels'. Apparently that is exactly what I need but it can only be selected in pips. What kind of loop inside the 'For each trade' loop should I create to 1) transform the initial percentages into pips, 2) referred to each open price, 3) to be inserted as a string variable into that box?
I pray for it to be feasible without custom code blocks. Otherwise I'm doomed.

-
@l-andorrà You lost me as you haven't shared your project ;-))
However, as far as I understood calculate the first 11 % in pips and than multiply it?!? If you need to multiply a pricefragment to Pips you may try this function MathPow(10,_Digits-1) as an multiplicator.
-
You're right, sorry :D. Here it is:
https://fxdreema.com/shared/ZPUTG3aKb
This is for buys only. This is what I do:
- Trail percentage and trail step are inserted as input parameters as decimal numbers (11 and 4 for example).
- Both percentages are translated into fraction numbers (in this example 0.11 and 0.04)
- Then they are used in that loop inside a loop structure.
The loop below the buy block is designed to visualize all trailing triggers ans trail steps. None of them is visualized.
The loop below 'For each trade' is supposed to do the job. It doesn't. I'm still struggling with loops. I guess the solution is there but I can't see it right now. Any hint?
-
@l-andorrà okay, tried to understand your approach, but my brain didn't make it in the end.
May you please repeat the price levels when the stop should be modified and at what distance?EDIT
After reflecting once more, I still don't understand why you can't use the regular traling stop as the values are variable per trade, but the basis is static as it's the open price.Example: My asset has the price of 100 USD and I'm in a Buy trade. My trailing starts at 11% profit and SL is set to 4% of open price.
- Adjustment - at 111 USD -> SL 104
- Adjustment - at 122 USD -> SL 108
- Adjustment - at 133 USD -> SL 112
If that is what you want to achieve, all input values such as start, step and stop are static for the trade, right?
With static values and assuming that the 1 pip is 1 point, it would look like that, right?

If that is still right I think your mistake is in calculating the price percentage as pips. But let's do one step after the other.
-
I would suggest to calculate the trailing step beforehand.
This could be a starting point for a long trade.
OpenPrice = 1.00000 (get the openprice as a variable)
PointSize = 0.0001 (get this value from the market properties)
PercentToMove = 11%
TrailStepPercent = 4%
TrailStopLevelPriceToMoveStopLoss = OpenPrice + PercentToMove = 1.00000 + 1.00000*(11/100) = 1.11
PipsToMoveStopLoss = (PriceToMoveStopLoss - OpenPrice)/PointSize = (1.11000 - 1.00000)/0.0001 = 1100
TrailStepPips = PipsToMoveStopLoss x TrailStepPercent = 1100 x (4/100) = 44
TrailStopLevel = StopLossLevel + TrailStepPips (as a price fraction)If Price (Ask, Mid, Bid) >= PriceToMoveStopLoss -> {Move stop loss to (SL + TrailStepPips as price fraction) AND Modify [PercentToMove = PercentToMove x 2 (or +11) AND TrailStepPercent = TrailStepPercent x 2 (or +4)]}
As a project, something like

It does not look very polite but it can be improved.
Don´t forget to reset variables to initial point when a new trade opens.
Hope this might help a few.
-
Thank you to both of you. Let me study your suggestions in detail and I will be back with my results.
-
@trader-philipps I tried as per your first post above and I confirm it doesn't work. For a reason I don't understand the stop moves before hitting the first level.
Let me show my last backtest example. I tried GBPJPY qith a 4% trailing stop and a 1% trailing step.The open price for a buy was 131.094. This means that:
a) Trailing stop = 131.094 x 1.04 = 136.338.
b) Once the previous price is hit the trailing step should move the stop to: 131.094 x 1.01 = 132.405.Well, because of weird calculation made by the block, the stop moved when price reached 135.300, far before it should.
On your second suggestion, yes, I need static values. The problem is finding the equivalent of pips or price levels from the initial percentages and then 'translate' them into the trailing stop block.
-
@josecortesllobat Your suggestion is apparently very close to what I need. However, I see two problems. The first one is this formula
TrailStepPips = PipsToMoveStopLoss x TrailStepPercent = 1100 x (4/100) = 44
If you read my first post, the trailing step is a % of the ope price too. This means the formula should be:
TrailStepPips = OpenPrice x TrailStepPercent = 1.00000 x (4/100) = 0.04.
Then I don't understand the following one:
TrailStopLevel = StopLossLevel + TrailStepPips (as a price fraction). Is StopLossLevel the initial SL? And how TrailStepPips (as a price fraction) is affected by the new result 0.04?
The second problem is your loop. Those calculations before the 'For each trade' block will not be updated for all open trades, but on a tick on tick basis. If I have 3 open trades, all of them will have to have their specific TrailStopLevel value, for example. In your structure, if I understand it correctly, that cannot happen as those calculations will be applied before eavary trade is searched for.
-
@l-andorrà I have a feeling this is unnecessarily complicated approach

Why doesn't "% of profit" work as a solution?
What do you mean by "11% of open price", isn't that like EURUSD crashes to 0.1234 ?

-
@roar said in Help on Trailing stop block appreciated:
@l-andorrà I have a feeling this is unnecessarily complicated approach

Why doesn't "% of profit" work as a solution?
What do you mean by "11% of open price", isn't that like EURUSD crashes to 0.1234 ?

That option doesn't work because that % is static on the block (something I want) but is linking the current price to the open price (something i do NOT want). Is that same option was available for the current SL level instead of the open price that would do the trick. Additionally it is calculated as money (profit), and not pips or price level. Why transforming the initial % into money first and then put them here? Double effort worthless, I'm afraid.

On the other hand, when I say '% of open price' I mean exactly that, an percentage applied to the open price that is added (for buys) or substracted (for sells) in order to get the trigger for the TS to move up/down to the trail step.
-
@l-andorrà Did I get you right that you want for 2and adjustment the same value percent of the current SL as pricefraction for the 3rd adjustment and so on for all next?
As I asked before, please have an example for understanding what you try to achieve! -
Ok, I will detail a concrete example.
-
Initial conditions: TS trigger every 4% and TS step at 1% of open price. Both percentages are input parameters, so they can different every time the EA is run.
-
Sell trade at 1.12320
-
This means that 1.12320 x (4/100) = 0.04493. So when price hits the following levels:
a) 1.12320 - (0.04493 x 1) = 1.07827
b) 1.12320 - (0.04493 x 2) = 1.03334
c) 1.12320 - (0.04493 x 3) = 0.98842
d) 1.12320 - (0.04493 x 4) = 0.94349
e) ...and so on the TS is to be moved.
-
SL is moved according to the input parameter: 1.12320 x (1/100) = 0.01123. This means it is moved to the following price levels:
a) 1.12320 - (0.01123 x 1) = 1.07827
b) 1.12320 - (0.01123 x 2) = 1.03334
c) 1.12320 - (0.01123 x 3) = 0.98842
d) 1.12320 - (0.01123 x 4) = 0.94349
e) ...and so on.
And this is to be calculated for all open trades (up to 10 open trades at the same time).
I hope it is more clear now.
-
-
@l-andorrà Besides that the SL prices are wrong in calculation I think I got what you try to do. And I still believe that you can do this with the standard trailing block.
Even if the inputs are variable depending on open price, trailing start trailing step and trailing stop are static from there on, right?
In your case if I get it right it's
trailing start: 0.04493
trailing step: 0.04493
trailing stop: 0.01123Is that correct? In that case you just need to calculate those values and place the variables in the input fields. Maybe you need to transfer in Pips using the
MathPow(10,_Digits-1);multiplicator. Or if possible use the price fraction.