public void OnData(TradeBars data) { if (rsi.IsReady && mom.IsReady) { try { double signal = engine.DoInference((float)mom.Current.Value, (float)rsi.Current.Value); if (!Portfolio.Invested) { if (signal > 30) { int quantity = Decimal.ToInt32(Portfolio.Cash / data[symbol].Price); Buy(symbol, quantity); Debug("Purchased Stock: " + quantity + " shares"); } } else { if (signal < -10) { int quantity = Portfolio[symbol].Quantity; Sell(symbol, quantity); Debug("Sold Stock: " + quantity + " shares"); } } } catch (Exception ex) { Debug("Ex: " + ex.Message); Debug("## rsi: " + rsi + " mom: " + mom); } } }
public void OnData(TradeBars data) { if (_rsi.IsReady && _mom.IsReady) { try { var signal = _engine.DoInference((float)_mom.Current.Value, (float)_rsi.Current.Value); if (!Portfolio.Invested) { if (signal > 30) { var quantity = decimal.ToInt32(Portfolio.MarginRemaining / data[_symbol].Price); Buy(_symbol, quantity); Debug("Purchased Stock: " + quantity + " shares"); } } else { if (signal < -10) { var quantity = decimal.ToInt32(Portfolio[_symbol].Quantity); Sell(_symbol, quantity); Debug("Sold Stock: " + quantity + " shares"); } } } catch (Exception ex) { Debug("Ex: " + ex.Message); Debug("## rsi: " + _rsi + " mom: " + _mom); } } }
public void Scan(QuoteBar data) { var filter = !_securityHolding.Invested; double signal = _engine.DoInference((float)_rsi.Current.Value); if (signal > 20 && filter) { Signal = SignalType.Short; } else if (signal < -20 && filter) { Signal = SignalType.Long; } else { Signal = SignalType.NoSignal; } }