Method to force a chart update

Created at 15 Feb 2021, 15:33
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

Method to force a chart update
15 Feb 2021, 15:33


Is there a method to force the update of the chart with text. 
I like to disp a progress indicator but the chart does not (always) react in the chart.drawtext("time "+Server.Time.Ticks)
Questions
1  what triggers a screenupdate in cTrader automate.

2 how can we force a screen update

 

Best rgds,

Ton


@Shares4us
Replies

... Deleted by UFO ...

PanagiotisCharalampous
16 Feb 2021, 08:15

Hi Share4us,

You need to do the update asynchronously. The below example might help you.

using System;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
using cAlgo.Indicators;
using System.Threading.Tasks;

namespace cAlgo
{
    [Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class NewIndicator : Indicator
    {
        protected override void Initialize()
        {
            Task.Factory.StartNew(() => { LongOperationWithProgress(); });
        }

        private void LongOperationWithProgress()
        {
            for (var i = 0; i < 100; i++)
            {
                UpdateProgress(i.ToString() + "%");
                System.Threading.Thread.Sleep(50);
            }
            UpdateProgress("Finished");
        }

        private void UpdateProgress(string message)
        {
            BeginInvokeOnMainThread(() => { Chart.DrawStaticText("progress", message, VerticalAlignment.Top, HorizontalAlignment.Left, Chart.ColorSettings.ForegroundColor); });
        }

        public override void Calculate(int index)
        {
            // Calculate value at specified index
            // Result[index] = ...
        }
    }
}

Best Regards,

Panagiotis 

Join us on Telegram


@PanagiotisCharalampous

Shares4us
16 Feb 2021, 15:12 ( Updated at: 16 Feb 2021, 15:34 )

RE:

tried that but gave a  cBot crashed: Error #16302605
funny, restarting the bot does not always give the error |:)  ??

 


@Shares4us

PanagiotisCharalampous
16 Feb 2021, 16:05

Hi Share4us,

Did you try the example as is or just incorporated in some other code?

Best Regards,

Panagiotis 

Join us on Telegram


@PanagiotisCharalampous

Shares4us
19 Feb 2021, 01:47

RE:

BeginInvokeonMainthread still crashes the bot intermediately.

I think there are severe threading designflaws.

for instance in a seperate thread 

Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index    

at System.ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument argument, ExceptionResource resource)    

at System.Collections.Generic.List`1.get_Item(Int32 index)    at cTrader.Automate.Small.V1.MarketApi.SmallBarsChartSource.cAlgo.API.Bars.get_Item(Int32 index)  

on a 
 Bar _lastBar = Bars.LastBar;

That's just not keeping your routines well closed.

 

 


@Shares4us

PanagiotisCharalampous
19 Feb 2021, 07:55

Hi Share4us,

We cannot reproduce this. Can you please share some source code?

Best Regards,

Panagiotis 

Join us on Telegram


@PanagiotisCharalampous