OnBarUpdate:
-- the OnExecution code sets the profit target using ExitLongLimit
-- the TargetPrice is assumed calculated using ex.Price, but it's not important
OnExecution #1:
-- we'll find that ex.Order.OrderState == OrderState.PartFilled
-- we'll set the profit target like this,
-- a few bars later, another partial fill for 4 contracts --
-- we'll modify TargetOrder to include these 4 additional contracts --
OnExecution #2:
-- we'll find that ex.Order.OrderState == OrderState.PartFilled
-- we'll check profit target like this,
TargetOrder = ExitLongLimit(1, true, TargetOrder.Quantity + ex.Order.Filled, TargetOrder.LimitPrice, "L1tgt", "L1");
[Edit: no it doesn't, this code has an error, see my post #3 below]
-- a few bars later, the order is filled with the 1 remaining contract --
-- we'll modify TargetOrder to include this 1 remaining contract --
OnExecution #3:
-- we'll find that ex.Order.OrderState == OrderState.Filled
-- we'll check profit target like this,
TargetOrder = ExitLongLimit(1, true, TargetOrder.Quantity + ex.Order.Filled, TargetOrder.LimitPrice, "L1tgt", "L1");
[Edit: no it doesn't, this code has an error, see my post #3 below]
My Questions:
1. For fills of 5, 4, and 1 contracts, do the OnExecution sequence of events make sense?
[Edit: Only #1 is correct, code in #2 & #3 has an error]
2. Is ex.Order.OrderState == OrderState.PartFilled correct for OnExecution #1 and #2?
[Edit: yes, state will be OrderState.PartFilled for #1 and #2]
3. Is ex.Order.OrderState == OrderState.Filled correct for OnExecution #3?
[Edit: yes, final fill of the order will be OrderState.Filled]
4a. In OnExecution #1, what is the value of TargetOrder.Quantity after ExitLongLimit() returns?
[Edit: same as ex.Order.Filled, which should be value of '5']
4b. In OnExecution #1, what is the value of TargetOrder.LimitPrice after ExitLongLimit() returns?
[Edit: same as TargetPrice]
5a. Is it safe to use TargetOrder.Quantity in ExitLongLimit() in OnExecution #2 and #3?
[Edit: safe? sure, but my code is using it incorrectly.]
5b. Is it safe to use TargetOrder.LimitPrice in ExitLongLimit() in OnExecution #2 and #3?
[Edit: yes, TargetOrder.LimitPrice contains the limit price set when TargetOrder is first returned in #1 -- reusing it to set to same price in #2 & #3 is benign, and safe]
6. I'm trying to get to a definitive answer for 5a and 5b, because I want to update the existing target order, and I assume I do this by using same last 2 arg strings in ExitLongLimit() in OnExecution #2 and #3 as was used in OnExecution #1.
Is this Correct? [Edit: no, code in #2 & #3 is wrong, code in #1 is correct]
Will this work? [Edit: no, code in #2 & #3 is wrong, code in #1 is correct]
7. I see the advanced overload of ExitLongLimit() is documented like this,
Is this version of ExitLongLimit() being used correctly? [Edit: yes]
Is this overload documented? [Edit: no, not that I can find]
Well, smarty pants, if it's not documented, how did you find it?
Good question, I think I must have found it in example code,
on the forums, or at BMT somewhere ...
Thanks
[Edit: added answers to my own questions in red]
Comment