Get Color Picker for parameter

09 Jun 2018, 22:48Get Color Picker for parameter#1
ADFXposts: 2since: 09 Jun 2018

Hi all,

I'm trying to get a color picker as parameter for my indicator. Should not be that dificult. Cannot use the enumerate Colors for some reason.

Help...

11 Jun 2018, 09:34#2
Panagiotis Charalampousposts: 1003since: 13 Jan 2017

Dear Trader,

Thanks for posting in our forum. This is currently not possible in cAlgo. A workaround is to get the Color as a string parameter and use the following function to convert the string to a Color

        //A function for getting the color from a string
        private Colors GetColor(string colorString)
        {
            foreach (Colors color in Enum.GetValues(typeof(Colors)))
            {
                if (color.ToString() == colorString)
                    return color;
            }
            return Colors.White;
        }

Let me know if this helps,

Best Regards,

Panagiotis


Head of Community Management at cTrader
13 Jun 2018, 13:44Workaround#3
ADFXposts: 2since: 09 Jun 2018

Is there another workaround, by retreiving the color from an IndicatorDataSeries ? In that case one could define a dataseries and use the settings for making lines.

13 Jun 2018, 14:11#4
Panagiotis Charalampousposts: 1003since: 13 Jan 2017

Hi ADFX,

It is not possible to retrieve the color of IndicatorDataSeries using cAlgo.

Best Regards,

Panagiotis Charalampous


Head of Community Management at cTrader
13 Jun 2018, 15:01RE:#5
afhackerposts: 30since: 15 Oct 2015

Panagiotis Charalampous said:

Dear Trader,

Thanks for posting in our forum. This is currently not possible in cAlgo. A workaround is to get the Color as a string parameter and use the following function to convert the string to a Color

        //A function for getting the color from a string
        private Colors GetColor(string colorString)
        {
            foreach (Colors color in Enum.GetValues(typeof(Colors)))
            {
                if (color.ToString() == colorString)
                    return color;
            }
            return Colors.White;
        }

Let me know if this helps,

Best Regards,

Panagiotis

 

Simple method:

        private Colors GetColor(string colorText, string colorParameterName)
        {
            Colors color;

            if (!Enum.TryParse(colorText, true, out color))
            {
                string errorObjName = string.Format("Your input for '{0}' parameter is incorrect", colorParameterName);

                ChartObjects.DrawText("Error", errorObjName, StaticPosition.Center, Colors.Red);

                // throw new ArgumentException(errorObjName);
            }

            return color;
        }

 


http://algodeveloper.com/