Category Other  Published on 13/11/2020

Example with background color intensity

Description

Example with background color intensity with intensity value from 0 to 100


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

namespace cAlgo
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class IntensityColor : Indicator
    {
        [Parameter("Intensity (0 - 100)", DefaultValue = 100, MaxValue = 100, MinValue = 0, Step = 1)]
        public double Intensity { get; set; }

        [Parameter("Origincal color (RGB or ARGB)", DefaultValue = "#000000")]
        public string OriginalColor { get; set; }

        [Parameter("Target color (RGB or ARGB)", DefaultValue = "#00FF00")]
        public string TargetColor { get; set; }


        protected override void Initialize()
        {
            var originalColor = Color.FromHex(OriginalColor);
            var targerColor = Color.FromHex(TargetColor);
            var intensity = Math.Max(0, Math.Min(100, Intensity));

            var rDiff = Math.Max(0, targerColor.R - originalColor.R);
            var gDiff = Math.Max(0, targerColor.G - originalColor.G);
            var bDiff = Math.Max(0, targerColor.B - originalColor.B);

            var a = originalColor.A;
            var r = originalColor.R + rDiff * intensity / 100;
            var g = originalColor.G + gDiff * intensity / 100;
            var b = originalColor.B + bDiff * intensity / 100;

            var colorWithIntensity = Color.FromArgb(a, (int)r, (int)g, (int)b);
            Chart.ColorSettings.BackgroundColor = colorWithIntensity;
        }

        public override void Calculate(int index)
        {
        }
    }
}


BE
bennn

Joined on 06.03.2019

  • Distribution: Free
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: IntensityColor.algo
  • Rating: 0
  • Installs: 1088
  • Modified: 13/10/2021 09:55
Comments
Log in to add a comment.
No comments found.