Category Other  Published on 25/08/2020

Area chart with watermark

Description

This indicator replace bars with area chart and adds a watermark with symbol name and period.

Text parameters of the watermark are configurable.


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

namespace cAlgo
{
    [Cloud("Main", "Zero")]
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AutoRescale = false, AccessRights = AccessRights.None)]
    public class AreaChart : Indicator
    {
        [Parameter("Show watermark", DefaultValue = true)]
        public bool IsWatermarkVisible { get; set; }

        [Parameter("Font size", DefaultValue = 40, MinValue = 1, MaxValue = 999)]
        public int FontSize { get; set; }

        [Parameter("Font weight", DefaultValue = 7)]
        public FontWeight FontWeight { get; set; }

        [Parameter("Text color", DefaultValue = "#10FFFFFF")]
        public string ForegroundColor { get; set; }

        [Output("Main", LineColor = "#FF40E0D0")]
        public IndicatorDataSeries MainResult { get; set; }

        [Output("Zero", LineColor = "#00FFFFFF")]
        public IndicatorDataSeries ZeroResult { get; set; }


        protected override void Initialize()
        {
            if (IsWatermarkVisible)
            {
                DrawWatermark();
            }
        }

        public override void Calculate(int index)
        {
            Chart.SetBarColor(index, Color.Transparent);
            MainResult[index] = Bars.ClosePrices[index];
            ZeroResult[index] = 0;
        }

        private void DrawWatermark()
        {
            var text = string.Format("{0}, {1}", SymbolName, TimeFrame);
            var textBlock = new TextBlock 
            {
                VerticalAlignment = VerticalAlignment.Center,
                HorizontalAlignment = HorizontalAlignment.Center,
                Text = text,
                ForegroundColor = ForegroundColor,
                FontSize = FontSize,
                FontWeight = FontWeight,
                IsHitTestVisible = false
            };
            Chart.AddControl(textBlock);
        }
    }
}


BE
bennn

Joined on 06.03.2019

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