Table of Contents

Managing the chart

Besides the chart settings menu, the chart can be controlled from an indicator: a setting of the indicator changes the spacing of the bars, the chart type or the footprint mode, or scrolls the chart. These methods and properties change the chart the user works with, not only the indicator.

The chart is reached through ChartInfo:

Example

Every setting of the indicator below applies its value to the chart at once. OnDispose returns the automatic bar spacing and releases the bar width when the indicator is removed.

using System.ComponentModel.DataAnnotations;

using ATAS.Indicators;

namespace ATAS.Docs.Samples.ChartIndicators;

public class ChartManagingIndicator : Indicator
{
    private decimal _barsSpacing = 1;
    private decimal _barsWidth = 1;
    private ChartVisualModes _modes;
    private FootprintVisualModes _visualMode;
    private FootprintContentModes _contentMode;
    private FootprintColorSchemes _colorScheme;
    private int _moveChartUpAndDown;
    private int _scrollPrice;

    [Range(1, 1000)]
    public decimal BarsSpacing
    {
        get => _barsSpacing;
        set
        {
            _barsSpacing = value;
            ChartInfo?.PriceChartContainer?.SetCustomBarsSpacing(_barsSpacing);
            RedrawChart();
        }
    }

    [Range(1, 1000)]
    public decimal BarsWidth
    {
        get => _barsWidth;
        set
        {
            _barsWidth = value;
            ChartInfo?.PriceChartContainer?.SetCustomBarsWidth(_barsWidth, false);
            RedrawChart();
        }
    }

    public ChartVisualModes ChartMode
    {
        get => _modes;
        set
        {
            _modes = value;

            if (ChartInfo != null)
                ChartInfo.ChartVisualMode = value;

            RedrawChart();
        }
    }

    public FootprintContentModes FootprintContentMode
    {
        get => _contentMode;
        set
        {
            _contentMode = value;

            if (ChartInfo != null)
                ChartInfo.FootprintContentMode = value;
        }
    }

    public FootprintVisualModes FootprintVisualMode
    {
        get => _visualMode;
        set
        {
            _visualMode = value;

            if (ChartInfo != null)
                ChartInfo.FootprintVisualMode = value;
        }
    }

    public FootprintColorSchemes FootprintColorScheme
    {
        get => _colorScheme;
        set
        {
            _colorScheme = value;

            if (ChartInfo != null)
                ChartInfo.FootprintColorScheme = value;
        }
    }

    public int MoveChartUpAndDown
    {
        get => _moveChartUpAndDown;
        set
        {
            // A positive offset moves the chart down, so the sign is inverted:
            // increasing this property moves the chart up.
            var diff = _moveChartUpAndDown - value;
            ChartInfo?.CoordinatesManager?.MoveChartUpAndDown(diff);
            _moveChartUpAndDown = value;
        }
    }

    public int ScrollPrice
    {
        get => _scrollPrice;
        set
        {
            // A positive ticks count moves the chart down, so the sign is inverted:
            // increasing this property moves the chart up.
            var diff = _scrollPrice - value;
            ChartInfo?.CoordinatesManager?.ScrollPrice(diff);
            _scrollPrice = value;
        }
    }

    protected override void OnCalculate(int bar, decimal value)
    {
    }

    protected override void OnDispose()
    {
        // Return the automatic bar spacing
        ChartInfo?.PriceChartContainer?.SetCustomBarsSpacing(null);

        // Bar width has no automatic mode: keep the current width and let the user change it again
        ChartInfo?.PriceChartContainer?.SetCustomBarsWidth(ChartInfo.PriceChartContainer.BarsWidth, false);
    }
}

The chart managed from the indicator settings