Are threads ok in cBots?

Created at 15 Apr 2019, 20:28
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!
DA

dalinar

Joined 03.04.2019

Are threads ok in cBots?
15 Apr 2019, 20:28


Is it safe to create a Thread from within a cBot? 

My problem is that putting my logic within OnTick() is not fast enough always since it depends on the speed of the tick

So I'm thining about putting it in a Thread or some kind of Timer, does cTrader supply a timer mechansim?

 

 


@dalinar
Replies

dalinar
15 Apr 2019, 20:29

note: I'm not going to open or close trades from within the thread


@dalinar

Waxy
15 Apr 2019, 21:52

You can do:
 

         protected override void OnStart()
        {
            Timer.Start(TimeSpan.FromMilliseconds(100));
        }
        
        protected override void OnTimer()
        {
            Print("Test");
        }

 

If you need more timers you could use the Timer inside System.Windows.Forms, I read that is also single threaded, read the documentation here:
https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.timer?view=netframework-4.7.2

The timers inside System.Timers are not single threaded and I think they're not safe.


@Waxy

Waxy
17 Apr 2019, 18:09

My bad tho, I tried it and it doesn't work outside forms, the one built in cTrader is enough for most tasks I think.


@Waxy