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

Re: Problem with Code for Exiting on day of Entry



PureBytes Links

Trading Reference Links

> I was under the impression that it wasn't possible to exit on the
> day of entry via a stop, but an associate gave me some code that said
> it was possible. 

It is possible.  But not the way you're doing it.

TS runs system code at the CLOSE of the bar.  By the time your 
system runs on your EOD data, the day is already over.  It's too 
late to do anything on that bar.

Because of this, stop orders must be issued on bar X-1 to be 
active on bar X.  You can't say "if MarketPosition = -1, ahh, OK, 
I'm short in this bar, now let's set a stop in this bar."  You 
can only set a stop on the NEXT bar.

To exit on the entry day via a stop, you'd have to issue both the 
entry and exit orders on the previous bar, like this:

  buy at Close + Range/10 stop;       { Entry order }
  exitlong at Close + Range/5 limit;  { Profit target }

However be aware that code like this is dangerous.  If you're 
trading with only OHLC data for the daily bar, and if the market 
opens between your two stops, there's no way to know if the 
market hit your exit price before or after your entry price.  It 
would be even worse if you added in a stoploss exit at, say, 
Close - Range/5.  Assuming all 3 prices were hit by the next bar, 
you could safely assume you entered the trade, but you wouldn't 
be able to tell which exit stop was hit first.  TS makes some 
assumptions, but you can't assume those assumptions would have 
matched reality.

If you have higher-resolution data (tick, minute, whatever) 
"inside" your daily bars, then TS2k and later versions can 
calculate the system performance using that higher-performance 
data.  But if you're just using daily OHLC data, there's no way 
to know.

Gary