[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Trailing stop formula



PureBytes Links

Trading Reference Links

As Dave pointed out, without using the PREV function, the stop is
recalculated from each point at which your entry parameters are
true, not from the point at which you entered the trade.  You could
get your stops reset incorrectly several times during the course of
a trade.  Here is a solution, albeit a slow one, adapted from some
Chuck LeBeau code:

LONG ENTRY
Close > Mov(Close,120,Simple) {Just an example}

LONG EXIT
{DEFINE ENTRY PRICE, WITH EXIT BEING -ENTRY
  PRICE AND NO TRADE BEING 0}
  EntryPrice:= If(PREV <= 0,
      {Trade entered today?}
       If(CLOSE > Mov(Close,120,Simple), CLOSE, 0),
            {Trade entered before today. Stopped today?}
             If(Low <= HighestSince(1,PREV > 0,Low) - ATR(10), -PREV,
  PREV));
{EXIT IF ENTRY PRICE < 0 (MEANING EXIT)}
  EntryPrice < 0

The awkwardness here is in defining the entry point (in this case
I've done it by defining the entry price).  The code would be much
easy and faster if there was a function that could capture either
the entry date or the entry price.  Coincidentally, I recently sent
a suggestion to Equis to create an EntryPrice() function and an
EntryDate() function.  This is one area where TradeStation has us
beat.

I would urge you guys to apply some pressure on Equis, too.




----- Original Message ----- 
From: "Dave Nadeau" <dave_nadeau@xxxxxxxxx>
To: <metastock@xxxxxxxxxxxxx>
Sent: Wednesday, June 27, 2001 5:56 AM
Subject: RE: Trailing stop formula

> Philip,
> 
> Here's one approach to coding this trailing stop.  I've written it this way
> since I prefer not to use the PREV function because it greatly slows down
> the computations.  The disadvantage of this approach is that if a new LONG
> signal is triggered while you are still in a LONG trade, the new Highest
> High Value is in reference to that most recent LONG signal, not the one you
> entered your trade on.
> 
> 
> {Chandelier Exit}
> RefHigh:=HighestSince(1,Long=1,H);
> RefLow:=LowestSince(1,Short=1,L);
> Fact=2.5;
> ATRng:=Mov(ATR(1),10,S);
> CloseLong:=CLOSE<(RefHigh-(FactHigh*ATRng));
> CloseShort:=CLOSE>(RefLow+(FactLow*ATRng));
> 
> Dave Nadeau
> Fort Collins, CO
>
>
> 
> > -----Original Message-----
> > From: owner-metastock@xxxxxxxxxxxxx
> > [mailto:owner-metastock@xxxxxxxxxxxxx]On Behalf Of Philip
> > Sent: Tuesday, June 26, 2001 9:38 PM
> > To: metastock@xxxxxxxxxxxxx
> > Subject: Trailing stop formula
> >
> > Greetings,
> >
> > I would like to ask your help in writing a formula for trailing stops. The
> > concepts themselves are very basic:
> >
> > For short trades: H + ATR(10)
> > For long trades: L- ATR(10) . . . or some such, doesn't really
> > matter at this
> > point.
> >
> > But I'd like to write the formula in such a way that once a trade has been
> > entered, the stop ONLY moves in the direction of the trade, or
> > stays at the
> > same level. Thus, in a short trade, the stop would only follow the market
> > down or stay unchanged, it would never retrace any progress it's
> > made, never
> > give up any ground, even if the market moved up against the position. The
> > same would hold true for a long trade, in reverse naturally. The trailing
> > stop moves up with price, but goes sideways if the market drops, thereby
> > letting the stop take me out.
> >
> > Has anyone been over this terrain? I am running MS 6.52.
> >
> > Best regards,
> > Philip