Wrong Backtesting Result
Posted: Feb 26 2019
Hi there,
I wrote below codes to backtest how MC treats Limit order on historical data (60 Secs bar). I chose a bar (Date = 1180810, Time = 16:25) that was 28225 on Close and arbitrarily set a Buy Limit price of Close - 4 (28225 - 4 = 28221) , because the first 3 ticks of next bar (Date = 1180810, Time 16:26) was 28225, 28223, 28218. As I had turned on IntraBarOrderGeneration, and Bar Magnifier, I assumed that the filled price should be 28218 because 28218 was the first best buy price for Buy Limit price of 28221. However, the backtesting result shows that the Filled Buy Price was 28221 instead. As there was not even a tick of 28221 within that bar, I appears to me that MC did not really assess each tick in the bar, but just arbitrarily took 28221 as the Buy price.
I attached the screenshots showing the Close price at 16:25, the buy price at 16:26 on the chart, and the print result of various prices (Tick price, planned Buy Limit Price, Actual Filled Price) in the Output window of the PL editor. I also attached a text file containing the historical data, and the screenshots showing my strategy settings.
Please help investigate and explain why caused the error, and how it can be corrected.
Thanks,
McGeorge
I wrote below codes to backtest how MC treats Limit order on historical data (60 Secs bar). I chose a bar (Date = 1180810, Time = 16:25) that was 28225 on Close and arbitrarily set a Buy Limit price of Close - 4 (28225 - 4 = 28221) , because the first 3 ticks of next bar (Date = 1180810, Time 16:26) was 28225, 28223, 28218. As I had turned on IntraBarOrderGeneration, and Bar Magnifier, I assumed that the filled price should be 28218 because 28218 was the first best buy price for Buy Limit price of 28221. However, the backtesting result shows that the Filled Buy Price was 28221 instead. As there was not even a tick of 28221 within that bar, I appears to me that MC did not really assess each tick in the bar, but just arbitrarily took 28221 as the Buy price.
Code: Select all
Inputs:
StartDate (1180810),
StartTime (1624),
EndDate (1180810),
EndTime (1625);
Variables:
StartDateTime (0),
EndDateTime (0),
IntraBarPersist Price_Current (0),
IntraBarPersist Price_Planned (0),
IntraBarPersist Price_Actual (0);
StartDateTime = ELDateToDateTime (StartDate) + ELTimeToDateTime (StartTime);
EndDateTime = ELDateToDateTime (EndDate) + ELTimeToDateTime (EndTime);
If DateTime [0] >= StartDateTime And DateTime [0] <= EndDateTime Then Begin
Print ( "DateTime = ", DateTimeToString (DateTime), ", Current Price = ", Close [0], ", Time = ", NumToStr (Time, 0) );
If Time = 1624 Then Begin
Price_Current = Close [0];
Price_Planned = Price_Current - 4;
Print ( "DateTime = ", DateTimeToString (DateTime), ", Planned Price = ", Price_Planned, ", Time = ", NumToStr (Time, 0) );
End;
If Time = 1625 Then Buy Next Bar At Price_Planned Limit;
If MarketPosition <> 0 Then Begin
Price_Actual = EntryPrice;
Print ( "DateTime = ", DateTimeToString (DateTime), ", Actual Price = ", Price_Actual, ", MarketPosition = ", MarketPosition );
End;
Print ("============================================================================================================================");
End;
I attached the screenshots showing the Close price at 16:25, the buy price at 16:26 on the chart, and the print result of various prices (Tick price, planned Buy Limit Price, Actual Filled Price) in the Output window of the PL editor. I also attached a text file containing the historical data, and the screenshots showing my strategy settings.
Please help investigate and explain why caused the error, and how it can be corrected.
Thanks,
McGeorge