Candles creating by instrument basket
Click or drag to resize

Candles creating by instrument basket

To create ContinuousSecurity, WeightedIndexSecurity or ExpressionIndexSecurity candles the same procedure used as for creating the Security candles.

For example, create a 1 min candle for APM5 - ESM5 spread:

private OpenECryTrader _trader;

private Security _instr1;
private Security _instr2;
private WeightedIndexSecurity _indexInstr;

private const string _secCode1 = "APM5";
private const string _secCode2 = "ESM5";

private CandleManager _candleManager;
private CandleSeries _indexSeries;

readonly TimeSpan _timeFrame = TimeSpan.FromMinutes(1);

private ChartArea _area;
private ChartCandleElement _candlesElem;


_area = new ChartArea();

_candlesElem = new ChartCandleElement();


_candleManager = new CandleManager(_trader);
_candleManager.Processing += DrawCandles;

_indexInstr = new WeightedIndexSecurity() { Board = ExchangeBoard.Nyse, Id = "IndexInstr" };
_indexInstr.Weights.Add(_instr1, 1);
_indexInstr.Weights.Add(_instr2, -1);
_indexSeries = new CandleSeries(typeof(TimeFrameCandle), _indexInstr, _timeFrame)
    BuildCandlesMode = BuildCandlesModes.Build,


After that, candles will come to the event handler Processing - DrawCandles. These candles can be displayed on the chart:

private void DrawCandles(CandleSeries series, Candle candle)
    if (series == _indexSeries) 
          var chartData = new ChartDrawData();
          chartData.Group(candle.OpenTime).Add(_candleElement, candle);
See Also