Chart.FindAllObjects() Crashes when there is a Fibonacci Timezones on the Chart.

Created at 12 Apr 2023, 10:02
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!
vegaxlr's avatar

vegaxlr

Joined 14.02.2023

Chart.FindAllObjects() Crashes when there is a Fibonacci Timezones on the Chart.
12 Apr 2023, 10:02


 I'm trying to get all the Fibonacci Timezones on the chart with Chart.FindAllObjects(), but the indicator crashes when there is a Fibonacci Timezones on the chart. This crash only happens with Fibonacci Timezones as far as I know. I tried creating a new indicator and placing one single line of code on the Initialize method to test this.

The line of code I used is:

var myFibTimezonesChartObjects = Chart.FindAllObjects(ChartObjectType.FibonacciTimezones);

 

Here is the error:

Crashed in Initialize with ArgumentOutOfRangeException: Exception of type 'System.ArgumentOutOfRangeException' was thrown. (Parameter 'chartObjectType') Actual value was FibonacciTimezones.

 

Then I tried another way, but it still crashes.

List<ChartFibonacciTimezones> myFibTimeZonesList = new List<ChartFibonacciTimezones>();


            foreach (ChartObject obj in Chart.Objects)
            {

                if (obj.ObjectType == ChartObjectType.FibonacciTimezones)
                {
                    Print("  TEST !!!!!!!!!!!!!"); //<<<<<<---------------- This never prints
                    ChartFibonacciTimezones fibTimeZones = (ChartFibonacciTimezones)obj;
                    myFibTimeZonesList.Add(fibTimeZones);
                }
            }


            ChartFibonacciTimezones[] myFibTimeZonesArray = myFibTimeZonesList.ToArray();

 

The only way it doesn't crash is if i find the object by name, but that doesn't help me.


@vegaxlr
Replies

pick
13 Apr 2023, 13:24

This issue also appears on my end when calling to obj.ObjectType on a FibonacciTimezone. Below I will include a crude workaround, but don't rely on this to work going forward - hopefully an official change can be made in the near future.

if (obj.GetType().ToString().Equals("cTrader.Automate.Adapters.ChartApi.ChartObjects.ChartFibonacciTimezonesAdapter"))
{
	Print("Found fibTimzones: " + obj.Name);
	ChartFibonacciTimezones fibTimeZones = (ChartFibonacciTimezones)obj;
	myFibTimeZonesList.Add(fibTimeZones);
}

 


@pick