Tiger.com Windows Wiki
English
English
  • πŸ‘‹Welcome!
  • ⭐How to start?
    • Recommended system requirements
    • Register and setup
    • Licenses and login
  • βš™οΈSettings
    • Workspace
    • Trading modes
    • Connections
      • Crypto exchanges
        • TigerX
        • Binance via Tiger.com Broker
        • Bybit via Tiger.com Broker
        • Binance
        • Bitfinex
        • BitMEX
        • Bybit
        • OKX
        • Gate.io
        • MEXC
      • Trading terminals
        • DataFeed
        • MetaTrader 5
        • OEC Trader (GAIN Capital)
        • Rithmic
        • QUIK
        • SmartCOM
        • Trader WorkStation (Interactive Brokers)
        • Transaq Connector
    • Basic setup
      • Selecting a symbol
      • Selecting a timeframe
      • Linking windows
      • Setting up exit strategies
      • Setting offsets
    • Terminal
      • Order volumes preset
      • Configuration
        • How to create public configuration
      • General settings
      • Email notifications
      • Telegram alerts
      • Hotkeys Manager
      • Sound alerts
      • Symbols manager
  • πŸ–₯️Windows
    • Chart
      • Chart trading
      • Toolbar setup
      • Chart theme
      • Chart settings
      • Scaling and moving the chart
      • Cluster chart
      • Cluster presets
      • Graphical objects in Chart window
        • Text
        • Ruler
        • Volume profile
        • Trend angle
        • Elliott Correction Wave
        • Elliott Impulse Wave
        • Fibonacci Fan
        • Fibonacci Extensions
        • Fibonacci Retracement
        • Fibonacci Time Zones
        • Linear Regression
      • Main indicators in Chart window
        • Bar Search
        • Bar Timer
        • Bid Ask
        • Big Trades
        • BW MFI
        • Cluster Search
        • Cluster Statistic
        • Cumulative Delta
        • Delta
        • Depth Of Market
        • Dynamic Levels
        • Elders Force Index
        • External Chart
        • Gradient
        • Heatmap
        • High Low
        • Histogram
        • Ichimoku
        • Margin Zones
        • Maximum Levels
        • Open Interest
        • Price
        • Session Color
        • Trades Flow
        • Volume
        • Volume Profile
        • VWAP
        • Weis Wave Volume
        • ZigZag
    • DOM
      • Selecting a trading account
      • Ruler
      • Multiplier
      • DOM settings
        • Main
        • Cluster
        • Trading
      • Stop Loss
      • Take Profit
      • Trigger orders
    • Watchlist
      • How to filter watchlist
    • SmartTape
    • Statistics
    • Volume search
    • All prices
    • Options board
  • πŸ“‹Tables
    • Orders
    • Executions
    • Positions
    • XPositions
    • Accounts
    • Limits
    • Player
    • Signals
    • Log
  • πŸ”Video Tutorials
    • Terminal Basics
    • Charts and technical analysis
    • Charts, Trade Tape and Player
    • Trading in Tiger.com Windows
  • πŸ’‘Platform Updates
    • Version 7.0 Beta
    • Version 6.9
    • Version 6.8
    • Version 6.7
    • Version 6.6
    • Version 6.5
    • Version 6.4
    • Version 6.3
    • Version 6.2
    • Version 6.1
    • Version 6.0.2
    • Version 6.0.1
    • Version 6.0.0
    • Version 5.0.7
    • Version 4.5.15
  • ⌨️Development for Tiger.com Windows
    • Indicator examples
      • DepthOfMarket
      • Trades Flow
      • Volume Profiles
      • Cluster Search
      • Bar Search
      • VWAP
      • Bar Timer
      • Volume
      • Trades
      • Session color
      • Open Interest
      • Dynamic Levels
      • Delta
      • Cumulative Delta
      • Cluster Statistic
      • Bid Ask
      • External Chart
      • High Low
      • Histogram
    • Source examples
      • Moving Average
      • Stock
    • Examples of graphical objects
      • Fibonacci Extensions
      • Fibonacci Retracement
      • Vertical Line
      • Horizontal Line
      • Volume Profile
      • Rectangle
  • ❓Frequently Asked Questions
    • Questions about licenses
    • Questions about indicators
    • Questions about connections
    • Questions about trading
    • Error "Connection lost" when launching the terminal
    • Why do I need to set commission in the terminal?
    • How does automatic account selection work?
    • How do I optimize the terminal to improve performance?
    • How to use the Crypto license to trade on Binance
    • Which order types are available in Tiger.com?
    • How to set up chart auto-refresh for QUIK connection?
    • How do I enable Take Profit orders on Binance?
    • How does autoselection of data type work?
    • Troubles installing the terminal
    • What are the system requirements for the terminal?
    • How to provide Tiger.com Windows app logs for investigation?
    • Fixing Network Issues: How to Adjust DNS Settings
  • πŸ“¬Technical support
  • πŸ’­Suggest an improvement
