Measure Tool free

by Spotware in category Other at 16/12/2021
Description

This indicator allows you to measure an area of chart in terms of number of bars, amount of time, price delta, price percentage change, and volume.

Measure Tool is an open source indicator, if you want to contribute check our Github: spotware/Measure-Tool: cTrader chart measuring tool (github.com)

Changelog:

Version 1.2.0.0

Release Date: January 26, 2023

Changed: String color parameters to new Color type parameter

Note: This version only works on cTrader 4.6 or above.

Version 1.1.0.0

Release Date: December 20, 2022

Fixed: Issues with new versions of cTrader

Changed: Target framework from .NET 4 to 6

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 cAlgo.API;
using cAlgo.Controls;
using cAlgo.Helpers;
using cAlgo.Patterns;
using System.Collections.Generic;

namespace cAlgo
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.FullAccess)]
    public class MeasureTool : Indicator
    {
        private StackPanel _mainButtonsPanel;

        private StackPanel _mainPanel;

        private Style _buttonsStyle;

        private readonly List<Button> _buttons = new();

        #region Container Panel parameters

        [Parameter("Orientation", DefaultValue = Orientation.Vertical, Group = "Container Panel")]
        public Orientation PanelOrientation { get; set; }

        [Parameter("Horizontal Alignment", DefaultValue = HorizontalAlignment.Left, Group = "Container Panel")]
        public HorizontalAlignment PanelHorizontalAlignment { get; set; }

        [Parameter("Vertical Alignment", DefaultValue = VerticalAlignment.Top, Group = "Container Panel")]
        public VerticalAlignment PanelVerticalAlignment { get; set; }

        [Parameter("Margin", DefaultValue = 3, Group = "Container Panel")]
        public double PanelMargin { get; set; }

        #endregion Container Panel parameters

        #region Buttons parameters

        [Parameter("Disable Color", DefaultValue = "#FFCCCCCC", Group = "Buttons")]
        public Color ButtonsBackgroundDisableColor { get; set; }

        [Parameter("Enable Color", DefaultValue = "Red", Group = "Buttons")]
        public Color ButtonsBackgroundEnableColor { get; set; }

        [Parameter("Text Color", DefaultValue = "Blue", Group = "Buttons")]
        public Color ButtonsForegroundColor { get; set; }

        [Parameter("Margin", DefaultValue = 1, Group = "Buttons")]
        public double ButtonsMargin { get; set; }

        [Parameter("Transparency", DefaultValue = 0.5, MinValue = 0, MaxValue = 1, Group = "Buttons")]
        public double ButtonsTransparency { get; set; }

        #endregion Buttons parameters

        #region TimeFrame Visibility parameters

        [Parameter("Enable", DefaultValue = false, Group = "TimeFrame Visibility")]
        public bool IsTimeFrameVisibilityEnabled { get; set; }

        [Parameter("TimeFrame", Group = "TimeFrame Visibility")]
        public TimeFrame VisibilityTimeFrame { get; set; }

        [Parameter("Only Buttons", Group = "TimeFrame Visibility")]
        public bool VisibilityOnlyButtons { get; set; }

        #endregion TimeFrame Visibility parameters

        #region Measure parameters

        [Parameter("Up Color", DefaultValue = "700070C0", Group = "Measure")]
        public Color MeasureUpColor { get; set; }

        [Parameter("Down Color", DefaultValue = "70FE0000", Group = "Measure")]
        public Color MeasureDownColor { get; set; }
        
        [Parameter("Thickness", DefaultValue = 1, Group = "Measure")]
        public int MeasureThickness { get; set; }

        [Parameter("Style", DefaultValue = LineStyle.Solid, Group = "Measure")]
        public LineStyle MeasureStyle { get; set; }

        [Parameter("Filled", DefaultValue = true, Group = "Measure")]
        public bool MeasureIsFilled { get; set; }

        [Parameter("Text Color", DefaultValue = "Yellow", Group = "Measure")]
        public Color MeasureTextColor { get; set; }

        [Parameter("Font Size", DefaultValue = 10, Group = "Measure")]
        public int MeasureFontSize { get; set; }

        [Parameter("Text Bold", DefaultValue = true, Group = "Measure")]
        public bool MeasureIsTextBold { get; set; }

        #endregion Measure parameters

        #region Overridden methods

        protected override void Initialize()
        {
            _mainPanel = new StackPanel
            {
                HorizontalAlignment = PanelHorizontalAlignment,
                VerticalAlignment = PanelVerticalAlignment,
                Orientation = PanelOrientation == Orientation.Horizontal ? Orientation.Vertical : Orientation.Horizontal,
                BackgroundColor = Color.Transparent,
            };

            _mainButtonsPanel = new StackPanel
            {
                Orientation = PanelOrientation,
                Margin = PanelMargin
            };

            _mainPanel.AddChild(_mainButtonsPanel);
            
            _buttonsStyle = new Style();

            _buttonsStyle.Set(ControlProperty.Margin, ButtonsMargin);
            _buttonsStyle.Set(ControlProperty.BackgroundColor, ButtonsBackgroundDisableColor);
            _buttonsStyle.Set(ControlProperty.ForegroundColor, ButtonsForegroundColor);
            _buttonsStyle.Set(ControlProperty.HorizontalContentAlignment, HorizontalAlignment.Center);
            _buttonsStyle.Set(ControlProperty.VerticalContentAlignment, VerticalAlignment.Center);
            _buttonsStyle.Set(ControlProperty.Opacity, ButtonsTransparency);

            var patternConfig = new PatternConfig(Chart, Color.Transparent, true, Color.Transparent,
                true, true, new Logger(this.GetType().Name, Print));

            AddPatternButton(new MeasurePattern(patternConfig, new MeasureSettings
            {
                Thickness = MeasureThickness,
                Style = MeasureStyle,
                UpColor = MeasureUpColor,
                DownColor = MeasureDownColor,
                TextColor = MeasureTextColor,
                IsFilled = MeasureIsFilled,
                FontSize = MeasureFontSize,
                IsTextBold = MeasureIsTextBold
            }));

            Chart.AddControl(_mainPanel);

            CheckTimeFrameVisibility();
        }

        public override void Calculate(int index)
        {
        }

        #endregion Overridden methods

        private void AddPatternButton(IPattern pattern)
        {
            var button = new PatternButton(pattern)
            {
                Style = _buttonsStyle,
                OnColor = ButtonsBackgroundEnableColor,
                OffColor = ButtonsBackgroundDisableColor,
            };

            _buttons.Add(button);

            _mainButtonsPanel.AddChild(button);

            pattern.Initialize();
        }

        private void CheckTimeFrameVisibility()
        {
            if (IsTimeFrameVisibilityEnabled)
            {
                if (TimeFrame != VisibilityTimeFrame)
                {
                    _mainButtonsPanel.IsVisible = false;

                    if (!VisibilityOnlyButtons) Chart.ChangePatternsVisibility(true);
                }
                else if (!VisibilityOnlyButtons)
                {
                    Chart.ChangePatternsVisibility(false);
                }
            }
        }
    }
}
Comments

TommyDee - January 31, 2022 @ 14:52

Thank you!

0