cAlgo.Time Question when running backtest with tick data

Created at 21 May 2024, 13:43
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
CL

Clark22

Joined 17.05.2024

cAlgo.Time Question when running backtest with tick data
21 May 2024, 13:43


Hi,

Sorry if these are noob questions, but for me the behaviours I'm encountering are unexpected.

Here I have a cbot that works when backtesting m1 data, but I have a failure under tick data from server setting.

M1 Data : cAlgo.Time == MyEventTime

Tick Data : cAlgo.Time != MyEventTime

 

Any idea why Time is both equal and not equal? The backtests both pass through the EconomicEventTime under all cases, cAlgo Time UTC and cBot UTC, just the data source used is different.

 

Thanks for the assistance.

 

Clark

protected override void OnStart()

        {




            #if DEBUG

                var result = System.Diagnostics.Debugger.Launch();

                if (result is false) {

                    Print("Debugger launch failed");

                } else {

                    Print("Debugging launched");

                }

               

            #else

                Print("Not Debugging");

            #endif



            Timer.Start(TimeSpan.FromSeconds(1));


            EconomicEventTime = new DateTime(

                Time.Year,

                5,

                13,

                3,

                0,0,0); // 13/05/2024 03:00 UTC

            Print("EventDateTime: {0}", EconomicEventTime);

            DateTime wakeUp = EconomicEventTime.AddMinutes(-1);

            Print("Wake up Time 1 minute before event: {0}", wakeUp);

            Sleep(wakeUp);

        }



        protected override void OnTimer()

        {

            Print("OnTimer: {0}", Time); <-- OUTPUT LOOKING GOOD 13/05/2024 03:00 UTC
            Print(Time.Equals(EconomicEventTime)); <-- FALSE ANYWAY

            if(Time.Equals(EconomicEventTime)) { <-- FAILING HERE FOR Tick, PASSING HERE FOR m1

                ExecuteMarketOrder(TradeType.Buy, SymbolName, stakeAsVolume, "Buy Order", StopLossInPips, TakeProfitInPips);  
            } 
		}

Tick data backtest OUTPUT:

13/05/2024 00:00:00.252 | Info | EventDateTime: 5/13/2024 3:00:00 AM
13/05/2024 00:00:00.252 | Info | Wake up Time 1 minute before event: 5/13/2024 2:59:00 AM
13/05/2024 00:00:00.252 | Info | Sleep started.
13/05/2024 02:59:00.252 | Info | Sleep finished.
13/05/2024 02:59:01.252 | Info | OnTimer: 5/13/2024 2:59:01 AM
13/05/2024 02:59:01.252 | Info | False
13/05/2024 02:59:02.252 | Info | OnTimer: 5/13/2024 2:59:02 AM

13/05/2024 03:00:00.252 | Info | OnTimer: 5/13/2024 3:00:00 AM
13/05/2024 03:00:00.252 | Info | False


@Clark22
Replies

Clark22
21 May 2024, 13:52

Okay,

I see the precision is different: 

Logging Tick .252

Logging m1 .000

What is the expectation from the OnTimer() method and the Time object then?


@Clark22