< 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 SetStopContract are used.

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 a trade is exited and immediately entered again in the same direction.  This results in unexpected trade behavior and can be easily avoided using this strategy coding practice.

I reported the TradeSameEntryExit 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.

NOTE:  As of June 2024, MultiWalk will now check your strategy for these bugs during optimization.  This means that you can use the built-in SetStopLoss and SetProfitTarget EasyLanguage keywords since they work correctly in most situations.  In those situations where they do NOT work, MultiWalk will warn you so that you can change your strategy logic using one of the below workaround solutions.

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