With the latest release, we now have a TOS function in our strategies called “entryprice()”. It returns the price of the most recent entry while using strategies. This is great news for us, because it means we no longer have to reproduce our entry signals in a trailing stop strategy like I described in my earlier post! While it doesn’t make a trailing stop strategy any easier to code, it does make them universal instead of entry specific.
I have created two strategy files for my Donors that use this function to approximate having a trailing stop in the market. There’s one for long exits and one for short exits. Here’s a picture of one in action:
The way this works on the long side is this: after entry, a stop is placed x points (or percent, there is an input) below the entry price. As we make new highs, the stop loss is trailed up x points/percent below that high. It’s the opposite for shorts. In the picture, we didn’t get a big enough retracement from each subsequent low to trigger our trail. It just kept getting moved down until it finally hit.
With these files, you just add them to any chart that you are running any entry strategies on, and they will just work, no other coding required. These strategies are available to blog donors. You can download “TrailingStopStrategies.zip” which contains the strategy files from the Donors Only folder at “Released Thinkscript Strategies” from my Google site. If you are trying to do it yourself, leave a comment and I can answer questions or give some pointers.