Screen/Chart/Display Update timing

Created at 11 Jun 2020, 13:34
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!
SH

Shares4us

Joined 01.04.2020

Screen/Chart/Display Update timing
11 Jun 2020, 13:34


@panagiotis:

The source.
What i can see is that the chart/display is not updated immediately but only when the tick finishes. 
And that Ticks are not processed parallel but in a serial manner skipping the events for ticks when the bot is busy.
My goal is to not wait until the tick-handling has finished but to force the chart to display the drawn text immediately.
 

using System;
using cAlgo.API;
using cAlgo.API.Requests;
using cAlgo.API.Internals;


namespace cAlgo
{
    [Robot(AccessRights = AccessRights.None)]
    public class Test5 : Robot
    {
 
        protected override void OnStart()
        {
           Chart.DrawStaticText("X", "Test" , VerticalAlignment.Top, HorizontalAlignment.Center, "FFFFFFFF");
        }

        bool         Done = false;
        protected override void OnTick()
        {
                Print("Tick");
                if (Done) 
                    return;

                Done = true;
                Chart.DrawStaticText("Y", "\nTest2" , VerticalAlignment.Top, HorizontalAlignment.Center, "FFFFFFFF");
                DateTime Until = DateTime.Now.AddSeconds(10);
                while(DateTime.Now<Until)
                    System.Threading.Thread.Sleep(1000);  
        }
    }
}

Hope you can help.


@Shares4us
Replies

PanagiotisCharalampous
11 Jun 2020, 14:46

Hi Ton,

This is by design. If you want to execute lengthy tasks better use another thread. See below

using System;
using cAlgo.API;
using cAlgo.API.Requests;
using cAlgo.API.Internals;


namespace cAlgo
{
    [Robot(AccessRights = AccessRights.None)]
    public class Test5 : Robot
    {

        protected override void OnStart()
        {
            Chart.DrawStaticText("X", "Test", VerticalAlignment.Top, HorizontalAlignment.Center, "FFFFFFFF");

        }
        bool Done = false;
        protected override void OnTick()
        {
            Print("Tick");
            Chart.DrawStaticText("Y", "\n" + Symbol.Bid, VerticalAlignment.Top, HorizontalAlignment.Center, "FFFFFFFF");
            if (Done)
                return;
            Done = true;
            var thread = new System.Threading.Thread(RunSomeTask);
            thread.Start();
        }

        private void RunSomeTask()
        {
            BeginInvokeOnMainThread(() => { Print("Thread started"); });

            DateTime Until = DateTime.Now.AddSeconds(10);
            while (DateTime.Now < Until)
            {
                BeginInvokeOnMainThread(() => { Chart.DrawStaticText("Time", DateTime.Now.ToString("HH:mm:ss.fff"), VerticalAlignment.Bottom, HorizontalAlignment.Center, "FFFFFFFF"); });
                System.Threading.Thread.Sleep(50);
            }
            Chart.DrawStaticText("Time", "Task Finished", VerticalAlignment.Bottom, HorizontalAlignment.Center, "FFFFFFFF");
            BeginInvokeOnMainThread(() => { Print("Thread finished"); });
        }
    }
}

Best Regards,

Panagiotis 

Join us on Telegram

 


@PanagiotisCharalampous

Shares4us
11 Jun 2020, 16:43

RE: I am already using that possibility for several projects.

My question was not about a lengthy task but about how cTrader works under the hood.

I hope you will update the docu on ticks with the serial & skip & chartupdate after the tick has been completely processed.

 


@Shares4us

PanagiotisCharalampous
11 Jun 2020, 16:56

Hi Ton,

Quoting below your words

My goal is to not wait until the tick-handling has finished but to force the chart to display the drawn text immediately.
Hope you can help.

and this is what I replied to. I helped you achieve your goal. 

Best Regards,

Panagiotis 

Join us on Telegram

 


@PanagiotisCharalampous

Shares4us
11 Jun 2020, 17:22

RE:

I hope you will update the docu on ticks with the serial & skip & chartupdate after the tick has been completely processed.


@Shares4us