Live Trading Cancel & Replace Limit orders
Author: boreland
Creation Date: 11/7/2015 12:48 PM
profile picture

boreland

#1
While I have read the programming guide it is not clear to me if an active Limit Order or Stop Order is automatically cancelled and replaced by another sell order that the algorithm might generate.

Example:
CODE:
Please log in to see this code.

Does the second sell order (be it AtMarket, AtLimit, AtStop) automatically cancel and replace first sell order which is active in the market?
profile picture

Eugene

#2
Please review Cone's reply in post #14:

SellAtStopLimit index out of bounds error
profile picture

boreland

#3
Thanks, I did not see this additional response from Cone to my earlier question. I understand Cone's point about projecting orders forward, but I'm still a little unsure about have things are likely to play out real time. I apologize for being so pedantic but it's really important I get this right and I'm sure this issue must have crossed the minds of others building real time trading systems. There are really two issues/questions here.

1st:
CODE:
Please log in to see this code.


a. In the above code snippet the limit order will be placed IntradayBar = 1 if buyGap is true. On intradayBar = 2 does this order stay active or is it cancelled?

b. On IntradayBar = 9 the Limit Order will automatically be cancelled. Correct?

2nd:

CODE:
Please log in to see this code.


Should this statement become true and the previous order is active in the market (i.e. IntradayBar <= 8) how does this order statement get executed. Does it cause the live limit order to be cancelled and replaced with this one, or do I have to explicitly cancel the limit order first?








profile picture

Eugene

#4
1a. If the conditions become false according to your system's logic, the SellAtLimit isn't triggered any more. An alert is valid for one bar. If it's not placed it's canceled.

1b. Correct.

2. It's executed immediately on the next bar's open assuming that "anotherExitConditon" == true. It's not that one order cancels another. Like Cone said and I'm stressing, a stop/limit order is canceled by not placing it again.

P.S. Please check out the WealthScript Programming Guide > Programming Trading Strategies > Peeking > Order of Trading Signals.
profile picture

boreland

#5
CODE:
Please log in to see this code.

If we assume bugGap condition remains true then this order will remain active in the market (i.e. be "renewed") until IntradayBarNumber(bar) > 8. Correct?

But what if this condition become true during this period?

CODE:
Please log in to see this code.

Should the order sequence be reversed so that this order is execited before the renewal of the limit order?

i.e

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

Eugene

#6
QUOTE:
Should the order sequence be reversed so that this order is execited before the renewal of the limit order?

The order sequence, according to the manual I just mentioned, should at all times be reversed because it's unrealistic to expect that a SellAtLimit order would precede execution of a SellAtMarket order.
profile picture

boreland

#7
Thank's that's very helpful. So my takeaway is that orders are cancelled and or placed on bar close. An active limit order if it is to continue forward to the next bar if the condition remains true is first cancelled at bar close and then reinstated. The order of execution at the end of bar follows the examples in the programming guide as you referenced above. So a market order if it is to supersede a limit order should be placed ahead of the limit order in the program sequence of events. I should also add the another limit order if it is to supersede an exiting limit order should be placed ahead of it.
profile picture

Eugene

#8
Your understanding is correct.
This website uses cookies to improve your experience. We'll assume you're ok with that, but you can opt-out if you wish (Read more).