Trailing Stop Loss
Author: hulley
Creation Date: 2/10/2010 2:58 PM
profile picture

hulley

#1
Trying to figure out how do to a standard trailing stop. It would initially be percent under the entry price and then get adjusted upwards and the price moves up always staying 4 percent under the highest price. I went through the forums but I do not really understand it.

CODE:
Please log in to see this code.


Not to sure this is the way to do it ?
profile picture

Eugene

#2
Try this:
CODE:
Please log in to see this code.
profile picture

hulley

#3
That is great. Is there a function to specify a minimum hold period? I am trying to back test mutual fund switching, and I need to hold for 30 days, so the stop lose would need to be deactivated for the first 30 days.
profile picture

Eugene

#4
Sure. Define a counter of days outside the loop and here's how it would look then:
CODE:
Please log in to see this code.
profile picture

mdaumer

#5
I would like to plot a line of the 95% trailing stop of the highest high since the position was opened in the price pane. Is that possible and, if so, could you indicate the required code changes.

Thanks

Mike


CODE:
Please log in to see this code.
profile picture

Eugene

#6
Sure, see PlotStops() in the QuickRef.
profile picture

mdaumer

#7
Eugene,

My exit strategy requires the closing price to be below the 20 day MA and also be below 95% of the highest high since the position was opened. In this senario PlotStops only plots a red dot when the close has already fallen below the 20 day MA.

I should have phrased my earlier request differently. What I would like to do is to plot a line of 95% of the value of the highest high reached since the inception of the long position. By plotting this information throughout the trade I would be able to visualize proximity to my exit criteria at all times. Is this possible and could you provide or direct me to sample code.

Thanks,

Mike
profile picture

Eugene

#8
QUOTE:
In this senario PlotStops only plots a red dot when the close has already fallen below the 20 day MA.

To rephrase, this exit strategy might be incomplete since it doesn't have a clear exit level defined at each bar.
QUOTE:
What I would like to do is to plot a line of 95% of the value of the highest high reached since the inception of the long position

Here's how:
CODE:
Please log in to see this code.
profile picture

mdaumer

#9
This is very close to what I was looking for. I'm assuming that a plot is not possible since DrawLine was used.

Thank you for the help.

Mike
profile picture

Eugene

#10
A plot is possible if you have a clear exit level defined for each bar. Here, your exit technique is active on a very few bars during a trade.
This website uses cookies to improve your experience. We'll assume you're ok with that, but you can opt-out if you wish (Read more).