This is a copy of the canned TS6 long exit trailing stop. Hopefully it'll get you started:
{
LX trailing stop based on ATR, activates immediately after entry; profit floor not
required because stop starts out loose; entry-bar protection included.
NOTE: This is not a strict trailing stop because the stop can actually loosen
sometimes instead of always tightening. To convert to a strict trailing stop, ATRVal
should be fixed at the entry-bar for each position.
}
inputs: ATRLength( 10 ), NumATRs( 3 ) ;
variables: ATRVal( 0 ), MP( 0 ), PosHigh( 0 ) ;
ATRVal = AvgTrueRange( ATRLength ) * NumATRs ;
MP = MarketPosition ;
if MP = 1 then
begin
if MP[1] <> 1 or High > PosHigh then
PosHigh = High ;
Sell ( "AtrLX" ) next bar at PosHigh - ATRVal stop ;
end
else
Sell ( "AtrLX-eb" ) next bar at High - ATRVal stop ;
{ ** Copyright (c) 1991-2002 TradeStation Technologies, Inc. All rights reserved. ** }
Enjoy