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

Re: Simulation of SetPercentTrailing logic



PureBytes Links

Trading Reference Links

> Has    anyone    simulated   the SetPercentTrailing  function?
> That  is,  using  your  own buy/sell  easylanguage  code  and
> logic,  do the same or as close as possible to the
> SetPercentTrailing function.

It's not possible to duplicate it exactly.  TS's built-in stops 
take effect instantly and work intrabar.  So, for example, if you 
said

  SetPercentTrailing(500, 15);

and your open equity reached $500 within bar X, the 15% trailing 
stop would take effect instantly within bar X.  If the open 
equity goes to $5000 on bar X+1, TS will adjust its trailing stop 
within bar X+1 to protect the new larger open equity.  This can 
cause falsely positive results in backtesting if you don't set 
the strategy resolution fine enough, since TS tends to assume the 
best possible results.  This is why you shouldn't use these stops 
on TS4, because you can't set the strategy resolution.

You can't do that with EL.  To approximate this trail with your 
own EL, you have to detect the max-open-equity condition on bar 
X, and then set the trailing stop for bar X+1.  So the stop at 
$500-15% = $425 open equity will be in effect on bar X+1, even if 
the open equity goes to $5000 in bar X+1.  This kind of stop is 
guaranteed to be "safe," in that it reports the same results in 
backtesting that you'd see in realtime execution.

Here's some (untested) code that should do the trick:

inputs:  TrailFloor(500), TrailPerc(15);
vars:  TrailPts(0);
if MarketPosition <> 0 and MaxPositionProfit > TrailFloor then begin
  TrailPts = (1-TrailPerc/100) * MaxPositionProfit / BigPointValue;
  if MarketPosition = 1 then
    exitlong at EntryPrice + TrailPts stop
  else
    exitshort at EntryPrice - TrailPts stop;
end;

That's TS4/TS2k syntax.  You'll have to make the appropriate 
changes to the exit statements for TS6.

Gary