< All Topics

TradeStation Strategy Bugs

The Problem

There are two critical bugs in TradeStation that effect the results of our strategies when backtesting.  They occur in certain situations when SetStopLoss or SetProfitTarget are used with other TradeStation configuration options.

TradeOutOfBounds bug

https://community.tradestation.com/Discussions/Topic.aspx?Topic_ID=155584
https://community.tradestation.com/Discussions/Topic.aspx?Topic_ID=191991

If using SetStopContract or SetStopShare with backtest option “Fill entire order when trade price exceeds limit price”, then SetProfitTarget gives incorrect results.

Result: The trade fills will (impossibly) occur above the high or below the low of the bar.

TradeSameEntryExit issue

https://community.tradestation.com/Discussions/Topic.aspx?Topic_ID=142849

If using SetStopPosition (the default) and continuous contract symbols have negative prices (such as CL, RB, HO, S, etc), then SetStopLoss and SetProfitTarget give incorrect results.  However, I have found cases where this also occurs with continuous contracts that never have negative prices.

Result: A trade entry and exit will occur on the same tic at the same price.  This results in a commission charge as well as change of trade logic flow.

However, this is not always an indication that this “same entry/exit” trade is because of the above bug.  It can also happen when you have “unqualified” sell/buytocover exit orders active.  This can result in unexpected trade situations where a trade is exited and immediately entered again in the same direction.   I like to keep things simple and avoid this situation by using this strategy coding practice. If I want a trade to immediately re-enter or keep an order in the market instead of exiting/re-entering, then I would that code that into the strategy logic implicitly.

I reported the TradeSameEntryExit issue in 2015. Kevin reported the TradeOutOfBounds bug in 2018. It is now Dec 2023 as I am writing this article and neither have been fixed regardless of multiple pleas from the user base. I have given up hope long ago that these will ever be corrected.

The Workaround Solutions
Kevin’s Close-On-Bar Solution

Kevin has a workaround solution that uses “soft” stop loss and profit targets that exits at the close of the bar:

if openpositionprofit < -stopl then Begin
   sell ("SLL Exit") next bar at market;
   buytocover ("SLS Exit") next bar at market;
end;

if openpositionprofit > proft then Begin
   sell ("PTL Exit") next bar at market;
   buytocover ("PTS Exit") next bar at market;
end;

Part of me likes this approach because it avoids the need for LIBB, which can cause strain on TradeStation when running many strategies. But there are situations when I don’t want to be exposed to the risk of waiting until the close of a bar to evaluate a stop, only to find that the loss far exceeded the original stop.

I am working on a solution that will replace both SetStopLoss and SetProfitTarget, but uses stop and limit orders and maintains entry-bar protection.  E-mail me for more information or check back here for updates.

Table of Contents