Click or drag to resize


The S# normally provides for more than 70 indicators of technical analysis, which allows not to create a necessary indicator from scratch, but to use a ready-made (or to create your own one based on existing, as shown in the Custom indicator section). All base classes for working with indicators, as well as indicators themselves are in the StockSharp.Algo.Indicators namespace.

Indicator connection to algorithm

  1. First, you need to create an indicator. The indicator is created as a usual .NET object:

    var longSma = new SimpleMovingAverage { Length = 80 };
  2. Next, you need to fill it with data. For example, it may be the candle closing price:

    foreach (var candle in candles)

    The indicator takes the IIndicatorValue. Some of the indicators operate a primitive value, such as the SimpleMovingAverage. Others require a full candle, for example, MedianPrice. Therefore, the incoming values should be casted to either DecimalIndicatorValue or CandleIndicatorValue. The indicator resulting value works under the same rules as the input value.

  3. In order to get the current indicator value the GetValueT method is used:

    // new relative position between long and short sma indicators
    var isShortLessThenLong = ShortSma.GetValue<decimal>(0) < LongSma.GetValue<decimal>(0);
    // we got crossing
    if (_isShortLessThenLong != isShortLessThenLong)
        // short is less than long - sell, otherwise, buy.
        var direction = isShortLessThenLong ? OrderDirections.Sell : OrderDirections.Buy;
        // creating a new order
        var order = this.CreateOrder(direction, Security.GetMarketPrice(direction), Volume);
        // sending to registration
        // save the last relative position
        _isShortLessThenLong = isShortLessThenLong;