/// <summary> /// Event fired each time the we add/remove securities from the data feed /// </summary> /// <param name="algorithm">The algorithm instance that experienced the change in securities</param> /// <param name="changes">The security additions and removals from the algorithm</param> public override void OnSecuritiesChanged(QCAlgorithmFramework algorithm, SecurityChanges changes) { foreach (var added in changes.AddedSecurities) { // this model is limitted to looking at a single pair of assets if (added.Symbol != _asset1 && added.Symbol != _asset2) { continue; } if (added.Symbol == _asset1) { _asset1Price = algorithm.Identity(added.Symbol); } else { _asset2Price = algorithm.Identity(added.Symbol); } } if (_ratio == null) { // initialize indicators dependent on both assets if (_asset1Price != null && _asset2Price != null) { _ratio = _asset1Price.Over(_asset2Price); _mean = new ExponentialMovingAverage(500).Of(_ratio); var upper = new ConstantIndicator <IndicatorDataPoint>("ct", 1 + _threshold / 100m); _upperThreshold = _mean.Times(upper, "UpperThreshold"); var lower = new ConstantIndicator <IndicatorDataPoint>("ct", 1 - _threshold / 100m); _lowerThreshold = _mean.Times(lower, "LowerThreshold"); } } }