0
Votes

System Timer and Stopwatch Support

Vote  

17 Dec 2018, 20:53System Timer and Stopwatch Support#1
westend.tradingposts: 7since: 12 Aug 2018

Dear Spotware-Team,

a great but missing feature in my opinion is the support of a proper system time reference which also works in backtest.
Using Stopwatch and Timer events will not work in backtest but they are quite fundamental features for many operations.

The important thing is to have precise reference source. It should not be too much of an effort in my humble opinion.

Thanks in advance.

Ben

 

18 Dec 2018, 09:39#2
Panagiotis Charalampousposts: 2978since: 13 Jan 2017

Hi Ben,

Thank you for posting in our forum and for sharing yor suggestion. Please note that cTrader Automate API features its own Timer class which works in backtesting as well.

Best Regards,

Panagiotis


Head of Community Management at cTrader
19 Dec 2018, 20:53#3
westend.tradingposts: 7since: 12 Aug 2018

Hi Panagiotis,

thank you for the quick response!
Can I assume it to run precisely in millisecond range?
The signal processing I intent to implement requires a very reliable reference clock. In realtime mode, this is no problem but results in backtest seem to be unrealistic.

How can I get the server timestamp of incoming ticks in backtest and normal operation mode?
Is it possible at all?

Best regards,

Ben

20 Dec 2018, 09:44#4
Panagiotis Charalampousposts: 2978since: 13 Jan 2017

Hi Ben,

Yes it will be accurate, you can verify it with the following experiment

using System;
using System.Linq;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;

namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class NewcBot : Robot
    {
        [Parameter(DefaultValue = 0.0)]
        public double Parameter { get; set; }

        protected override void OnStart()
        {
            Timer.Start(new TimeSpan(10000));
            Timer.TimerTick += OnTimerTimerTick;
        }

        void OnTimerTimerTick()
        {
            Print(Server.Time.Hour + ":" + Server.Time.Minute + ":" + Server.Time.Second + ":" + Server.Time.Millisecond);
        }

        protected override void OnTick()
        {

        }

        protected override void OnStop()
        {
            // Put your deinitialization logic here
        }
    }
}

Regarding the timestamp, check here how you can get the timestamp in C#.

Best Regards,

Panagiotis


Head of Community Management at cTrader
04 Jan 2019, 22:03#5
westend.tradingposts: 7since: 12 Aug 2018

Hi Panagiotis,

thanks for the hint.

Server.Time

actually solves the issue. And the Timer class is working precisely as well.

Is it possible to acquire the specific timestamps of past price ticks as well when creating an indicator or does this only work for a robot (including backtesting)?

Thank you again.

Best regards,

Benjamin

07 Jan 2019, 09:36#6
Panagiotis Charalampousposts: 2978since: 13 Jan 2017

Hi Ben,

An indicator's Calculate method is called only on each bar for past bars and on each tick for the current bar. So using an indicator you can obtain such information only for the current bar. So it is not possible to acquire this information without using backtesting.

Best Regards,

Panagiotis

 


Head of Community Management at cTrader
09 Jan 2019, 19:51#7
westend.tradingposts: 7since: 12 Aug 2018

Hi Panagiotis,

thank you again. This is what I expected. Will find a workaround for this.

Nonetheless I can run a robot that e.g. calculates time between incoming ticks and processes this data somehow. This works for simple backtesting precisely as far as I can verify. But runnning the same robot in Optimization mode (using same parameter and a dummy value for optimization) fails. The robot does not open any position in optimization mode. In backtest it works fine.

Can you please comment on that?

Best regards,

Ben

10 Jan 2019, 17:04#8
Panagiotis Charalampousposts: 2978since: 13 Jan 2017

Hi Ben,

I will need to have the robot to comment on this. Can you post it?

Best Regards,

Panagiotis


Head of Community Management at cTrader
10 Jan 2019, 22:11#9
westend.tradingposts: 7since: 12 Aug 2018

Hi Panagiotis,

I was just preparing the code to post (it is huge and I was removing all parts not related to the issue). Funny thing is: the stripped down version works in optimization mode.
Only non-relevant parts have been removed.

Backtest looks like this:
Screenshot Backtest

Optimization mode (same parameter, modifying one value only) -no output:

Core feature is a incoming tick data histogram.

Weird.

Best regards,

Ben

11 Jan 2019, 10:24#10
Panagiotis Charalampousposts: 2978since: 13 Jan 2017

Hi Ben,

So probably the problem in the non relevant parts :)

Best Regards,

Panagiotis


Head of Community Management at cTrader