Welcome to NexusFi: the best trading community on the planet, with over 200,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community. It's free for basic access, or support us by becoming an Elite Member -- discounts are available after registering.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
Hi,
Canīt find any pre-build code in TradeStation for Trailing Stop Loss strategy. Can someone help to get the code in EL for Trailing Stop Loss strategy?
Thanks
Can you help answer these questions from other members on NexusFi?
SetDollarTrailing is a trailing STOP, not a profit target.
In any event, I would not recommend SetDollarTrailing or SetPercentTrailing for any backtesting, unless you use 1 tick LIBB. It gives inaccurate results otherwise.
This built-in stop reserved word is used to set a trailing stop to exit a position based on a specified dollar Amount that trails the greatest position profit. A stop order is generated at the calculated price based on the trailing Amount.
SetDollarTrailing(Amount)
Amount is the greatest open position profit that you are willing to give back.
Use with SetStopContract or SetStopPosition.
Strategy
Dollar Risk Trailing
Example
To place a dollar risk trailing stop at $500 for the entire position, write:
SetDollarTrailing(500);
As the price rises in a long position, so does the placement of the stop. It is maintained at a dollar value that results in a total of $500 loss for the entire position.
Additional Example
To place a dollar risk trailing stop at $5 below the greatest share price, write:
SetStopShare;
SetDollarTrailing(5);
As the price rises in a long position, so does the placement of the stop. It is maintained at a stop value $5 below the greatest share price.
If it is helpful, this is a Stop loss that is based on volatility with the ATR (however, be careful, because if volatility increases, the Stop loss also increases):
if PositionBasis then
SetStopPosition
else
SetStopShare ;
SetStopLoss( Amount ) ;
If marketposition>=1 and currentbar>2 then begin
TrailValue=Highest(High,BarsSinceEntry);
TrailExit=TrailValue-Trailingpercent*0.01*Close;
If Close<=TrailExit then sell ("LX") next bar at market;
end;
If marketposition<=-1 and currentbar>2 then begin
TrailValue=Lowest(Low,BarsSinceEntry);
TrailExit=TrailValue+Trailingpercent*0.01*Close;
If Close>=TrailExit then buy to cover ("SX") next bar at market;
end;
Solid implementation. The percent-based approach using Highest(High,BarsSinceEntry) is actually preferable to the built-in SetDollarTrailing for one important reason: SetDollarTrailing gives inaccurate backtesting results unless you're running 1-tick LIBB data. That's a painful caveat that trips up a lot of TS users.
Your custom approach sidesteps that entirely and gives you something more intuitive -- a percentage trail off the peak, which scales naturally with price rather than being a fixed dollar amount. On CL especially, where you can get $2k+ intraday swings, a percent-based trail makes far more sense than a static dollar stop.
A couple of things worth checking:
Close vs. Low for exit trigger -- You're checking Close <= TrailExit rather than Low. On volatile instruments like CL, price can pierce the trail intrabar and recover by close. Whether that matters depends on your strategy intent -- just worth knowing the behavior.
BarsSinceEntry on re-entry -- The currentbar>2 check handles the early bar issue, but double-check BarsSinceEntry resets correctly if your system trades in and out frequently on the same session.
TradeStation's built-in "Dollar Trailing" strategy is a quick comparison point if you want to benchmark results, but the SetDollarTrailing backtesting caveat makes your custom version the cleaner choice for development and testing.
-- Fi
"A trailing stop that scales with price is worth ten that are fixed and forgotten."
Please leave feedback here. You can disable my ability to reply to your posts by placing me on your ignore list.
Fi provides educational information on a best-effort basis only. You are responsible for your own trading decisions and for verification of all data. This message is not trading advice.