Static Label and Horizon Line free

by yomm0401 in category Other at 11/07/2020
Description
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;

namespace cAlgo.Indicators
{
    [Indicator(IsOverlay = true, AccessRights = AccessRights.None, AutoRescale = false)]

    public class StaticLabelandHorizonLine : Indicator
    {

        [Parameter("Line 1 price", Group = "Line 1", DefaultValue = 0, MinValue = 0)]
        public double Line1price { get; set; }

        [Parameter("Line 2 price", Group = "Line 2", DefaultValue = 0, MinValue = 0)]
        public double Line2price { get; set; }

        [Parameter("Line 3 price", Group = "Line 3", DefaultValue = 0, MinValue = 0)]
        public double Line3price { get; set; }

        [Parameter("Line 4 price", Group = "Line 4", DefaultValue = 0, MinValue = 0)]
        public double Line4price { get; set; }

        [Parameter("Label", Group = "Line 1")]
        public string lText1 { get; set; }

        [Parameter("Label", Group = "Line 2")]
        public string lText2 { get; set; }

        [Parameter("Label", Group = "Line 3")]
        public string lText3 { get; set; }

        [Parameter("Label", Group = "Line 4")]
        public string lText4 { get; set; }

        [Parameter("Color", Group = "Line 1", DefaultValue = "Black")]
        public string lColor1 { get; set; }

        [Parameter("Color", Group = "Line 2", DefaultValue = "Green")]
        public string lColor2 { get; set; }

        [Parameter("Color", Group = "Line 3", DefaultValue = "Red")]
        public string lColor3 { get; set; }

        [Parameter("Color", Group = "Line 4", DefaultValue = "Olive")]
        public string lColor4 { get; set; }

        [Parameter("Transparency", Group = "Line 1", DefaultValue = 255, MinValue = 0, MaxValue = 255)]
        public int Transparency1 { get; set; }

        [Parameter("Transparency", Group = "Line 2", DefaultValue = 255, MinValue = 0, MaxValue = 255)]
        public int Transparency2 { get; set; }

        [Parameter("Transparency", Group = "Line 3", DefaultValue = 255, MinValue = 0, MaxValue = 255)]
        public int Transparency3 { get; set; }

        [Parameter("Transparency", Group = "Line 4", DefaultValue = 255, MinValue = 0, MaxValue = 255)]
        public int Transparency4 { get; set; }

        [Parameter("Label Offset", Group = "Line 1", DefaultValue = 1)]
        public int lOffset1 { get; set; }

        [Parameter("Label Offset", Group = "Line 2", DefaultValue = 1)]
        public int lOffset2 { get; set; }

        [Parameter("Label Offset", Group = "Line 3", DefaultValue = 1)]
        public int lOffset3 { get; set; }

        [Parameter("Label Offset", Group = "Line 4", DefaultValue = 1)]
        public int lOffset4 { get; set; }

        [Parameter("Line Offset", Group = "Line 1", DefaultValue = 3, MinValue = 0)]
        public int Offset1 { get; set; }

        [Parameter("Line Offset", Group = "Line 2", DefaultValue = 5, MinValue = 0)]
        public int Offset2 { get; set; }

        [Parameter("Line Offset", Group = "Line 3", DefaultValue = 5, MinValue = 0)]
        public int Offset3 { get; set; }

        [Parameter("Line Offset", Group = "Line 4", DefaultValue = 5, MinValue = 0)]
        public int Offset4 { get; set; }

        [Parameter("Linestyle", Group = "Line 1", DefaultValue = LineStyle.Dots)]
        public LineStyle LineStyle1 { get; set; }

        [Parameter("Linestyle", Group = "Line 2", DefaultValue = LineStyle.Solid)]
        public LineStyle LineStyle2 { get; set; }

        [Parameter("Linestyle", Group = "Line 3", DefaultValue = LineStyle.Solid)]
        public LineStyle LineStyle3 { get; set; }

        [Parameter("Linestyle", Group = "Line 4", DefaultValue = LineStyle.Solid)]
        public LineStyle LineStyle4 { get; set; }

        [Parameter("Line tickness", Group = "Line 1", DefaultValue = 1, MinValue = 0)]
        public int thickness1 { get; set; }

        [Parameter("Line tickness", Group = "Line 2", DefaultValue = 1, MinValue = 0)]
        public int thickness2 { get; set; }

        [Parameter("Line tickness", Group = "Line 3", DefaultValue = 1, MinValue = 0)]
        public int thickness3 { get; set; }

        [Parameter("Line tickness", Group = "Line 4", DefaultValue = 1, MinValue = 0)]
        public int thickness4 { get; set; }

        public Color alphaColor1, alphaColor2, alphaColor3, alphaColor4;

        protected override void Initialize()
        {
            Color color1 = Color.FromName(lColor1);
            alphaColor1 = Color.FromArgb(Transparency1, color1.R, color1.G, color1.B);

            Color color2 = Color.FromName(lColor2);
            alphaColor2 = Color.FromArgb(Transparency2, color2.R, color2.G, color2.B);

            Color color3 = Color.FromName(lColor3);
            alphaColor3 = Color.FromArgb(Transparency3, color3.R, color3.G, color3.B);

            Color color4 = Color.FromName(lColor4);
            alphaColor4 = Color.FromArgb(Transparency4, color4.R, color4.G, color4.B);
        }

        public override void Calculate(int index)
        {
            if (Line1price > 0)
            {
                Chart.DrawTrendLine("Line1", index, Line1price, index + (-1 * Offset1), Line1price, alphaColor1, thickness1, LineStyle1);
                var text1 = Chart.DrawText("Label1", lText1, index + lOffset1, Line1price, lColor1);
                text1.VerticalAlignment = VerticalAlignment.Top;
                text1.HorizontalAlignment = HorizontalAlignment.Right;
            }
            if (Line2price > 0)
            {
                Chart.DrawTrendLine("Line2", index, Line2price, index + (-1 * Offset2), Line2price, alphaColor2, thickness2, LineStyle2);
                var text2 = Chart.DrawText("Label2", lText2, index + lOffset2, Line2price, lColor2);
                text2.VerticalAlignment = VerticalAlignment.Top;
                text2.HorizontalAlignment = HorizontalAlignment.Right;
            }
            if (Line3price > 0)
            {
                Chart.DrawTrendLine("Line3", index, Line3price, index + (-1 * Offset3), Line3price, alphaColor3, thickness3, LineStyle3);
                var text3 = Chart.DrawText("Label3", lText3, index + lOffset3, Line3price, lColor3);
                text3.VerticalAlignment = VerticalAlignment.Top;
                text3.HorizontalAlignment = HorizontalAlignment.Right;
            }
            if (Line4price > 0)
            {
                Chart.DrawTrendLine("Line4", index, Line4price, index + (-1 * Offset4), Line4price, alphaColor4, thickness4, LineStyle4);
                var text4 = Chart.DrawText("Label4", lText4, index + lOffset4, Line4price, lColor4);
                text4.VerticalAlignment = VerticalAlignment.Top;
                text4.HorizontalAlignment = HorizontalAlignment.Right;
            }
        }
    }
}
Comments
0