Decrease Stop Loss depending on trade duration

Avatar
  • updated
  • Completed

As this is my first suggestion please gladly correct me if this idea doesn’t make sense. 😊

Regularly you enter a trade when the entry signals you chose show up/down. Then there are three possibilities:

  1. The trade actually moves into the desired direction; hence you pretty soon enter the win area.
  2. The trade moves against you and pretty soon the stop loss is hit. Even though this sucks, this is why you do set it 😊.
  3. The trade stays between your SL and your TP for some/a long time.

Possibilities 1. and 2. are daily business. However, when a scenario 3. takes place, this has some severe disadvantages:

  • When this runs over a period of several days you need to pay swap fees.
  • The margin you use is blocked so you can not use it for other (more promising) trades.
  • Over all, if after a longer time period the asset price eventually moves in one direction or the other, it is more like a coin toss rather than based on what your entry conditions were.

Furthermore, in case 2., when the stop loss is hit, this can also be due to a rapid movement directly after the trade has been opened (depending on which indicators you used). Hence, it can occur, that your SL is hit right before the price bounces back into the direction you wanted it to go.

My solution to this would be a time dependency of the stop loss depending on the amount of time that passed after opening the trade. I suggest the following formula according to logistic growth.

Image 1980

With the following formula signs:

  • SL(0): Initial Stop loss you set
  • SL(t): Current stop loss after t time steps after the trade has been opened.
  • P(0): Asset price at the moment when the Trade has been opened
  • K: Exponential damping constant (“How quickly is the SL decreased”)
  • t: Time after the trade has been opened

When the trade eventually hits the win area and a trailing stop is applied, this should override the logistic SL function.

By implementation my hopes are to improve my trading strategy by giving the trade a little more space to breathe directly after opening but cutting it of after a certain time when it does not “take off”.

Avatar
0
Andrey Khatimlianskyi
  • Completed

Done in 2.52.2 -- https://t.me/CommunityPowerNews/82

Documentation is also updated.

Avatar
0
Andrey Khatimlianskyi
  • Started
Avatar
1
jagr19

To simplify things, using reduce SL after time XX would be good. similar to how reduce TP works

Avatar
0
Andrey Khatimlianskyi
  • Planned (collecting votes)
Quote from hendrik dubbe

Thank you both for your answers! First, I am glad that I am not the only one looking for that function 😊. For starters, the formula I gave above is the explicit formulation of logistic growth ant there is a minus missing in the exponent. Mea culpa. Possibly, when coding this function into EA, one would use the recursive formulation which would look like:

again with the following signs:

  • SL(0): Initial Stop loss you set
  • SL(t): Current stop loss after t time steps after the trade has been opened.
  • P(0): Asset price at the moment when the Trade has been opened
  • K: Exponential damping constant (“How quickly is the SL decreased”)
  • t: Time after the trade has been opened

So you would have a law that calculates the stop loss at time step t+1 after trade has been opened, based on the stop loss from the previous time step.

However, your comments made me think if you can simplify/modify this formula
(besides the missing minus 😊). Therefore, I spent some time thinking, what kind of rules one might apply. Here are my thoughts:

  • I started with the logistics growth idea because I thought the sigmoidal curve would give the trade some time to breathe before successively tightening up. I saw the fact, that there would be only one parameter to optimize (K), as an advantage in terms of simplifying the parameter fitting process.
  • However, I fiddled a bit around and saw that a second parameter (time frame where the SL remains constant) would make it easier to adjust EA behavior.
  • This leaves us with one parameter (let’s call it T) during which the SL is held constant. After time T has passed there remain two options: We could decrease SL linearly or exponentially.
  • As any capital market data more or less contains exponential elements, I would suggest to in fact implement an exponential decrease of the stoop loss to entry level.

Summary of suggested solution

To give an illustration of how this would look in the chart, I made the following sketch: 

Let’s look at the setup for a long position:

  • We open a trade at price P at t=0 (Point 1).
  • We set the initial SL at Point 2.
  • Until t=T (Point 3) we can either be stopped out (blue asset branch) or not. So of course, our SL should still not be too big.
  • Let’s say that the trade does recover a bit around t=T. Then it can either continue and we make a profit or we drop again (blue branch that hits points 4 and 5).
  • In that scenario, I believe that with a proper factor for exponential decrease we will have slight advantage compared to linear decrease.

Formula

In plain maths, this will mean the following:

  • From t=0 to t=T:

SL(0): Initial Stop loss you set

SL(t): Current stop loss after t time steps after the trade has been opened.

  • For t > T:

P(0): Asset price at the moment when the Trade has been opened

K: Exponential damping constant (“How quickly is the SL decreased”)

t: Time after the trade has been opened

Does this make sense to you? However, if the implementation effort would be largely increased by

the exponential formula, then please let me know. I believe, that in order to initially test the 

condition, also a linear approach could suffice. If so, of course, I will also give you the 

linear formula. 

Hendrik, thanks for the detailed explanation!

It looks like some kind of trailing stop that moves SL to the position open price level.

And it should be implemented, I guess!
Exponential formula is not as complicated as I thought. So, let it be exponential)
Avatar
1
Sam Kelly
Quote from hendrik dubbe