Powered by GitBook
On this page
  1. Development for Tiger.com Windows
  2. Examples of graphical objects

Horizontal Line

//------------------------------------------------------------------------------
//
// ГрафичСский ΠΎΠ±ΡŠΠ΅ΠΊΡ‚ HorizontalLine. Copyright (c) 2023 Tiger Trade Capital AG. All rights reserved.
//
//------------------------------------------------------------------------------
 
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Runtime.Serialization;
using System.Windows;
using System.Windows.Media;
using TigerTrade.Chart.Alerts;
using TigerTrade.Chart.Base;
using TigerTrade.Chart.Base.Enums;
using TigerTrade.Chart.Indicators.Common;
using TigerTrade.Chart.Objects.Common;
using TigerTrade.Chart.Objects.Enums;
using TigerTrade.Core.Utils.Logging;
using TigerTrade.Dx;
using TigerTrade.Dx.Enums;
 
namespace TigerTrade.Chart.Objects.Custom
{
    [DataContract(Name = "HorizontalLineObject", Namespace = "http://schemas.datacontract.org/2004/07/TigerTrade.Chart.Objects.Custom")]
    [ChartObject("X_HorizontalLine", "Π“ΠΎΡ€ΠΈΠ·ΠΎΠ½Ρ‚Π°Π»ΡŒΠ½Π°Ρ линия", 1, Type = typeof(HorizontalLineObject))]
    public class HorizontalLineObject : ObjectBase
    {
        [Category("Π¦Π΅Π½Π°"), DisplayName("Π¦Π΅Π½Π°")]
        public decimal Price
        {
            get => (decimal)ControlPoints[0].Y;
            set
            {
                if (value == (decimal)ControlPoints[0].Y)
                {
                    return;
                }
 
                ControlPoints[0].Y = (double)value;
 
                OnPropertyChanged();
                OnPropertyChanged(nameof(ControlPoints));
            }
        }
 
        private ChartAlertSettings _alert;
 
        [DataMember(Name = "Alert")]
        [Category("ΠžΠΏΠΎΠ²Π΅Ρ‰Π΅Π½ΠΈΠ΅"), DisplayName("ΠžΠΏΠΎΠ²Π΅Ρ‰Π΅Π½ΠΈΠ΅")]
        public ChartAlertSettings Alert
        {
            get => _alert ?? (_alert = new ChartAlertSettings());
            set
            {
                if (Equals(value, _alert))
                {
                    return;
                }
 
                _alert = value;
 
                OnPropertyChanged();
            }
        }
 
        private int _alertMinDistance;
 
        [DataMember(Name = "AlertMinDistance")]
        [Category("ΠžΠΏΠΎΠ²Π΅Ρ‰Π΅Π½ΠΈΠ΅"), DisplayName("Мин. расстояниС")]
        public int AlertMinDistance
        {
            get => _alertMinDistance;
            set
            {
                if (value == _alertMinDistance)
                {
                    return;
                }
 
                _alertMinDistance = value;
 
                OnPropertyChanged();
            }
        }
 
        private string _text;
 
        [DataMember(Name = "Text")]
        [Category("ВСкст"), DisplayName("ВСкст")]
        public string Text
        {
            get => _text;
            set
            {
                if (value == _text)
                {
                    return;
                }
 
                _text = value;
 
                OnPropertyChanged();
            }
        }
 
        private ObjectTextAlignment _textAlignment;
 
        [DataMember(Name = "TextAlignment")]
        [Category("ВСкст"), DisplayName("РасполоТСниС")]
        public ObjectTextAlignment TextAlignment
        {
            get => _textAlignment;
            set
            {
                if (value == _textAlignment)
                {
                    return;
                }
 
                _textAlignment = value;
 
                OnPropertyChanged();
            }
        }
 
        private int _fontSize;
 
