Get Color Picker for parameter

Created at 09 Jun 2018, 22:48
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!
ADFX's avatar

ADFX

Joined 09.06.2018

Get Color Picker for parameter
09 Jun 2018, 22:48


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...


@ADFX
Replies

PanagiotisCharalampous
11 Jun 2018, 09:34

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


@PanagiotisCharalampous

ADFX
13 Jun 2018, 13:44

Workaround

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.


@ADFX

PanagiotisCharalampous
13 Jun 2018, 14:11

Hi ADFX,

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

Best Regards,

Panagiotis Charalampous


@PanagiotisCharalampous

afhacker
13 Jun 2018, 15:01

RE:

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;
        }

 


@afhacker