> For the complete documentation index, see [llms.txt](https://support.tiger.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://support.tiger.com/razrabotka-dlya-tiger.trade-windows/primery-indikatorov/session-color.md).

# Session Color

```
/------------------------------------------------------------------------------
//
// Индикатор SessionColor. Copyright (c) 2023 Tiger Trade Capital AG. All rights reserved.
//
//------------------------------------------------------------------------------
 
using System;
using System.ComponentModel;
using System.Runtime.Serialization;
using System.Windows;
using System.Windows.Media;
using TigerTrade.Chart.Base;
using TigerTrade.Chart.Indicators.Common;
using TigerTrade.Chart.Indicators.Enums;
using TigerTrade.Dx;
 
namespace TigerTrade.Chart.Indicators.Custom
{
    [DataContract(Name = "SessionColorIndicator", Namespace = "http://schemas.datacontract.org/2004/07/TigerTrade.Chart.Indicators.Custom")]
    [Indicator("X_SessionColor", "*SessionColor", true, Type = typeof(SessionColorIndicator))]
    internal sealed class SessionColorIndicator : IndicatorBase
    {
        private TimeSpan _startTime;
 
        [DataMember(Name = "StartTime")]
        [Category("Параметры"), DisplayName("Начальное время")]
        public TimeSpan StartTime
        {
            get => _startTime;
            set
            {
                if (value == _startTime)
                {
                    return;
                }
 
                _startTime = value;
 
                OnPropertyChanged();
            }
        }
 
        private TimeSpan _endTime;
 
        [DataMember(Name = "EndTime")]
        [Category("Параметры"), DisplayName("Конечное время")]
        public TimeSpan EndTime
        {
            get => _endTime;
            set
            {
                if (value == _endTime)
                {
                    return;
                }
 
                _endTime = value;
 
                OnPropertyChanged();
            }
        }
 
        private XBrush _backBrush;
 
        private XColor _backColor;
 
        [DataMember(Name = "BackColor")]
        [Category("Стиль"), DisplayName("Цвет фона")]
        public XColor BackColor
        {
            get => _backColor;
            set
            {
                if (value == _backColor)
                {
                    return;
                }
 
                _backColor = value;
 
                _backBrush = new XBrush(_backColor);
 
                OnPropertyChanged();
            }
        }
 
        [Browsable(false)]
        public override bool ShowIndicatorValues => false;
 
        [Browsable(false)]
        public override bool ShowIndicatorLabels => false;
 
        [Browsable(false)]
        public override IndicatorCalculation Calculation => IndicatorCalculation.OnEachTick;
 
        public SessionColorIndicator()
        {
            ShowIndicatorTitle = false;
 
            StartTime = TimeSpan.FromHours(0);
            EndTime = TimeSpan.FromHours(12);
 
            BackColor = Color.FromArgb(127, 30, 144, 255);
        }
 
        protected override void Execute()
        {
        }
 
        public override void Render(DxVisualQueue visual)
        {
            var st = DateTime.MinValue;
            var et = DateTime.MinValue;
            var sp = new Point();
            var ep = new Point();
 
            for (var i = Canvas.Count - 1; i >= -Canvas.AfterBars; i--)
            {
                var index = Canvas.GetIndex(i);
 
                var d = Canvas.ConvertTimeToLocal(Canvas.IndexToDate(index));
 
                if (StartTime < EndTime)
                {
                    var newStartDate = d.Date.Add(StartTime);
                    var newEndDate = d.Date.Add(EndTime);
 
                    if (st == DateTime.MinValue && d >= newStartDate && d < newEndDate)
                    {
                        sp = new Point(Canvas.GetXX(i) - Canvas.ColumnWidth / 2.0, 0);
                        st = d;
 
                        et = DateTime.MinValue;
                        ep = new Point();
                    }
 
                    if (st != DateTime.MinValue && st.Date < d.Date)
                    {
                        ep = new Point(Canvas.GetXX(i + 1) + Canvas.ColumnWidth / 2.0, Canvas.Rect.Bottom);
                        et = d;
                    }
                    else
                    {
                        if (d >= newEndDate)
                        {
                            ep = new Point(Canvas.GetXX(i + 1) + Canvas.ColumnWidth / 2.0, Canvas.Rect.Bottom);
                            et = d;
                        }
                    }
                }
                else
                {
                    var newStartDate = d.Date.Add(StartTime);
                    var newEndDate = d.Date.Add(EndTime);
 
                    if (st == DateTime.MinValue && (d >= newStartDate || d < newEndDate))
                    {
                        sp = new Point(Canvas.GetXX(i) - Canvas.ColumnWidth / 2.0, 0);
                        st = d;
 
                        et = DateTime.MinValue;
                        ep = new Point();
                    }
 
                    if (d >= newEndDate && d < newStartDate)
                    {
                        ep = new Point(Canvas.GetXX(i + 1) + Canvas.ColumnWidth / 2.0, Canvas.Rect.Bottom);
                        et = d;
                    }
                }
 
                if (st == DateTime.MinValue || et == DateTime.MinValue)
                {
                    continue;
                }
 
                visual.FillRectangle(_backBrush, new Rect(sp, ep));
 
                st = DateTime.MinValue;
                et = DateTime.MinValue;
                sp = new Point();
                ep = new Point();
            }
 
            if (st != DateTime.MinValue)
            {
                visual.FillRectangle(_backBrush,
                    new Rect(sp, new Point(Canvas.Rect.Right, Canvas.Rect.Bottom)));
            }
        }
 
        public override void ApplyColors(IChartTheme theme)
        {
            BackColor = theme.GetNextColor();
 
            base.ApplyColors(theme);
        }
 
        public override void CopyTemplate(IndicatorBase indicator, bool style)
        {
            var i = (SessionColorIndicator)indicator;
 
            BackColor = i.BackColor;
            StartTime = i.StartTime;
            EndTime = i.EndTime;
 
            base.CopyTemplate(indicator, style);
        }
    }
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://support.tiger.com/razrabotka-dlya-tiger.trade-windows/primery-indikatorov/session-color.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