        [DataMember(Name = "FontSize")]
        [Category("ВСкст"), DisplayName("Π Π°Π·ΠΌΠ΅Ρ€")]
        public int FontSize
        {
            get => _fontSize;
            set
            {
                value = Math.Max(10, Math.Min(100, value));
 
                if (value == _fontSize)
                {
                    return;
                }
 
                _fontSize = value;
 
                OnPropertyChanged();
            }
        }
 
        private XBrush _lineBrush;
 
        private XPen _linePen;
 
        private XColor _lineColor;
 
        [DataMember(Name = "LineColor")]
        [Category("Линия"), DisplayName("Π¦Π²Π΅Ρ‚ Π»ΠΈΠ½ΠΈΠΈ")]
        public XColor LineColor
        {
            get => _lineColor;
            set
            {
                if (value == _lineColor)
                {
                    return;
                }
 
                _lineColor = value;
 
                _lineBrush = new XBrush(_lineColor);
                _linePen = new XPen(_lineBrush, LineWidth, LineStyle);
 
                OnPropertyChanged();
            }
        }
 
        private int _lineWidth;
 
        [DataMember(Name = "LineWidth")]
        [Category("Линия"), DisplayName("Π’ΠΎΠ»Ρ‰ΠΈΠ½Π° Π»ΠΈΠ½ΠΈΠΈ")]
        public int LineWidth
        {
            get => _lineWidth;
            set
            {
                value = Math.Max(1, Math.Min(10, value));
 
                if (value == _lineWidth)
                {
                    return;
                }
 
                _lineWidth = value;
 
                _linePen = new XPen(_lineBrush, _lineWidth, LineStyle);
 
                OnPropertyChanged();
            }
        }
 
        private XDashStyle _lineStyle;
 
        [DataMember(Name = "LineStyle")]
        [Category("Линия"), DisplayName("Π‘Ρ‚ΠΈΠ»ΡŒ Π»ΠΈΠ½ΠΈΠΈ")]
        public XDashStyle LineStyle
        {
            get => _lineStyle;
            set
            {
                if (value == _lineStyle)
                {
                    return;
                }
 
                _lineStyle = value;
 
                _linePen = new XPen(_lineBrush, LineWidth, _lineStyle);
 
                OnPropertyChanged();
            }
        }
 
        protected override int PenWidth => LineWidth;
 
        private Rect _lineRect;
 
        public HorizontalLineObject()
        {
            AlertMinDistance = 3;
 
            Text = "";
            TextAlignment = ObjectTextAlignment.RightTop;
 
            FontSize = 14;
 
            LineColor = Colors.Black;
            LineWidth = 1;
            LineStyle = XDashStyle.Solid;
        }
 
        protected override void Draw(DxVisualQueue visual, ref List<ObjectLabelInfo> labels)
        {
            if (Canvas == null)
            {
                return;
            }
 
            var point = ToPoint(ControlPoints[0]);
 
            var startPoint = new Point(Canvas.Rect.Left, point.Y);
            var endPoint = new Point(Canvas.Rect.Right, point.Y);
 
            _lineRect = new Rect(startPoint, endPoint);
 
            if (Settings.TransformHorLines && Canvas.IsStock &&
                Canvas.StockType == ChartStockType.Clusters)
            {
                var y = ControlPoints[0].Y;
 
                var step = DataProvider.Step;
 
                var price = (long)Math.Round(y / step);
 
                var y1 = GetY((price + .5) * step);
                var y2 = GetY((price - .5) * step);
 
                if (y2 - y1 > LineWidth + 2)
                {
                    var brush = new XBrush(LineColor, LineColor.Alpha > 127 ? 127 : LineColor.Alpha);
 
                    _lineRect = new Rect(new Point(startPoint.X, y1), new Point(endPoint.X, y2));
 
                    visual.FillRectangle(brush, _lineRect);
 
                    DrawText(visual);
 
                    labels.Add(new ObjectLabelInfo(price * step, y1, y2, LineColor));
 
                    return;
                }
            }
 
            visual.DrawLine(_linePen, startPoint, endPoint);
 
            DrawText(visual);
 
            labels.Add(new ObjectLabelInfo(ControlPoints[0].Y, LineColor));
        }
 
