Files
mika@stocksharp.com 3b814d26d2 Samples: build from the applications' sources again and follow the awaited API
The applications moved every host into a folder of its own, so the projects the from-source samples reference
are under Xaml\Avalonia and Xaml\Wpf now, and the FIX connector they named lives in the public connectors
repository. Nine WPF samples still named Xaml and Xaml.Charting where they were before: a missing project
reference is only a warning, so they failed later, at the first DevExpress or StockSharp tag of their markup.

The MultiConnect samples sign in through the window the WPF head has. That head keeps the credentials window
in Studio.WebApi.UI, taking the site's client service; the samples asked StockSharp.Xaml for one taking a
fetcher, which the head does not have, and did not compile from sources. The published UI packages are far
behind the sources and are not what the samples are kept in step with: the package-based projects of these
samples compile once the WPF packages built from that head are published.

The WPF samples await the connector's settings window, which the WPF library offers as ConfigureAsync only,
and the active-orders sample awaits the chart's save instead of the obsolete blocking wrapper. The
package-based projects of the same samples compile once a StockSharp.Xaml package that has ConfigureAsync is
published.

The Avalonia samples keep the connection settings through the awaited store: IConnectorSettingsStore reads
and writes through awaited members now, so the sample store reads or writes its file when it is asked instead
of reading both files up front and queueing its writes. The chart sample saves and loads its chart the same
way.

Eight Avalonia samples put the wheel date picker into columns of 150-170 pixels. It does not get narrower
than about three hundred, so the two of them ran over each other and over the Start and Stop buttons. They
take the compact calendar editor now, which the history testing sample already had.
2026-10-15 23:02:33 +03:00
..
2024-06-22 13:45:38 +03:00
2025-01-14 13:32:47 +03:00
2024-06-22 13:45:38 +03:00
2024-06-22 13:45:38 +03:00
2025-12-01 09:20:08 +03:00
2025-12-30 23:55:07 +03:00

Implementation of Custom and Standard Moving Averages in StockSharp

Overview

This application illustrates how to integrate StockSharp's charting capabilities with custom and standard indicators for financial market analysis. The main components are two moving averages displayed alongside the candlestick data for the stock "SBER@TQBR".

Detailed Code Breakdown

Initialization and Chart Setup

The MainWindow constructor initializes the UI components, sets up the chart area, and configures the candle and indicator elements:

public MainWindow()
{
    InitializeComponent();

    var chartArea = new ChartArea();
    Chart.AddArea(chartArea);

    var chartCandleElement = new ChartCandleElement();
    Chart.AddElement(chartArea, chartCandleElement);

    var chartIndicatorElement1 = new ChartIndicatorElement
    {
        FullTitle = "SMA",
        Color = Colors.Brown,
        DrawStyle = DrawStyles.Line
    };

    var chartIndicatorElement2 = new ChartIndicatorElement
    {
        FullTitle = "Lazy",
        Color = Colors.DodgerBlue,
        DrawStyle = DrawStyles.Line
    };
    Chart.AddElement(chartArea, chartIndicatorElement1);
    Chart.AddElement(chartArea, chartIndicatorElement2);
}

Data Loading and Indicator Processing

The code loads candle data and processes it through two indicators, drawing results on the chart:

var secId = "SBER@TQBR".ToSecurityId();
var candleStorage = new StorageRegistry().GetTimeFrameCandleMessageStorage(secId, TimeSpan.FromMinutes(1), new LocalMarketDataDrive(_pathHistory), StorageFormats.Binary);
var candles = candleStorage.Load(Paths.HistoryBeginDate, Paths.HistoryEndDate);

var indicator1 = new SimpleMovingAverage { Length = 10 };
var indicator2 = new LazyMovingAverage { Length = 10 };

foreach (var candle in candles)
{
    var indicatorValue1 = indicator1.Process(candle);
    var indicatorValue2 = indicator2.Process(candle);
    var chartDrawData = new ChartDrawData();

    chartDrawData.Group(candle.OpenTime)
        .Add(chartCandleElement, candle)
        .Add(chartIndicatorElement1, indicatorValue1)
        .Add(chartIndicatorElement2, indicatorValue2);

    Chart.Draw(chartDrawData);
}

Custom Indicator Definition: LazyMovingAverage

The custom indicator, LazyMovingAverage, is defined with a simplified approach to smoothing data points, creating a "lazy" average:

internal class LazyMovingAverage : BaseIndicator
{
    public int Length { get; set; } = 32;
    private decimal? _outputValue;

    protected override bool CalcIsFormed() => true;

    protected override IIndicatorValue OnProcess(IIndicatorValue input)
    {
        var value = input.GetValue<decimal>();
        if (_outputValue == null) _outputValue = value;
        _outputValue = _outputValue + (value - _outputValue) / Length;
        return new DecimalIndicatorValue(this, _outputValue.Value);
    }
}

This indicator starts with the first value it receives and then gradually adjusts towards new data points, moving towards them at a rate determined by the Length property.

Conclusion

This WPF application provides an effective way to visualize how different types of moving averages respond to the same data set, helping traders or analysts to compare the sensitivity and lag of each indicator. The Lazy Moving Average offers a more gradual adjustment to price changes compared to the more responsive Simple Moving Average. This example can be adapted or extended to include other types of indicators or financial data for more comprehensive analysis.