Category Other  Published on 01/06/2022

Price Tag

Description

This indicator allows you to tag a price level, it shows the price with an arrow based on price distance from the bars.

 

Features

  • You can customize the appearance
  • Use any of the modifier keys you want to as hotkey
  • Changes on indicator parameters take effect on current added price tags
  • Shows an up arrow if price level was below the bar low or down arrow if price was above bar high

 

Usage

  1. Add indicator on a chart
  2. Press shift and click somewhere on the chart, you can change the key from indicator parameters

Note: When you change the indicator parameters the change will effect all existing price tags, to avoid this add something to price tag comment and that price tag style will not change even if you change the indicator parameters like font size or color.

This indicator is open source, feel free to improve it: spotware/Price-Tag: This is a cTrader desktop indicator for showing price levels on the chart (github.com)

 


using System;
using cAlgo.API;
using cAlgo.API.Internals;
using System.Linq;

namespace cAlgo
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class PriceTag : Indicator
    {
        private Color _color;
        private const string OBJECTS_NAME_PREFIX = "PriceTag";

        [Parameter("Modifier", DefaultValue = ModifierKeys.Shift, Group = "Hotkey")]
        public ModifierKeys HotkeyModifier { get; set; }

        [Parameter("Name/Code", DefaultValue = "Red", Group = "Color")]
        public string ColorName { get; set; }

        [Parameter("Alpha", DefaultValue = 255, MinValue = 0, MaxValue = 255, Group = "Color")]
        public int ColorAlpha { get; set; }

        [Parameter("Font Size", DefaultValue = 10, MinValue = 0, Step = 1, Group = "Text")]
        public double FontSize { get; set; }

        protected override void Initialize()
        {
            _color = GetColor(ColorName, ColorAlpha);

            var priceTags = from chartObject in Chart.Objects
                            where chartObject.Name.StartsWith(OBJECTS_NAME_PREFIX, StringComparison.Ordinal)
                            where string.IsNullOrWhiteSpace(chartObject.Comment)
                            select chartObject as ChartText;

            foreach (var priceTag in priceTags)
            {
                priceTag.Color = _color;
                priceTag.FontSize = FontSize;
            }

            Chart.ObjectsUpdated += Chart_ObjectsUpdated;
            Chart.MouseDown += Chart_MouseDown;
        }

        private void Chart_ObjectsUpdated(ChartObjectsUpdatedEventArgs obj)
        {
            foreach (var updatedObject in obj.ChartObjects)
            {
                if ((updatedObject is ChartText) == false
                    || !updatedObject.Name.StartsWith(OBJECTS_NAME_PREFIX, StringComparison.Ordinal))
                {
                    continue;
                }

                var chartText = updatedObject as ChartText;

                SetPrice(chartText);
            }
        }

        private void Chart_MouseDown(ChartMouseEventArgs obj)
        {
            if ((HotkeyModifier == ModifierKeys.Alt && !obj.AltKey)
                || (HotkeyModifier == ModifierKeys.Control && !obj.CtrlKey)
                || (HotkeyModifier == ModifierKeys.Shift && !obj.ShiftKey))
            {
                return;
            }

            AddPriceTag(obj.TimeValue, obj.YValue, _color);
        }

        public override void Calculate(int index)
        {
        }

        private Color GetColor(string colorString, int alpha = 255)
        {
            var color = colorString[0] == '#' ? Color.FromHex(colorString) : Color.FromName(colorString);

            return Color.FromArgb(alpha, color);
        }

        private void AddPriceTag(DateTime time, double yValue, Color color)
        {
            var name = string.Format("PriceTag_{0}", DateTime.UtcNow.Ticks);

            var text = Chart.DrawText(name, string.Empty, time, yValue, color);
            text.IsInteractive = true;
            text.IsLocked = true;
            text.FontSize = FontSize;

            SetPrice(text);
        }

        private void SetPrice(ChartText chartText)
        {
            var barIndex = Bars.OpenTimes.GetIndexByTime(chartText.Time);

            var arrowType = string.Empty;

            if (chartText.Y < Bars.LowPrices[barIndex])
            {
                arrowType = "↑ ";
            }
            else if (chartText.Y > Bars.LowPrices[barIndex])
            {
                arrowType = "↓ ";
            }

            chartText.Text = string.Format("{0}{1}", arrowType, Math.Round(chartText.Y, Symbol.Digits));
        }
    }
}

Spotware's avatar
Spotware

Joined on 23.09.2013

  • Distribution: Free
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: Price Tag.algo
  • Rating: 0
  • Installs: 1057
Comments
Log in to add a comment.
MA
marlener.deanda · 1 year ago

When it comes to choosing an essay writing service online, the price tag can be a major deciding factor. However, it's important to remember that the cheapest option may not always be the best. Look for a service that offers a balance of affordability and quality. Reading reviews and checking for guarantees can also help ensure that you get a good value for your money. Ultimately, investing in a reliable and trustworthy essay writing service can save you time and stress in the long run.

EL
elisjohn64 · 1 year ago

The informative articles and threads are really helpful and beneficial to the individuals. They can get significant help and informative stuff from these articles. The people working for the how to watch channel 4 in canada also tend to read such articles and blogs to enhance their knowledge and information.

IT
itsalexjim · 1 year ago

The rule, “assignment book always goes home” is vital in pay someone to do my programming homework. You may forget to do homework if you do not keep assignment book with you.