Colors/Color issues with code

Created at 14 Aug 2024, 13:39
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!
DA

danerius

Joined 07.01.2024

Colors/Color issues with code
14 Aug 2024, 13:39


 

Hi. Ive created this code with ChatGPT and theres one issue that I neither me or ChatGPT can get our head around. Heres the error message:

Argument 6: cannot convert from 'cAlgo.API.Color' to 'cAlgo.API.Colors'

Best regards /danerius

using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;

namespace cAlgo
{
   [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
   public class FibonacciEMAs : Indicator
   {
       // Input parameters for the EMAs
       [Parameter("EMA 1 Period (5)", DefaultValue = 5)]
       public int Period1 { get; set; }

       [Parameter("EMA 2 Period (8)", DefaultValue = 8)]
       public int Period2 { get; set; }

       [Parameter("EMA 3 Period (13)", DefaultValue = 13)]
       public int Period3 { get; set; }

       [Parameter("EMA 4 Period (21)", DefaultValue = 21)]
       public int Period4 { get; set; }

       [Parameter("EMA 5 Period (34)", DefaultValue = 34)]
       public int Period5 { get; set; }

       [Parameter("EMA 6 Period (55)", DefaultValue = 55)]
       public int Period6 { get; set; }

       [Parameter("EMA 7 Period (89)", DefaultValue = 89)]
       public int Period7 { get; set; }

       [Parameter("EMA 8 Period (144)", DefaultValue = 144)]
       public int Period8 { get; set; }

       // Input parameter for color customization
       [Parameter("EMA Color", DefaultValue = "White")]
       public string EMAColorName { get; set; }

       // Property to convert string to Color
       public Color EMAColor => Color.FromName(EMAColorName);

       // Input parameter for line thickness and transparency
       [Parameter("Line Thickness", DefaultValue = 2)]
       public int Thickness { get; set; }

       [Parameter("Transparency (0-255)", DefaultValue = 100, MinValue = 0, MaxValue = 255)]
       public int Transparency { get; set; }

       private ExponentialMovingAverage[] _emas;

       protected override void Initialize()
       {
           _emas = new ExponentialMovingAverage[8];
           _emas[0] = Indicators.ExponentialMovingAverage(Bars.ClosePrices, Period1);
           _emas[1] = Indicators.ExponentialMovingAverage(Bars.ClosePrices, Period2);
           _emas[2] = Indicators.ExponentialMovingAverage(Bars.ClosePrices, Period3);
           _emas[3] = Indicators.ExponentialMovingAverage(Bars.ClosePrices, Period4);
           _emas[4] = Indicators.ExponentialMovingAverage(Bars.ClosePrices, Period5);
           _emas[5] = Indicators.ExponentialMovingAverage(Bars.ClosePrices, Period6);
           _emas[6] = Indicators.ExponentialMovingAverage(Bars.ClosePrices, Period7);
           _emas[7] = Indicators.ExponentialMovingAverage(Bars.ClosePrices, Period8);
       }

       public override void Calculate(int index)
       {
           for (int i = 0; i < _emas.Length; i++)
           {
               ChartObjects.DrawLine($"EMA{i + 1}", index - 1, _emas[i].Result[index - 1], index, _emas[i].Result[index],
                   Color.FromArgb(Transparency, EMAColor.ToArgb()), Thickness, LineStyle.Solid);
           }
       }
   }
}

 


@danerius
Replies

firemyst
15 Aug 2024, 01:04 ( Updated at: 15 Aug 2024, 05:20 )

Stop making it hard on yourself.

Change your parameter “EMA Color” to a “Color” parameter and use that. 

Examples here: https://help.ctrader.com/ctrader-algo/guides/parameter-types/#cbot-examples

 


@firemyst