        protected void DrawText(DxVisualQueue visual)
        {
            if (string.IsNullOrEmpty(Text) || TextAlignment == ObjectTextAlignment.Hide)
            {
                return;
            }
 
            var font = new XFont(Canvas.ChartFont.Name, FontSize);
 
            var textSize = font.GetSize(Text);
 
            var x = 0.0;
            var y = 0.0;
 
            var width = textSize.Width;
 
            switch (TextAlignment)
            {
                case ObjectTextAlignment.LeftTop:
                case ObjectTextAlignment.CenterTop:
                case ObjectTextAlignment.RightTop:
 
                    y = _lineRect.Top - 4 - textSize.Height;
 
                    break;
 
                case ObjectTextAlignment.LeftMiddle:
                case ObjectTextAlignment.CenterMiddle:
                case ObjectTextAlignment.RightMiddle:
 
                    y = (_lineRect.Top + _lineRect.Bottom - textSize.Height) / 2.0;
 
                    break;
 
                case ObjectTextAlignment.LeftBottom:
                case ObjectTextAlignment.CenterBottom:
                case ObjectTextAlignment.RightBottom:
 
                    y = _lineRect.Bottom + 4;
 
                    break;
            }
 
            switch (TextAlignment)
            {
                case ObjectTextAlignment.LeftTop:
                case ObjectTextAlignment.LeftMiddle:
                case ObjectTextAlignment.LeftBottom:
 
                    x = _lineRect.X;
 
                    break;
 
                case ObjectTextAlignment.CenterTop:
                case ObjectTextAlignment.CenterMiddle:
                case ObjectTextAlignment.CenterBottom:
 
                    x = _lineRect.Right - (_lineRect.Width + width) / 2.0;
 
                    x = Math.Max(x, _lineRect.Left);
 
                    break;
 
                case ObjectTextAlignment.RightTop:
                case ObjectTextAlignment.RightMiddle:
                case ObjectTextAlignment.RightBottom:
 
                    x = _lineRect.Right - width;
 
                    x = Math.Max(x, _lineRect.Left);
 
                    break;
            }
 
            var rect = new Rect(x, y, width, textSize.Height);
 
            visual.DrawString(Text, font, _lineBrush, rect);
        }
 
        public override void DrawControlPoints(DxVisualQueue visual)
        {
            if (_lineRect == Rect.Empty)
            {
                return;
            }
 
            var width = LineWidth / 2 + 4;
 
            var center = new Point((_lineRect.Left + _lineRect.Right) / 2.0, (_lineRect.Top + _lineRect.Bottom) / 2.0);
 
            var rect = new Rect(center, center);
 
            rect.Inflate(new Size(width, width));
 
            visual.FillRectangle(Theme.ChartCpFillBrush, rect);
            visual.DrawRectangle(Theme.ChartCpLinePen, rect);
        }
 
        protected override bool InObject(int x, int y)
        {
            if (_lineRect == Rect.Empty)
            {
                return false;
            }
 
            var r = Rect.Inflate(_lineRect, new Size(0, 2));
 
            return r.Contains(x, y);
        }
 
        protected override bool IsObjectOnChart()
        {
            return true;
        }
 
        public override void ApplyTheme(IChartTheme theme)
        {
            base.ApplyTheme(theme);
 
            LineColor = theme.ChartObjectLineColor;
        }
 
        public override void CopyTemplate(ObjectBase objectBase, bool style)
        {
            if (objectBase is HorizontalLineObject obj)
            {
                Alert.Copy(obj.Alert, !style);
 
                OnPropertyChanged(nameof(Alert));
 
                AlertMinDistance = obj.AlertMinDistance;
 
                Text = obj.Text;
                TextAlignment = obj.TextAlignment;
 
                FontSize = obj.FontSize;
 
                LineColor = obj.LineColor;
                LineWidth = obj.LineWidth;
                LineStyle = obj.LineStyle;
            }
 
            base.CopyTemplate(objectBase, style);
        }
 
        private double _lastAlertValue;
        private int _lastAlertIndex;
 
        public override void CheckAlert(List<IndicatorBase> indicators)
        {
            if (!Alert.IsActive)
            {
                return;
            }
 
            try
            {
                foreach (var indicator in indicators)
                {
                    if (indicator.CheckAlert(ControlPoints[0].Y, AlertMinDistance, ref _lastAlertIndex,
                        ref _lastAlertValue))
                    {
                        var message =
                            $"{indicator.Name}: пСрСсСчСниС уровня {DataProvider.Symbol.FormatPrice((decimal) ControlPoints[0].Y)}.";
 
                        AddAlert(Alert, message);
                    }
                }
            }
            catch (Exception e)
            {
                LogManager.WriteError(e);
            }
        }
    }
}
PreviousVertical LineNextVolume Profile

Last updated 2 years ago

⌨️