Self adjusting trailing stop based on market movements
Forums › ProRealTime English forum › General trading discussions › Self adjusting trailing stop based on market movements
- This topic has 17 replies, 6 voices, and was last updated 6 years ago by Leo.
-
-
01/09/2018 at 5:27 PM #58700
I was just considering putting together a trailing stop code that if you are in a long position and there is a red candle the trailing stop halves the distance or reduces it by a chosen percentage. If there is a green candle the trailing stop is not moved. This way as a market starts moving against you or starts going sideways your trailing stop comes up to meet your market position.
Not a very difficult code to write but I just wondered before doing it whether anyone else had experimented with this style of trailing stop and how it worked out for them?
01/09/2018 at 5:39 PM #58704I suppose it would be worth considering on how many occasions as a percentage a red candle precedes a trailing stop being triggered , if it is ‘most’ of the time would it not just be the same as just halving the trailing stop period . Some stats will help ascertain whether this might be a useful tool , id just build it and compare to the static trailer in backtest .
Edit , the idea of a dynamic stop losses is a subject i have just started investigating myself .
01/09/2018 at 5:51 PM #58710Yes Brisvegas – I used to be very wary of trailing stops as they always seemed to be either too close or too far away – never just right. Now I am starting to see the benefits of letting trades run but sometimes the market just stops and goes sideways and you are still left with a trailing stop miles away from where you are. It would be nice in this scenario of a stopped/sideways market that the trailing stop moved up steadily locking in more profit or preventing further loss depending on how the trade was going.
Maybe the percentage amount the trailing stop reduces each time could be based on the historical ratio of red candles to green candles. A little more complicated to code but very possible.
Unfortunately like all good ideas it needs to be attached to a good strategy in the first place!
01/09/2018 at 6:06 PM #58714Markets are dynamic with so many variables , trend , volatility etc etc thats a static stop loss system is a pretty poor compromise most ( all ) of the time , this is where i think dynamic stop systems with different sets of variable parameters for long & short based on changing market dynamics is the only real way forward . i think this is a subject that has huge scope for improving systems returns . Interested to read anyones views and ideas ..
01/09/2018 at 6:20 PM #58715I never tried this kind of trailing stop. You should even consider calling it “reverse trailing stop” because it is the opposite way the trailing stop is commonly used!
When you enter a trade you place your stop loss because you expect some retracements and want them not to affect your trade. If you fear your stop loss you either:
- placed the stop loss in a wrong place
- the trade was not worth while being initiated
Usually novice traders, in case they place a stop loss, tend to move it a bit further as the price moves aginst their trade, thus losing lots of money.
You want to do the opposite… move it towards the price with a high (? I really never tested it, just guessing) probability that it be hit, mainly while still below breakeven. Instead of suffering a bigger loss you’ll suffer a smaller one, but it would still be a loss and you don’t want to trade to lose!
I rarely use trailing stops, because they make me win less money, when I do. I don’t like breakeven as well, since I trade to win, not to even a match! But in case of automated strategies trailing stops may help scalpers gain some pips.
01/09/2018 at 6:55 PM #58725Thanks for your replies.
My thought process is that sometimes you have to accept that you are wrong and a falling market (if long) and a sideways market are telling you that. Better to get out with a small loss than keep holding for a bigger one. Time not in the market is time when your risk is zero. On the other side not moving it if the market is going up is giving the trade lots of breathing room in a rapidly trending market rather than having a trailing stop trail up with you only to suddenly get hit in a sudden down spike or stop loss hunt by the big boys.
Another idea is to have the take profit level also move down to meet your long trade if there is a red bar. This way your risk to reward stays the same and you stand more chance of a close for profit.
Obviously the amount it moves closer to your position would need to be tuned for each market and it would be nice if this could be automatic by looking at past performance by counting reds and greens over a look back period for example (any other ideas?)
Just some thoughts. I’m a bit busy with other stuff right now but I’ll put it on my list. Obviously if anybody else wants to try it out then two ways of looking at something are always better than one.
Note: I just realised that maybe this should be in the General Trading section of the forum rather than this one feel free to move it if you want.
01/09/2018 at 7:17 PM #58729I used to be very wary of trailing stops as they always seemed to be either too close or too far away – never just right.
Try using a supertrend as a trailing stop, instead of the “normal” trailing stop. In my experience, this is much better than the simple built-in trailing stop, partially because supertrend is based on median prices, not on highs (= extreme points) as a trailing stop, and because additionally, volatility (ATR) is used to calculate the position of the supertrend. I never use normal trailing stops in my strategies, results were always bad.
01/09/2018 at 8:05 PM #58732I have tried SuperTrend before but without much success. maybe that was more to do with the strategy than the trailing stop though! Maybe I will revisit it.
I struggle to like ATR. Markets never seem to care what the average range just was!
A lot of my strategies make their decisions based on TotalPrice which I find to be a far better opinion of where the market is heading compared to where it just was than the close price.
01/10/2018 at 1:14 AM #58779I just threw this simple code onto a 1 minute long only DAX strategy that I have on live demo test that uses an MFE based trailing stop. The strategy has so far proven to be only mildly profitable and the backtest didn’t really light any fires. Forward testing has proven similar. With this new reducing stop/reducing take profit code on backtest returns were substantially better (67% improvement). The gain/loss ratio was worse but the average gain per trade was 118% better even if the win/loss rate was far lower (58% compare to 95%). Time in the market was more than halved. There were 32% less trades. Bearing in mind that everything was optimized for the original strategy and that I just threw some numbers in for SL and TP on the new version it seems quite promising. So there may be some merit in my theory yet. Definitely on my ‘to be developed further’ list.
I could definitely see several areas where a long trade was entered and then the market went sideways before dropping rapidly. Any other trailing stop would have been hit for a big loss but my new reducing stop closed the trade near to the buy price.
In the code SL and TP are the starting stop loss and take profit amounts and MinSL and MinTP are the lowest level you want them to rise/drop to. I like using TotalPrice rather than close as at times you can have a lower close than open even when market momentum for the day is still more up than down.
123456789101112131415IF Not OnMarket and <conditions> THENBuy PositionSize Contracts AT MarketSL = ?TP = ?ENDIFIF OnMarket and TotalPrice < TotalPrice[1] THENSL = SL - 1TP = TP - 1SL = MAX(MinSL,SL)TP = MAX(MinTPTP,TP)ENDIFSet Target pProfit TPSET STOP ploss TP01/10/2018 at 1:59 AM #58788So this seems to be a little similar to SAR, only that SAR moves the stop a little closer in every bar, irrespective of whether there is a drop in price or not.
Supertrend (supertrend[sts, per] ) will also move the stop closer, when prices go sideways and volatility (ATR) decreases. The sensitivity of this effect depends on the number of bars (per) that the ATR component is looking back. The distance of the stop is adjusted by the multiplication factor sts. Best results are usually obtained when the supertrend is not used as an immediate stop, but when you check after each bar whether the supertrend line has been cut by the closing price.
01/10/2018 at 10:02 AM #58803Best results are usually obtained when the supertrend is not used as an immediate stop, but when you check after each bar whether the supertrend line has been cut by the closing price.
Thanks for that insight – I will have a play around with that when I get time. The same could be done with my trailing stop potentially. I guess I could not use the SET instruction with a negative number though and would also need to avoid it ever being zero as that turns off the order. It would probably need Stop and Limit orders at each bar close.
I also had a thought that maybe deducting the difference between TotalPrice and TotalPrice[1] when an adjustment is needed rather than a fixed 1 pip would help keep the trailing stop more in tune with market volatility. A rapidly falling market would be met by a rapidly rising trailing stop for a better exit price.
01/10/2018 at 12:48 PM #58837Spotted a typo in the code I posted above. The last two SET conditions are using the same variable which is wrong. With evenly matched TP and SL reductions this does not matter but if you make this a different value the code does not work correctly. Also one of the Min variables was different to my description.
In my defence it was the very early hours of the morning and I had had a couple of glasses of wine… oh and maybe a beer…. or maybe two!
Corrected code here:
123456789101112131415IF Not OnMarket and <conditions> THENBuy PositionSize Contracts AT MarketSL = ?TP = ?ENDIFIF OnMarket and TotalPrice < TotalPrice[1] THENSL = SL - 1TP = TP - 1SL = MAX(MinSL,SL)TP = MAX(MinTP,TP)ENDIFSET TARGET pProfit TPSET STOP pLoss SL01/10/2018 at 1:39 PM #5884301/10/2018 at 1:49 PM #58844Wein auf Bier – das rat’ ich Dir Bier auf Wein – das lass sein
Wine on beer – I advise you, Beer on wine – let it be – according to Google. Don’t worry it was all actually done in the right order.
I am at the moment running a few tests on the theory (Stop Loss one not drinking one!) and at the moment it appears that doing the opposite to what comes naturally appears to work best. Raise stop losses as the market moves towards them and lower take profit levels if it moves away from them. Interestingly lowering take profit levels faster than you raise the stop loss (I talk of long trades only at the moment) gives better strategy performance.
All just brief testing and analysis on one strategy at the moment but definitely getting my interest.
01/22/2018 at 2:55 PM #60178@Vonasi let me know if you got something 😀 As u might have noticed i opened a similar post asking for a better trailing stop 😀
Ive used supertrend as an exit, never as a trailing stop. Although i guess its kinda the same thing haha.
I have also never been friends with the ATR. havnt gotten good results no matter what i do with it 😀
Just a thought tho: Rising ATR as price crosses under a tight supertrend?
Aka when price crosses under a tight supertrend meaning price is reverting, if the ATR is big as well this might suggest a quick drop inc.
-
AuthorPosts
Find exclusive trading pro-tools on