Table of Contents

Color types

The API uses two color types. System.Windows.Media.Color (WPF) is the color of the settings and of the data series in the classic ATAS build; System.Drawing.Color is the color of everything that draws. Code that mixes them up does not compile, so this page lists which members take which type and how to convert between them.

Which type where

In a project for the classic ATAS (net10.0-windows):

System.Windows.Media.Color System.Drawing.Color
ValueDataSeries.Color, RangeDataSeries.RangeColor, LineSeries.Color RenderContext methods, RenderPen, RenderBrush
CandleDataSeries: UpCandleColor, DownCandleColor, BorderColor CandleDataSeries.ValuesColor, ValueDataSeries.ValuesColor
The elements of PaintbarsDataSeries (Color?) The per-bar colors of a data series (Colors[bar])
PriceSelectionValue: PriceSelectionColor, ObjectColor, TextColor IChart.ColorsStore: the colors of the chart settings
AddAlert background and foreground AddText colors and the drawing objects: DrawingText, HorizontalLine, HorizontalChannel
CustomValue.ValueColor The contexts of SmartDOM columns and modules, WatchlistCellValue colors

The rule of thumb: what the user sets in the settings window of a chart indicator and what the chart draws for you from a data series is WPF; what you draw yourself, and everything outside the chart indicators, is System.Drawing. The heatmap renderer takes colors as #AARRGGBB text; HeatmapIndicatorColors converts a setting color to it and back.

In a project for ATAS X only (net10.0), every color of the API is System.Drawing.Color: the WPF column above does not exist there.

Converting

The Convert() extension methods of ATAS.Indicators convert one type into the other, the alpha channel included:

  • System.Windows.Media.Color.Convert() returns a System.Drawing.Color;
  • System.Drawing.Color.Convert() returns a System.Windows.Media.Color.

In the ATAS X build Convert() of a System.Drawing.Color returns the same color, so code that converts compiles for both targets. Convert once, when the setting changes, rather than on every frame:

// A color setting: the type the data series use, so it can be assigned to them directly
[Display(Name = "Line color", GroupName = "Colors")]
public SettingColor LineColor
{
    get => ((ValueDataSeries)DataSeries[0]).Color;
    set
    {
        ((ValueDataSeries)DataSeries[0]).Color = value;

        // The drawing API takes System.Drawing.Color: convert once, not on every frame
        _pen = new RenderPen(value.Convert(), 2);
    }
}

One source for both targets

ATAS X loads the classic build and converts the WPF colors by itself (see ATAS X and macOS), so most extensions need one build only. If you build for both targets, give the color of the settings an alias. The net10.0-windows target defines the WINDOWS symbol:

// One alias for the color type of the settings and the data series: WPF in the classic ATAS build
// (net10.0-windows defines WINDOWS), System.Drawing in an ATAS X-only build (net10.0)
#if WINDOWS
using SettingColor = System.Windows.Media.Color;
#else
using SettingColor = System.Drawing.Color;
#endif

System.Windows.Media.Colors has no counterpart in the ATAS X build; take a named color from System.Drawing.Color and convert it (System.Drawing.Color.Orange.Convert()), which compiles for both.

Example

A color setting assigned to the data series, a pen converted from it once, and a text in the color of the chart's axis:

using System.ComponentModel;
using System.ComponentModel.DataAnnotations;

using ATAS.Indicators;
using OFT.Rendering.Context;
using OFT.Rendering.Tools;

// One alias for the color type of the settings and the data series: WPF in the classic ATAS build
// (net10.0-windows defines WINDOWS), System.Drawing in an ATAS X-only build (net10.0)
#if WINDOWS
using SettingColor = System.Windows.Media.Color;
#else
using SettingColor = System.Drawing.Color;
#endif

namespace ATAS.Docs.Samples.CommonApi;

[DisplayName("Color types")]
public class ColorTypesIndicator : Indicator
{
    private readonly RenderFont _font = new("Arial", 12);
    private RenderPen _pen = new(System.Drawing.Color.Orange, 2);

    // A color setting: the type the data series use, so it can be assigned to them directly
    [Display(Name = "Line color", GroupName = "Colors")]
    public SettingColor LineColor
    {
        get => ((ValueDataSeries)DataSeries[0]).Color;
        set
        {
            ((ValueDataSeries)DataSeries[0]).Color = value;

            // The drawing API takes System.Drawing.Color: convert once, not on every frame
            _pen = new RenderPen(value.Convert(), 2);
        }
    }

    public ColorTypesIndicator()
    {
        LineColor = System.Drawing.Color.Orange.Convert();

        EnableCustomDrawing = true;
        SubscribeToDrawingEvents(DrawingLayouts.Final);
    }

    protected override void OnCalculate(int bar, decimal value)
    {
        this[bar] = value;
    }

    protected override void OnRender(RenderContext context, DrawingLayouts layout)
    {
        // The chart colors are System.Drawing.Color already
        var textColor = ChartInfo?.ColorsStore.AxisTextColor ?? System.Drawing.Color.Gray;

        context.DrawLine(_pen, ChartArea.X + 8, ChartArea.Y + 30, ChartArea.X + 60, ChartArea.Y + 30);
        context.DrawString("Line color", _font, textColor, ChartArea.X + 66, ChartArea.Y + 22);
    }
}
  • Drawing: RenderContext, pens, fonts and the chart colors.
  • Settings: color settings and filters.
  • ATAS X and macOS: the types ATAS X converts at load time.