- ago
I am testing a strategy via the strategy monitor using a dummy broker and TD Ameritrade for streaming and using stock RBLX. My strategy executed a buy at the expected point in time, but WL8 reported fill price was way below the actual price as shown in ThinkOrSwim. It wasn't even close. The reported fill price was $39.77, but the actual price as shown in ThinkOrSwim at that point in time, looking at the RBLX chart, was $40.67. RBLX is heavily traded with typical spreads of only one or two cents.

I am using market buy/sell orders in my code. To place a buy I use PlaceTrade. To sell I use ClosePosition. The price for both buy and sell I specify 0 (zero) because they're market orders. I have all options checked in Preferences/Portfolio Sync.

For example, to buy market I use:

CODE:
PlaceTrade(bars, TransactionType.Buy, OrderType.Market, 0, -1, reason);


The stock is RBLX and the buy date/time is 7/18/2022 13:24. Later, the strategy executed a sell of the same set of shares occurring at 7/18/2022 13:34. The reported fill price was the same as the buy price - $39.77. The actual price in ThinkOrSwim was $40.49. A little later another buy and sell pairexecuted and the same fill price of $39.77 showed up for both buy/sell...


Maybe I need to flush some cache, or do a re-install, or I'm doing something wrong with the PlaceTrade and/or ClosePosition calls?

Thanks.
0
345
Solved
4 Replies

Reply

Bookmark

Sort
Glitch8
 ( 10.94% )
- ago
#1
We had another report of this and are investigating, thanks for adding more info.
0
- ago
#2
This problem just occurred, again, using a dummy broker and TD Ameritrade for streaming. Stock is RBLX, with buy date of 7/27/2022, 09:57, the reported fill price in WL8 strategy monitor as $39.00. Actual price in TOS was $40.03. The spread on this stock is only about 3 cents, typically - never $1.00 as it is heavily traded with volume around 50K per minute.

When backtesting, the correct prices are reported.
0
- ago
#3
I ran a test with a small C# strategy that uses FindOpenPosition, PlaceTrade and ClosePosition in the same manner as in the strategy that is exhibiting the issue. Below is the small test strategy that simply buys on two green bars and sells on two red bars. This simple strategy reports the correct fill prices in the strategy monitor. I carefully examined the FindOpenPosition, PlaceTrade and ClosePosition in both strategies, and there are no differences in any of the key parameters such as transaction type, order type, price and position tag. Hope this helps....

CODE:
using System; using WealthLab.Backtest; using WealthLab.Core; using WealthLab.Indicators; namespace WealthScript1 { public class MyStrategy : UserStrategyBase {     public MyStrategy() { } public override void Initialize(BarHistory bars) {          StartIndex = 1; } public override void Execute(BarHistory bars, int idx) {          Position foundPosition0 = FindOpenPosition(PositionType.Long);          if (foundPosition0 == null)          {             if (bars.Close[idx] > bars.Open[idx] && bars.Close[idx - 1] > bars.Open[idx - 1])             {                _transaction = PlaceTrade(bars, TransactionType.Buy, OrderType.Market, 0, -1, "Buy At Market (1)");             }          }          else          {             if (bars.Close[idx] < bars.Open[idx] && bars.Close[idx - 1] < bars.Open[idx - 1])             {                ClosePosition(foundPosition0, OrderType.Market, 0, "Sell At Market (1)");             }          } }       private Transaction _transaction; } }
0
Cone8
 ( 24.99% )
- ago
#4
Thanks, but a strategy isn't even required. The dummy broker is just getting a bad/inaccurate price from its partial bar request to fill active orders, so we'll just have to see what's making that happen.

(It's not a problem for live trading, where the broker directly reports the actual fill price.)
0
Best Answer

Reply

Bookmark

Sort