using BinanceExchange.API.Models.Response; using Newtonsoft.Json; using SignalsTest; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace SignalsTest { public class TAReport { public string pair; public int interval; [JsonIgnore] public KlineCandleStickResponse candle; public decimal Close; public decimal Open; public decimal High; public decimal Low; public DateTime CloseTime; public decimal SMA7; public decimal SMA25; public decimal SMA99; public decimal EMA7,EMA25, EMA99; public decimal MACD = 0; public decimal EMACD = 0; public decimal ATR14; public decimal ATR10; public decimal AVGDiff = 0; public decimal STHigh; public decimal STLow; public decimal ST; public decimal RSI=0; public bool STUp => STHigh > Close; public static TAReport Generate(string _pair, int _interval,List response, int index, List history) { TAReport report = new TAReport(); report.pair = _pair; report.interval = _interval; report.candle = response[index]; report.Open = response[index].Open; report.Close = response[index].Close; report.High = response[index].High; report.Low = response[index].Low; report.CloseTime = response[index].CloseTime; // foreach(int sma in m_SMA) // { // report.SMAs.Add(sma, Indicators.getSMA(response, index, sma)); // } // foreach (int ema in m_EMA) // { // report.SMAs.Add(ema, Indicators.getEMA(response, index, 0, ema)); // } report.SMA7 = Indicators.getSMA(response, index,7); report.SMA25 = Indicators.getSMA(response, index,25); report.SMA99 = Indicators.getSMA(response, index,99); report.EMA7 = Indicators.getEMA(response, index,0, 7); report.EMA25 = Indicators.getEMA(response, index,0,25); report.EMA99 = Indicators.getEMA(response, index,0,99); report.MACD = Indicators.getMACD(response, 12, 26, index); report.RSI = Indicators.getRSI(response,index); if(history == null){ return report; } //MACD Signal List MACDHistory = new List(); List ATR10History = new List(); List ATR14History = new List(); foreach(TAReport item in history){ MACDHistory.Add(item.MACD); ATR10History.Add(item.ATR10); ATR14History.Add(item.ATR14); } report.EMACD = Indicators.getEMA(MACDHistory, index,0,9); report.ATR10 = Indicators.getATR(response, 10,index, ATR10History); report.ATR14 = Indicators.getATR(response, 14,index, ATR14History); //SuperTrend decimal SuperTrendUpper = (response[index].High + response[index].Low) / 2 + 3 * report.ATR10; decimal SuperTrendLower = (response[index].High + response[index].Low) / 2 - 3 * report.ATR10; decimal SuperTrendFinal = 0; if (index > 0) { if (history[index - 1].STHigh > SuperTrendUpper || history[index - 1].Close > history[index - 1].STHigh) { } else { SuperTrendUpper = history[index - 1].STHigh; } if (history[index - 1].STLow < SuperTrendLower || history[index - 1].Close < history[index - 1].STLow) { } else { SuperTrendLower = history[index - 1].STLow; } } SuperTrendFinal = report.STUp ? SuperTrendLower : SuperTrendUpper; report.ST = SuperTrendFinal; return report; } } } public static class CustomExtensions { public static string toJson(this TAReport report) { return JsonConvert.SerializeObject(report, Formatting.Indented); } }