Thank you very much for your comment. In fact, in order to avoid swap fees, you can have a date filter in this EA so e.g. all trades will be closed 10:30pm. Yet, the decreasing stop loss idea can not be implemented with this simple condition. About the linear/exponential discussion: I have illustrated my thoughts about that in the post below. 

Very good analysis demonstrating an example of the linear vs exponential implementation of your idea. I am aware of the close trade at time option but don't want to be that strict; a night or two of paying swap fees is acceptable but I wouldn't want an order to continue for days as originally suggested; hence, the idea of a decreasing STOP LOSS over time would be preferred to that option. I think a lot of people feel the same as us. 

Avatar
0
hendrik dubbe
Quote from Sam Kelly

I'm new to Forex and EAs (experienced in stocks/shares and technical analysis though) and thought a decreasing STOP LOSS would be a standard feature due to swap fees - alas not. Whether this is a linear or exponential growth/decay for sell/buy I don't have an opinion. Perhaps for the sake of coding ease Andrey's suggestion above would suffice. 

Thank you very much for your comment. In fact, in order to avoid swap fees, you can have a date filter in this EA so e.g. all trades will be closed 10:30pm. Yet, the decreasing stop loss idea can not be implemented with this simple condition. About the linear/exponential discussion: I have illustrated my thoughts about that in the post below. 

Avatar
1
hendrik dubbe

Thank you both for your answers! First, I am glad that I am not the only one looking for that function 😊. For starters, the formula I gave above is the explicit formulation of logistic growth ant there is a minus missing in the exponent. Mea culpa. Possibly, when coding this function into EA, one would use the recursive formulation which would look like:

again with the following signs:

  • SL(0): Initial Stop loss you set
  • SL(t): Current stop loss after t time steps after the trade has been opened.
  • P(0): Asset price at the moment when the Trade has been opened
  • K: Exponential damping constant (“How quickly is the SL decreased”)
  • t: Time after the trade has been opened

So you would have a law that calculates the stop loss at time step t+1 after trade has been opened, based on the stop loss from the previous time step.

However, your comments made me think if you can simplify/modify this formula
(besides the missing minus 😊). Therefore, I spent some time thinking, what kind of rules one might apply. Here are my thoughts:

  • I started with the logistics growth idea because I thought the sigmoidal curve would give the trade some time to breathe before successively tightening up. I saw the fact, that there would be only one parameter to optimize (K), as an advantage in terms of simplifying the parameter fitting process.
  • However, I fiddled a bit around and saw that a second parameter (time frame where the SL remains constant) would make it easier to adjust EA behavior.
  • This leaves us with one parameter (let’s call it T) during which the SL is held constant. After time T has passed there remain two options: We could decrease SL linearly or exponentially.
  • As any capital market data more or less contains exponential elements, I would suggest to in fact implement an exponential decrease of the stoop loss to entry level.

Summary of suggested solution

To give an illustration of how this would look in the chart, I made the following sketch: 

Let’s look at the setup for a long position:

  • We open a trade at price P at t=0 (Point 1).
  • We set the initial SL at Point 2.
  • Until t=T (Point 3) we can either be stopped out (blue asset branch) or not. So of course, our SL should still not be too big.
  • Let’s say that the trade does recover a bit around t=T. Then it can either continue and we make a profit or we drop again (blue branch that hits points 4 and 5).
  • In that scenario, I believe that with a proper factor for exponential decrease we will have slight advantage compared to linear decrease.

Formula

In plain maths, this will mean the following:

  • From t=0 to t=T:

SL(0): Initial Stop loss you set

SL(t): Current stop loss after t time steps after the trade has been opened.

  • For t > T:

P(0): Asset price at the moment when the Trade has been opened

K: Exponential damping constant (“How quickly is the SL decreased”)

t: Time after the trade has been opened

Does this make sense to you? However, if the implementation effort would be largely increased by

the exponential formula, then please let me know. I believe, that in order to initially test the 

condition, also a linear approach could suffice. If so, of course, I will also give you the 

linear formula. 

Avatar
0
Sam Kelly

I'm new to Forex and EAs (experienced in stocks/shares and technical analysis though) and thought a decreasing STOP LOSS would be a standard feature due to swap fees - alas not. Whether this is a linear or exponential growth/decay for sell/buy I don't have an opinion. Perhaps for the sake of coding ease Andrey's suggestion above would suffice. 

Avatar
0
Andrey Khatimlianskyi
  • Under review

Hendrik,

Your idea looks good

But isn't it too complicated?

Maybe it will be better just to decrease the SL by some coefficient every X minutes or bars?

Or, if you want to decrease it exponentially, we can add one more coefficient to decrease the first coefficient )

What do you think?

Avatar
0
james

Hi, I was going to suggest the same thing, I was using RSI to make entry trades and sometimes it would be immediate, no SL needed, others it would do a quick bounceback then hit (large SL needed, risky), others it would sit at a small profit or loss for a very long time, I too wanted to be able to close if the market ranges for a certain period after my initial signal, just close these off as the trend identified didn't continue it stopped, would be very useful to have more flexibility with stop losses, exactly as above, where it starts large to accommodate a bit of fluctuation, then closes in over time, ultimately just closing the trade after a certain number of bars if trend didn't continue