Hello everyone:

I setup a small project to trade SPY on daily resolution and was confused by the fill price of order. This is code snippets:

// in Initialize:

           SetStartDate(2019, 11, 10);
           SetEndDate(2020, 11, 10);

           SetCash(100000000m);

           _symbol = AddEquity("SPY", Resolution.Daily).Symbol;
 // in OnData:

Setup a StopMarketOrder if we have nothing, and log every OnData event:

           TradeBar bar = data[_symbol];
           Log($"OnData Event: {this.Time}({this.Time.DayOfWeek}) {bar}");
           if (!this.Portfolio[_symbol].Invested && _testOrderTicket == null)
           {
               decimal stopPrice = bar.Close * 1.02m;
               _testOrderTicket = StopMarketOrder(_symbol, 100, stopPrice);
               return;
           }
and sell it immediately since it's for test only:

           if (this.Portfolio[_symbol].Invested && _testOrderTicket != null)
           {
               MarketOrder(_symbol, -100);
               _testOrderTicket = null;
           }
and log the order events in OnOrderEvent:

           Log($"OnOrderEvent: {orderEvent}");

in log files, I find something confusing:

2019-11-12 00:00:00 OnData Event: 11/12/2019 12:00:00 AM(Tuesday) SPY: O: 299.3374 H: 300.4182 L: 299.1816 C: 300.2332 V: 30463332
2019-11-12 00:00:00 OnOrderEvent: Time: 11/12/2019 05:00:00 OrderID: 1 EventID: 1 Symbol: SPY Status: Submitted Quantity: 100 StopPrice: 306.2379
2019-11-13 00:00:00 OnData Event: 11/13/2019 12:00:00 AM(Wednesday) SPY: O: 300.6227 H: 301.83 L: 300.0385 C: 300.8661 V: 43841640
 

Notice that in OnData Event we recorded the time: 11/12/2019 12:00:00 AM. However, in the later event OnOrderEvent, the time is 11/12/2019 05:00:00, it's smaller than the time in OnData event?

The order we subimitted on 2019-11-12 get filled on 2019-11-28:

2019-11-28 00:00:00 OnOrderEvent: Time: 11/28/2019 05:00:00 OrderID: 1 EventID: 2 Symbol: SPY Status: Filled Quantity: 100 FillQuantity: 100 FillPrice: 307.1755 USD StopPrice: 306.2379 OrderFee: 1 USD
2019-11-28 00:00:00 OnData Event: 11/28/2019 12:00:00 AM(Thursday) SPY: O: 306.3868 H: 307.1755 L: 306.0947 C: 307.1755 V: 40449133
2019-11-28 00:00:00 OnOrderEvent: Time: 11/28/2019 05:00:00 OrderID: 2 EventID: 1 Symbol: SPY Status: Submitted Quantity: -100
 

Notice that the Stop Price is 306.2379 and the fill Price is 307.1755, that is the Close price of the day 2019-11-28. However, the Open price(306.3868) has already greater than Stop price, It looks like that the order would be more possible to be filled with that Open price in living trade? 

This is another order submit-fill pair in log file:

2019-12-21 00:00:00 OnOrderEvent: Time: 12/21/2019 05:00:00 OrderID: 5 EventID: 1 Symbol: SPY Status: Submitted Quantity: 100 StopPrice: 320.0991

……

2020-01-11 00:00:00 OnOrderEvent: Time: 01/11/2020 05:00:00 OrderID: 5 EventID: 2 Symbol: SPY Status: Filled Quantity: 100 FillQuantity: 100 FillPrice: 320.0991 USD StopPrice: 320.0991 OrderFee: 1 USD
2020-01-11 00:00:00 OnData Event: 1/11/2020 12:00:00 AM(Saturday) SPY: O: 320.3099 H: 320.4078 L: 318.2013 C: 318.6954 V: 46657905

This time, the order with Stop price 320.0991 is filled with requested price(320.0991), which is greater than the Close price 318.6954.

So this is the second question: what's the specification of order fill price rules in daily resolution trading? I can't find the specification in documentations.

I have attached the backtest. Could anyone help me on the above two questions? Thanks!