Question #1
I want to clarify about order reference when I'm calling EnterLongStopMarket
Can I just use it like that(code below) and later on use it for cancellation without assignments on OnOrderUpdate?
If yes, will this work same way on Backtest/Live? Because I see most of your examples trying to assign order reference in OnOrder### callback, but actually calling EnterLongStopMarket already returns Order object (I understand that it is read-only), I only need to know if reference remain the same during order life-time and I can cancel it with that reference object.
In my example I'm trying to simulate my question in code. Calling EnterLongStopMarket on bar 300 and assuming price did not move cancelling it on bar 305. This is just simplification to explain what I'm asking. Important point if this code is fine, I want to know if it should behave the same in Realtime also. I understand that I need to call GetRealtimeOrder for Realtime, and want to know if anything else needed?
public class OrdersTestStrategy : Strategy
{
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Name = "OrdersTestStrategy";
Calculate = Calculate.OnBarClose;
TimeInForce = TimeInForce.Gtc;
}
}
private Order order;
protected override void OnBarUpdate()
{
var entryPrice = Close[0] + (TickSize * 100);
if(CurrentBar == 300)
order = EnterLongStopMarket(0, true, 1, entryPrice, "Long123");
else if(CurrentBar == 305)
CancelOrder(order);
}
}
Question #2
Sometimes reply on forum conflicting with documentation, or maybe there is few ways of doing same thing, but only one is documented. So I'm confused what could be used as source of truth.
So my question from which state GetRealtimeOrder can/should be called? From Transition or Realtime?
Question #3
Which from following approaches I can use in Realtime (in backtest they simply do nothing)? I have some logic where at some point I want to cancel all pending orders from Strategy, and make sure that there is nothing hidden stays which will be executed later.
protected override void OnBarUpdate()
{
//approach 1
foreach(var order in this.Orders)
{
CancelOrder(order);
}
//approach 2
this.Account.Cancel(this.Orders);
//approach 3
this.Account.CancelAllOrders(this.Instrument);
}
Comment