Trailing stop after price reaches target
Author: tradermike4
Creation Date: 8/24/2009 11:22 AM
profile picture

tradermike4

#1
Here's a little snippet from a script I recently built. When the current close is the highest in the past 5 bars, a sell is indicated.



if (Close[bar] == Highest.Value(bar, Close, 5))
{
SellAtMarket(bar + 1, p, "Group1");
}


Is there some way to use a variable to record the fact that the price has reached the target price, and then trail the price upward with a stop order for each successive bar until the stop is triggered?

Thanks.

Mike
profile picture

Eugene

#2
Hi Mike,

QUOTE:
Is there some way to use a variable to record the fact that the price has reached the target price,

Yes. Save it in a boolean variable and check it before executing your stop. When the Position is unloaded, reset the boolean variable to false:

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

tradermike4

#3
Thanks, Eugene. That worked perfectly.
Mike
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).