In Paper trading, auto staged Stop orders get Canceled
Author: cal777
Creation Date: 2/16/2017 4:07 PM
profile picture

cal777

#1
I am using paperaccount to test run my strategy, and I found that some automatically staged order could not get filled, the status shows Active for a little while and then Canceled. I use STOP entry and still have enough capital in this account, what could be the problem here?
profile picture

Eugene

#2
Could be that either the price has changed or your code does not submit the order on the subsequent bar, causing automated cancelation.

How does your strategy code looks like?
profile picture

cal777

#3
The code generated two orders, one of them is fine. The code is like this, not much change based on a prebuilt strategy:

CODE:
Please log in to see this code.
profile picture

Eugene

#4
QUOTE:
not much change

Probably not much... but that doesn't stop it from being very much destructive! :)

First, it's a mistake to use "bar" for AtStop/AtLimit orders and most AtMarket, too. This creates a peeking into the future condition. For more details please see the WealthScript Programming Guide > Programming Trading Strategies > Peeking. You should always change that to "bar+1":
CODE:
Please log in to see this code.


And this error looks like the culprit for triggering an automated cancel for your order as per the User Guide > Orders > Features and Limitations.

Next, IsLastBarOfDay will not work as you expect it to in live (paper) intraday trading i.e. the order won't be exited at 4:00pm. At the same time it's OK for backtesting. But it's too late to trade when the strategy has determined that the current bar is the last for today (the market has already closed):

CODE:
Please log in to see this code.


Resolving this problem may take more advanced skills than a new user typically has:

Wiki Knowledge Base > Keep from holding positions overnight

If you can't integrate this solution into your code I recommend that you pick an "easier" strategy for your Paper Trading or comment out the EOD exit for the time being.
profile picture

cal777

#5
Thank you Eugene for your lesson, I learned a lot from you!
profile picture

Eugene

#6
Xiao, you're welcome.