Example with background color intensity free

by bennn in category Other at 13/11/2020
Description

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

Notification Publishing copyrighted material is strictly prohibited. If you believe there is copyrighted material in this section you may use the Copyright Infringement Notification form to submit a claim.
Formula / Source Code
Language: C#
Trading Platform: cAlgocTrader
´╗┐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)
        {
        }
    }
}
Comments
0