public override IEnumerable <(ICandle, ITradingAdviceCode)> AllForecasts(IEnumerable <ICandle> candles) { if (candles.Count() < MinNumberOfCandles) { throw new Exception("Number of candles less then expected"); } List <(ICandle, ITradingAdviceCode)> result = new List <(ICandle, ITradingAdviceCode)>(); List <decimal?> ao = candles.AwesomeOscillator(); MacdItem macd = candles.Macd(5, 7, 4); for (int i = 0; i < candles.Count(); i++) { if (i == 0) { result.Add((candles.ElementAt(i), TradingAdviceCode.HOLD)); } else if (ao[i] < 0 && ao[i - 1] > 0 && macd.Hist[i] < 0) { result.Add((candles.ElementAt(i), TradingAdviceCode.SELL)); } else if (ao[i] > 0 && ao[i - 1] < 0 && macd.Hist[i] > 0) { result.Add((candles.ElementAt(i), TradingAdviceCode.BUY)); } else { result.Add((candles.ElementAt(i), TradingAdviceCode.HOLD)); } } return(result); }
public override IEnumerable <(ICandle, ITradingAdviceCode)> AllForecasts(IEnumerable <ICandle> candles) { if (candles.Count() < MinNumberOfCandles) { throw new Exception("Number of candles less then expected"); } List <(ICandle, ITradingAdviceCode)> result = new List <(ICandle, ITradingAdviceCode)>(); MacdItem macd = candles.Macd(7, 12, 9); StochItem stoch = candles.StochRsi(9, CandleVariableCode.CLOSE, 3, 3, TicTacTec.TA.Library.Core.MAType.Sma); for (int i = 0; i < candles.Count(); i++) { if (macd.Macd[i] - macd.Signal[i] < 0 && stoch.K[i] > 70 && stoch.K[i] < stoch.D[i]) { result.Add((candles.ElementAt(i), TradingAdviceCode.SELL)); } else if (macd.Macd[i] - macd.Signal[i] > 0 && stoch.K[i] < 30 && stoch.K[i] > stoch.D[i]) { result.Add((candles.ElementAt(i), TradingAdviceCode.BUY)); } else { result.Add((candles.ElementAt(i), TradingAdviceCode.HOLD)); } } return(result); }
public override IEnumerable <(ICandle, ITradingAdviceCode)> AllForecasts(IEnumerable <ICandle> candles) { if (candles.Count() < MinNumberOfCandles) { throw new Exception("Number of candles less then expected"); } List <(ICandle, ITradingAdviceCode)> result = new List <(ICandle, ITradingAdviceCode)>(); MacdItem macd = candles.Macd(12, 26, 9); List <decimal?> tema = candles.Tema(50); List <decimal> close = candles.Select(x => x.Close).ToList(); for (int i = 0; i < candles.Count(); i++) { if (i == 0) { result.Add((candles.ElementAt(i), TradingAdviceCode.HOLD)); } else if (tema[i] < close[i] && tema[i - 1] > close[i - 1] && macd.Macd[i] > 0 && macd.Macd[i - 1] < 0) { result.Add((candles.ElementAt(i), TradingAdviceCode.BUY)); } else if (tema[i] > close[i] && tema[i - 1] < close[i - 1] && macd.Macd[i] < 0 && macd.Macd[i - 1] > 0) { result.Add((candles.ElementAt(i), TradingAdviceCode.SELL)); } else { result.Add((candles.ElementAt(i), TradingAdviceCode.HOLD)); } } return(result); }
public override IEnumerable <(ICandle, ITradingAdviceCode)> AllForecasts(IEnumerable <ICandle> candles) { if (candles.Count() < MinNumberOfCandles) { throw new Exception("Number of candles less then expected"); } List <(ICandle, ITradingAdviceCode)> result = new List <(ICandle, ITradingAdviceCode)>(); MacdItem macd = candles.Macd(12, 26, 9); for (int i = 0; i < candles.Count(); i++) { if (i < 4) { result.Add((candles.ElementAt(i), TradingAdviceCode.HOLD)); } else if (macd.Macd[i] - macd.Signal[i] > 0 && macd.Hist[i] > macd.Hist[i - 1] && macd.Hist[i - 1] > macd.Hist[i - 2] && macd.Hist[i - 2] > macd.Hist[i - 3] && macd.Hist[i - 3] > macd.Hist[i - 4]) { result.Add((candles.ElementAt(i), TradingAdviceCode.BUY)); } else if (macd.Macd[i] - macd.Signal[i] > 0 && macd.Hist[i] < macd.Hist[i - 1] && macd.Hist[i - 1] < macd.Hist[i - 2] && macd.Hist[i - 2] < macd.Hist[i - 3] && macd.Hist[i - 3] < macd.Hist[i - 4]) { result.Add((candles.ElementAt(i), TradingAdviceCode.SELL)); } else { result.Add((candles.ElementAt(i), TradingAdviceCode.HOLD)); } } return(result); }
public override IEnumerable <(ICandle, ITradingAdviceCode)> AllForecasts(IEnumerable <ICandle> candles) { if (candles.Count() < MinNumberOfCandles) { throw new Exception("Number of candles less then expected"); } MacdCrossPreset preset = null; if (!string.IsNullOrWhiteSpace(Preset)) { preset = JsonConvert.DeserializeObject <MacdCrossPreset>(Preset); } List <(ICandle, ITradingAdviceCode)> result = new List <(ICandle, ITradingAdviceCode)>(); MacdItem macd = candles.Macd(preset?.MacdFast, preset?.MacdSlow, preset?.MacdSignal); for (int i = 0; i < candles.Count(); i++) { var crossUnder = macd.Macd.Crossunder(macd.Signal); var crossOver = macd.Macd.Crossover(macd.Signal); if (i == 0) { result.Add((candles.ElementAt(i), TradingAdviceCode.HOLD)); } else if (macd.Macd[i] > 0 && crossUnder[i]) { result.Add((candles.ElementAt(i), TradingAdviceCode.SELL)); } else if (macd.Macd[i] < 0 && crossOver[i]) { result.Add((candles.ElementAt(i), TradingAdviceCode.BUY)); } else { result.Add((candles.ElementAt(i), TradingAdviceCode.HOLD)); } } return(result); }
public override IEnumerable <(ICandle, ITradingAdviceCode)> AllForecasts(IEnumerable <ICandle> candles) { if (candles.Count() < MinNumberOfCandles) { throw new Exception("Number of candles less then expected"); } RsiMacdMfiPreset preset = null; if (!string.IsNullOrWhiteSpace(Preset)) { preset = JsonConvert.DeserializeObject <RsiMacdMfiPreset>(Preset); } List <(ICandle, ITradingAdviceCode)> result = new List <(ICandle, ITradingAdviceCode)>(); MacdItem macd = candles.Macd(preset?.MacdFast ?? 5, preset?.MacdSlow ?? 10, preset?.MacdSignal ?? 4); List <decimal?> rsi = candles.Rsi(preset?.Rsi ?? 16); List <decimal?> mfi = candles.Mfi(preset?.Mfi); List <decimal?> ao = candles.AwesomeOscillator(); List <decimal> close = candles.Select(x => x.Close).ToList(); for (int i = 0; i < candles.Count(); i++) { if (mfi[i] < 30 && rsi[i] < 45 && ao[i] > 0) { result.Add((candles.ElementAt(i), TradingAdviceCode.BUY)); } else if (mfi[i] > 30 && rsi[i] > 45 && ao[i] < 0) { result.Add((candles.ElementAt(i), TradingAdviceCode.SELL)); } else { result.Add((candles.ElementAt(i), TradingAdviceCode.HOLD)); } } return(result); }
public override IEnumerable <(ICandle, ITradingAdviceCode)> AllForecasts(IEnumerable <ICandle> candles) { if (candles.Count() < MinNumberOfCandles) { throw new Exception("Number of candles less then expected"); } List <(ICandle, ITradingAdviceCode)> result = new List <(ICandle, ITradingAdviceCode)>(); MacdItem macd = candles.Macd(); List <decimal?> fastMa = candles.Sma(12); List <decimal?> slowMa = candles.Sma(26); List <decimal?> sma200 = candles.Sma(200); List <decimal> closes = candles.Select(x => x.Close).ToList(); for (int i = 0; i < candles.Count(); i++) { if (i < 25) { result.Add((candles.ElementAt(i), TradingAdviceCode.HOLD)); } else if (slowMa[i] < sma200[i]) { result.Add((candles.ElementAt(i), TradingAdviceCode.SELL)); } else if (macd.Hist[i] > 0 && macd.Hist[i - 1] < 0 && macd.Macd[i] > 0 && fastMa[i] > slowMa[i] && closes[i - 26] > sma200[i]) { result.Add((candles.ElementAt(i), TradingAdviceCode.BUY)); } else { result.Add((candles.ElementAt(i), TradingAdviceCode.HOLD)); } } return(result); }
public override IEnumerable <(ICandle, ITradingAdviceCode)> AllForecasts(IEnumerable <ICandle> candles) { if (candles.Count() < MinNumberOfCandles) { throw new Exception("Number of candles less then expected"); } RsiMacdPreset preset = null; if (!string.IsNullOrWhiteSpace(Preset)) { preset = JsonConvert.DeserializeObject <RsiMacdPreset>(Preset); } List <(ICandle, ITradingAdviceCode)> result = new List <(ICandle, ITradingAdviceCode)>(); MacdItem macd = candles.Macd(preset?.MacdFast ?? 12, preset?.MacdSlow ?? 26, preset?.MacdSignal ?? 9); List <decimal?> rsi = candles.Rsi(preset?.Rsi ?? 14); for (int i = 0; i < candles.Count(); i++) { if (rsi[i] > 70 && macd.Macd[i] - macd.Signal[i] < 0) { result.Add((candles.ElementAt(i), TradingAdviceCode.SELL)); } else if (rsi[i] < 30 && macd.Macd[i] - macd.Signal[i] > 0) { result.Add((candles.ElementAt(i), TradingAdviceCode.BUY)); } else { result.Add((candles.ElementAt(i), TradingAdviceCode.HOLD)); } } return(result); }
public override IEnumerable <(ICandle, ITradingAdviceCode)> AllForecasts(IEnumerable <ICandle> candles) { if (candles.Count() < MinNumberOfCandles) { throw new Exception("Number of candles less then expected"); } List <(ICandle, ITradingAdviceCode)> result = new List <(ICandle, ITradingAdviceCode)>(); List <decimal?> emaShort = candles.Ema(4); List <decimal?> emaLong = candles.Ema(10); List <decimal?> plusDi = candles.PlusDi(28); List <decimal?> minusDi = candles.MinusDi(28); MacdItem macd = candles.Macd(5, 10, 4); for (int i = 0; i < candles.Count(); i++) { if (i == 0) { result.Add((candles.ElementAt(i), TradingAdviceCode.HOLD)); } else if (emaShort[i] < emaLong[i] && emaShort[i - 1] > emaLong[i] && macd.Macd[i] < 0 && plusDi[i] > minusDi[i]) { result.Add((candles.ElementAt(i), TradingAdviceCode.BUY)); } else if (emaShort[i] > emaLong[i] && emaShort[i - 1] < emaLong[i] && macd.Macd[i] > 0 && plusDi[i] < minusDi[i]) { result.Add((candles.ElementAt(i), TradingAdviceCode.SELL)); } else { result.Add((candles.ElementAt(i), TradingAdviceCode.HOLD)); } } return(result); }
public override IEnumerable <(ICandle, ITradingAdviceCode)> AllForecasts(IEnumerable <ICandle> candles) { if (candles.Count() < MinNumberOfCandles) { throw new Exception("Number of candles less then expected"); } List <(ICandle, ITradingAdviceCode)> result = new List <(ICandle, ITradingAdviceCode)>(); List <decimal> closes = candles.Select(x => x.Close).ToList(); BbandItem bb = candles.Bbands(20); List <decimal?> fastMa = candles.Ema(3); List <decimal?> hl1 = candles.Select(x => (x.High + x.Low) / 2).ToList().Sma(5); List <decimal?> hl2 = candles.Select(x => (x.High + x.Low) / 2).ToList().Sma(34); List <int> ao = new List <int>(); MacdItem macd = candles.Macd(); for (int i = 0; i < hl1.Count; i++) { if (i > 0) { if (hl1[i - 1].HasValue && hl2[i - 1].HasValue && hl1[i].HasValue && hl2[i].HasValue) { ao.Add(hl1[i].Value - hl2[i].Value >= 0 ? hl1[i].Value - hl2[i].Value > hl1[i - 1].Value - hl2[i - 1].Value ? 1 : 2 : hl1[i].Value - hl2[i].Value > hl1[i - 1].Value - hl2[i - 1].Value ? -1 : -2); } else { ao.Add(0); } } else { ao.Add(0); } } for (int i = 0; i < candles.Count(); i++) { if (i < 1) { result.Add((candles.ElementAt(i), TradingAdviceCode.HOLD)); } else { if (closes[i] > bb.MiddleBand[i] && // Closed above the bollinger band Math.Abs(ao[i]) == 1 && macd.Macd[i] > macd.Signal[i] && fastMa[i] > bb.MiddleBand[i] && fastMa[i - 1] < bb.MiddleBand[i]) { result.Add((candles.ElementAt(i), TradingAdviceCode.BUY)); } else if (closes[i] < bb.MiddleBand[i] && // Closed above the bollinger band Math.Abs(ao[i]) == 2 && fastMa[i] < bb.MiddleBand[i] && fastMa[i - 1] > bb.MiddleBand[i]) { result.Add((candles.ElementAt(i), TradingAdviceCode.SELL)); } else { result.Add((candles.ElementAt(i), TradingAdviceCode.HOLD)); } } } return(result); }