public void Run() { var data = GetPriceHistory(); var today = GetToday(); var oldState = LoadState(); var newState = new AnalyzerState(); TradeAction tradeAction = TradeAction.Nothing; DateTime prevData; decimal todayPrice; ProcessHistoricalData(data, out prevData, out todayPrice); var analytics = new Analytics { DateTime = today, BoilingerUpper = boilinger.PeekLastUpper(), BoilingerMiddle = boilinger.PeekLastMiddle(), BoilingerLower = boilinger.PeekLastLower(), Price = todayPrice, EMAs = emas.Select(x => x.PeekLast()).ToArray(), State = oldState, }; if (prevData.Date == today.Date) { int countAbove = 0; int countBelow = 0; foreach (var ema in emas) { if (todayPrice > ema.PeekLast()) { countAbove++; } else if (todayPrice < ema.PeekLast()) { countBelow--; } } float growthStrength = countAbove / (float)emas.Length; float fallStrength = countBelow / (float)emas.Length; newState.LastGrowthStrength = analytics.GrowthStrength = growthStrength; newState.LastFallStrength = analytics.FallStrength = fallStrength; decimal priceDiff = oldState.LastPrice - todayPrice; if (boilinger.PeekLastUpper() < todayPrice) // Fast growth { analytics.Comment("Boilinger: fast growth."); analytics.Comment(string.Format("Price diff: {0:C2}, margin: {1:C2}", priceDiff, priceDiff * oldState.Coins)); } else if (boilinger.PeekLastLower() > todayPrice) // Fast fall { analytics.Comment("Boilinger: fast fall."); analytics.Comment(string.Format("Price diff: {0:C2}, margin: {1:C2}", priceDiff, priceDiff * oldState.Coins)); } else // inside range { analytics.Comment("Boilinger: inside range."); } } newState.LastPrice = todayPrice; SaveState(newState); analytics.Coins = newState.Coins; analytics.Dollars = newState.FiatMoney; analytics.CoinsWorth = newState.Coins * todayPrice; analytics.TradeAction = tradeAction; if (OnReportAnalytics != null) { OnReportAnalytics(analytics); } }
protected virtual void SaveState(AnalyzerState state) { }