private static Rule CreateRandomThresholdRule() // Generate a random Threshold Rule. { int rndNum = RandomHolder.Instance.Next(6); if (rndNum == 0) // Create a Threshold (Overlay, Overlay) rule. { return(RuleFactory.createThresholdRule(IndicatorFactory.getRandomPriceOverlayIndicator(), IndicatorFactory.getRandomPriceOverlayIndicator())); } else if (rndNum == 1) // Create a Threshold (Value, Bounded) rule. { return(RuleFactory.createThresholdRule(IndicatorFactory.createRandomValue(), IndicatorFactory.getRandomBoundedIndicator())); } else if (rndNum == 2) // Create a Threshold (Value, Unbounded) rule. { return(RuleFactory.createThresholdRule(IndicatorFactory.createRandomValue(), IndicatorFactory.getRandomUnboundedIndicator())); } else if (rndNum == 3) // Create a Threshold (Bounded, Bounded) rule. { return(RuleFactory.createThresholdRule(IndicatorFactory.getRandomBoundedIndicator(), IndicatorFactory.getRandomBoundedIndicator())); } else if (rndNum == 4) // Create a Threshold (Bounded, Value) rule. { return(RuleFactory.createThresholdRule(IndicatorFactory.getRandomBoundedIndicator(), IndicatorFactory.createRandomValue())); } else // Create a Threshold (Unbounded, Value) rule. { return(RuleFactory.createThresholdRule(IndicatorFactory.getRandomUnboundedIndicator(), IndicatorFactory.createRandomValue())); } }
public MultiPointTool(FScene scene, SceneObject target) { this.Scene = scene; TargetSO = target; // do this here ?? behaviors = new InputBehaviorSet(); behaviors.Add( new MultiPointTool_2DBehavior(scene.Context, this) { Priority = 5 }); if (FPlatform.IsUsingVR()) { behaviors.Add( new MultiPointTool_SpatialBehavior(scene.Context, this) { Priority = 5 }); } Indicators = new ToolIndicatorSet(this, scene); IndicatorBuilder = new StandardIndicatorFactory(); GizmoPoints = new Dictionary <int, ControlPoint>(); PointHitTestF = PointIntersectionTest; }
public ExchangeCandles(ILogger logger, RepositoryService repoService, IExchangeService exchange, IndicatorFactory indicatorFactory, TimePeriod period, Instrument instrument) { _logger = logger; _repoService = repoService; _exchange = exchange; _indicatorFactory = indicatorFactory; _period = period; _instrument = instrument; _exchangeName = _exchange.ExchangeConfig.ExchangeName; CurrentCandle = new CandleDto { ExchangeName = _exchangeName, Period = _period, Instrument = _instrument }; }
private static Rule CreateRandomCrossRule() // Generate a random Cross Rule. { int rndNum = RandomHolder.Instance.Next(3); if (rndNum == 0) // Create a Cross( Overlay, Overlay) rule. { return(RuleFactory.createCrossRule(IndicatorFactory.getRandomPriceOverlayIndicator(), IndicatorFactory.getRandomPriceOverlayIndicator())); } else if (rndNum == 1) // Create a Cross( Overlay, PriceArray) rule. { return(RuleFactory.createCrossRule(IndicatorFactory.getRandomPriceOverlayIndicator(), IndicatorFactory.createRandomABPriceArray())); } else // Create a Cross( PriceArray, Overlay) rule. { return(RuleFactory.createCrossRule(IndicatorFactory.createRandomABPriceArray(), IndicatorFactory.getRandomPriceOverlayIndicator())); } }
public override void Populate() { TimeSeries ds = base.Parameters[0].AsTimeSeries; string symbol = Parameters[1].AsString; BarHistory idx = IndicatorFactory.GetHistory(ds, symbol, Bars.Scale); TimeSeries index = idx.Close; int period = base.Parameters[2].AsInt; int emaPeriod = base.Parameters[3].AsInt; this.DateTimes = ds.DateTimes; int FirstValidValue = Math.Max(period, emaPeriod) + 1; if (ds.Count < FirstValidValue) { return; } TimeSeries log1 = new TimeSeries(ds.DateTimes); TimeSeries log2 = new TimeSeries(index.DateTimes); TimeSeries tmp1 = new TimeSeries(ds.DateTimes); tmp1 = ds * 0; for (int i = 0; i < FirstValidValue; i++) { log1[i] = 0;// checked(Math.Log( ds[i] / index[i] )); log2[i] = 0; } for (int i = FirstValidValue; i < ds.Count; i++) { log1[i] = checked (Math.Log(ds[i] / index[i])); log2[i] = checked (Math.Log((ds[i - period]) / index[i - period])); tmp1[i] = log1[i] - log2[i]; } TimeSeries rsmk = EMA.Series(tmp1, emaPeriod) * 100d; for (int j = FirstValidValue; j < ds.Count; j++) { double val = rsmk[j]; base.Values[j] = double.IsNaN(val) ? 0 : val; } }
public CandleService(ILogger logger, RepositoryService repoService, IEnumerable <IExchangeService> exchangeServices, IndicatorFactory indicatorFactory) { _repoService = repoService; _exchangeServices = exchangeServices.ToList(); _logger = logger; var instruments = Enum.GetValues(typeof(Instrument)).Cast <Instrument>().ToArray(); _candleSubscriptions = new Dictionary <Instrument, IStreamSubscription>(); _tradeSubscriptions = new Dictionary <Instrument, IStreamSubscription>(); _exchangeCandles = new Dictionary <string, ExchangeCandles>(); foreach (var instrument in instruments) { _candleSubscriptions.Add(instrument, new StreamSubscription <CandleDto>(OnNewCandle)); _tradeSubscriptions.Add(instrument, new StreamSubscription <TradeDto>(OnNewTrade)); foreach (var exchange in _exchangeServices) { foreach (var timePeriod in exchange.ExchangeConfig.SupportedTimePeriods) { if (!exchange.ExchangeConfig.SupportedInstruments.ContainsKey(instrument)) { continue; } var exchangeData = new ExchangeCandles(logger, repoService, exchange, indicatorFactory, timePeriod.Key, instrument); _exchangeCandles.Add(exchangeData.Key, exchangeData); } } } }
async Task Init() { try { await _apiService.Login(); } catch (Exception ex) { _logger.LogException(new Exception("apiService.Login Failed")); _logger.LogException(ex); initSuccess = false; return; } try { var holidays = await _apiService.GetHolidays(); this._dateManager = Factories.CreateDateManager(holidays); if (!IsDevelopment) { if (!IsBusinessDay) { this.Close(); return; } } var stocks = await _apiService.GetStocks(); stocks = stocks.Where(s => !s.ignore).ToList(); string tickFileFolder = _settingsManager.GetSettingValue(AppSettingsKey.TickFile); var tickDBService = ServiceFactory.CreateTickDBService(stocks.Select(s => s.code), tickFileFolder); string baseStock = _settingsManager.GetSettingValue(AppSettingsKey.BaseStock); _stockService = ServiceFactory.CreateStockService(stocks, baseStock, tickDBService); _futuresService = ServiceFactory.CreateFuturesService(tickDBService); var indicatorDataList = await _apiService.GetIndicators(); foreach (var item in indicatorDataList) { this._indicators.Add(IndicatorFactory.Create(item.entity, _stockService, _futuresService)); } _source.SymbolCodes = _stockService.GetStockCodes(); _source.Connect(); } catch (Exception ex) { _logger.LogException(ex); initSuccess = false; return; } initSuccess = true; }