public void CheckInitStatus(object obj, System.Timers.ElapsedEventArgs e) { if (!Initializing) { lock (this) { if (!Initialized && initCdlStatus == DataInitStatus.Initialized && initRtdStatus == DataInitStatus.Initialized && initSigStatus == DataInitStatus.Initialized ) { Initializing = true; if( handler !=null ) handler.IsProcessing = false; if (initRtdStatus == DataInitStatus.Initialized) { Console.WriteLine(" LatesRtds count ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; " + LatesRtds.Count); LogUtil.Info(" LatesRtds count ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; " + LatesRtds.Count); if (LatesRtds.Count > 0) { if (dataCache.DataUnits.ContainsKey(CurrentTInterval)) { dataCache.DataUnits[CurrentTInterval].AddRange(LatesRtds); } else { dataCache.DataUnits.Add(CurrentTInterval, LatesRtds); } Console.WriteLine(" dataCache.DataUnits[CurrentTInterval].Count ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; " + dataCache.DataUnits[CurrentTInterval].Count); LogUtil.Info(" dataCache.DataUnits[CurrentTInterval].Count ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; " + dataCache.DataUnits[CurrentTInterval].Count); } } RealTimeData[] rtds = null; lock (dataCache.RealTimeDatas) { if (dataCache.RealTimeDatas.Count > 0) { rtds = new RealTimeData[dataCache.RealTimeDatas.Count]; dataCache.RealTimeDatas.CopyTo(rtds); dataCache.RealTimeDatas.Clear(); } } if (dataCache.DataUnits[CurrentTInterval].Count > 0) { List<BarData> datas = dataCache.DataUnits[CurrentTInterval]; BarData lastBar = dataCache.DataUnits[CurrentTInterval][datas.Count - 1]; dataCache.RefreshCurrentTime(currentTInterval, lastBar.DateTime); IntervalData data = new IntervalData(lastBar.Open, lastBar.Close, lastBar.Low, lastBar.High); dataCache.InitCurrentData(currentTInterval, data); Console.WriteLine(" Last BAR ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; " + lastBar ); LogUtil.Info(" Last BAR ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; " + lastBar); if (rtds != null && rtds.Length > 0) { Console.WriteLine(" dataCache.RealTimeDatas. count ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; " + rtds.Length); LogUtil.Info(" dataCache.RealTimeDatas. count ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; " + rtds.Length); Console.WriteLine(lastBar); if (lastBar.IsCompleted) { foreach (RealTimeData rtd in rtds) { dataCache.UpdateDataSource(rtd); } } else { bool isCompleted = false; double max = lastBar.High; double min = lastBar.Low; List<double> prices = new List<double>(); prices.Add(lastBar.Open); prices.Add(lastBar.Close); prices.Add(lastBar.Low); prices.Add(lastBar.High); for (int k = 0; k < rtds.Length; k++) { RealTimeData rtd = rtds[k]; Console.WriteLine(" RealTimeData ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; " + rtd); LogUtil.Info(" RealTimeData ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; " + rtd); if (rtd.dateTime.CompareTo(lastBar.DateTime) < 0) continue; if (rtd.dateTime.Subtract(AppConst.AppTimeSpans[CurrentTInterval]) < lastBar.DateTime) { foreach (double price in rtd.datas) { prices.Add(price); max = Math.Max(max, price); min = Math.Min(min, price); } if (k == rtds.Length - 1 && prices.Count > 0) { lastBar.Close = prices[prices.Count - 1]; lastBar.High = max; lastBar.Low = min; IntervalData newdata = new IntervalData(lastBar.Open, lastBar.Close, lastBar.Low, lastBar.High); dataCache.InitCurrentData(currentTInterval, newdata); dataCache.DataUnits[CurrentTInterval][datas.Count - 1] = lastBar; } } else if (rtd.dateTime.Subtract(AppConst.AppTimeSpans[CurrentTInterval]) >= lastBar.DateTime) { if (!isCompleted) { if (prices != null && prices.Count > 0) { lastBar.Close = prices[prices.Count - 1]; lastBar.High = max; lastBar.Low = min; prices.Clear(); } lastBar.IsCompleted = true; dataCache.DataUnits[CurrentTInterval][datas.Count - 1] = lastBar; IntervalData newdata = new IntervalData(lastBar.Open, lastBar.Close, lastBar.Low, lastBar.High); dataCache.InitCurrentData(currentTInterval, newdata); isCompleted = true; dataCache.UpdateDataSource(rtd); } else { dataCache.UpdateDataSource(rtd); } } } } } SAR sar = new SAR(symbol.ToString(), currentTInterval); RSI rsi = new RSI(symbol.ToString(), int.Parse(AppUtil.IntervalToString(currentTInterval)),6); RSI rsi2 = new RSI(symbol.ToString(), int.Parse(AppUtil.IntervalToString(currentTInterval)),42); RSI rsi3 = new RSI(symbol.ToString(), int.Parse(AppUtil.IntervalToString(currentTInterval)),14); RSI rsi4 = new RSI(symbol.ToString(), int.Parse(AppUtil.IntervalToString(currentTInterval)),22); CR cr = new CR(symbol.ToString(), int.Parse(AppUtil.IntervalToString(currentTInterval))); ARBR arbr = new ARBR(symbol.ToString(), int.Parse(AppUtil.IntervalToString(currentTInterval)), 26); ARBR arbr2 = new ARBR(symbol.ToString(), int.Parse(AppUtil.IntervalToString(currentTInterval)),42); CCI cci = new CCI(symbol.ToString(), int.Parse(AppUtil.IntervalToString(currentTInterval)), 14); //CCI cci2 = new CCI(symbol.ToString(), int.Parse(AppUtil.IntervalToString(currentTInterval)), 42); CCI cci2 = new CCI(symbol.ToString(), int.Parse(AppUtil.IntervalToString(currentTInterval)), 24); CCI cci3 = new CCI(symbol.ToString(), int.Parse(AppUtil.IntervalToString(currentTInterval)), 42); WR wr=new WR(symbol.ToString(), int.Parse(AppUtil.IntervalToString(currentTInterval)),14); WR wr2 = new WR(symbol.ToString(), int.Parse(AppUtil.IntervalToString(currentTInterval)), 24); LWR lwr=new LWR(symbol.ToString(), int.Parse(AppUtil.IntervalToString(currentTInterval)), 14, 3, 3); BOLL boll = new BOLL(symbol.ToString(), int.Parse(AppUtil.IntervalToString(currentTInterval)), 20); for (int i = 0; i < datas.Count; i++) { BarData bar = datas[i]; if (bar.IsCompleted) { sar.handleFullCandle(ref bar); rsi.handleFullCandle(ref bar, true, 1); rsi2.handleFullCandle(ref bar, true,2); rsi3.handleFullCandle(ref bar, true,3); rsi4.handleFullCandle(ref bar, true,4); cr.handleFullCandle(ref bar); arbr.handleFullCandle(ref bar, 1); arbr2.handleFullCandle(ref bar,2); cci.handleFullCandle(ref bar,1); cci2.handleFullCandle(ref bar,2); cci3.handleFullCandle(ref bar, 3); wr.handleFullCandle(ref bar, 1); wr2.handleFullCandle(ref bar,2); lwr.handleFullCandle(ref bar, 0); boll.handleFullCandle(ref bar, 0); datas[i] = bar; } } dataCache.SARs[currentTInterval] = sar; dataCache.RISs[currentTInterval] = rsi; dataCache.RISs2[currentTInterval] = rsi2; dataCache.RISs3[currentTInterval] = rsi3; dataCache.RISs4[currentTInterval] = rsi4; dataCache.CRs[currentTInterval] = cr; dataCache.ARBRs[currentTInterval] = arbr; dataCache.ARBRs2[currentTInterval] = arbr2; dataCache.CCIs[currentTInterval] = cci; dataCache.CCIs2[currentTInterval] = cci2; dataCache.CCIs3[currentTInterval] = cci3; dataCache.WRs[currentTInterval] = wr; dataCache.WRs2[currentTInterval] = wr2; dataCache.LWRs[currentTInterval] = lwr; dataCache.BOLLs[currentTInterval] = boll; List<Signal> signalList = dataCache.SignalUnits[currentTInterval]; LogUtil.Info(" SignalList count ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; " + signalList.Count); if (signalList.Count > 0) { Signal[] signals = new Signal[signalList.Count]; signalList.CopyTo(signals, 0); Array.Sort(signals); Array.Reverse(signals); DateTime currentTime = dataCache.CurrentTimes[currentTInterval]; int startIndex = 0; foreach (Signal signal in signals) { DateTime actTime = signal.ActTime; for (int i = startIndex; i < dataCache.DataUnits[currentTInterval].Count; i++) { bool isUpdate = false; List<CandleSignal> sigList = new List<CandleSignal>(); BarData candle = dataCache.DataUnits[currentTInterval][i]; if (actTime.CompareTo(candle.DateTime) > 0) { continue; } else if (actTime.CompareTo(candle.DateTime) == 0) { startIndex = i; isUpdate = true; LogUtil.Info(" Signal " + signal ); LogUtil.Info(" Candle " + candle); // LogUtil.Info(" bf1st " + dataCache.DataUnits[currentTInterval][i-1]); //LogUtil.Info(" bf2nd " + dataCache.DataUnits[currentTInterval][i-2]); CandleSignal cs = new CandleSignal(signal, 1); sigList.Add(cs); } if (signal.GainTip!=0 && signal.GainTipPrice > 0 && candle.DateTime.CompareTo(signal.GainTipTime) == 0) { CandleSignal cs = new CandleSignal(signal, 2); sigList.Add(cs); isUpdate = true; } if (signal.StopLoss != 0 && signal.StopLossBidPrice > 0 && candle.DateTime.CompareTo(signal.StopLossTime) == 0) { CandleSignal cs = new CandleSignal(signal, 3); sigList.Add(cs); isUpdate = true; } if (signal.StopGain != 0 && signal.StopGainPrice > 0 && candle.DateTime.CompareTo(signal.StopGainTime) == 0) { CandleSignal cs = new CandleSignal(signal, 4); sigList.Add(cs); isUpdate = true; } if (isUpdate) { if (candle.SignalList != null) candle.SignalList.AddRange(sigList); else candle.SignalList = sigList; candle.RefreshExValues(); dataCache.DataUnits[currentTInterval][i] = candle; } } List<CandleSignal> sList = new List<CandleSignal>(); if (signal.ActTime.CompareTo(currentTime) <= 0) { if (signal.ActTime.CompareTo(currentTime) == 0) { CandleSignal cs = new CandleSignal(signal, 1); sList.Add(cs); } if (signal.GainTipPrice > 0 && signal.GainTipTime.CompareTo(currentTime) == 0) { CandleSignal cs = new CandleSignal(signal, 2); sList.Add(cs); } if (signal.StopLossBidPrice > 0 && signal.StopLossTime.CompareTo(currentTime) == 0) { CandleSignal cs = new CandleSignal(signal, 3); sList.Add(cs); } if (signal.StopGainPrice > 0 && signal.StopGainTime.CompareTo(currentTime) == 0) { CandleSignal cs = new CandleSignal(signal, 4); sList.Add(cs); } dataCache.CurrentDatas[currentTInterval].SignalList.AddRange(sList); } } } Console.WriteLine(" LAST ###### "+lastBar); LogUtil.Info(" LAST ###### " + lastBar); dataCache.RefreshDataUnits(datas); } //dataCache.Start(); if (AppContext.IsLoading) { AppContext.IsFirstProviderInit = true; isAddCandle = true; Initialized = true; Initializing = false; ProviderHelper.CleanInitDirs(this); } else { isAddCandle = true; Initialized = true; Process(null, null); timerInit.Stop(); timerAuto.Start(); Initializing = false; ProviderHelper.CleanInitDirs(this); Console.WriteLine(" End Now ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; " + DateTime.Now.ToLongTimeString()); } } } } }
private void UpdateIntervalData(Interval intervSpan, ref IntervalData intvData, double[] prices, DateTime time, DataProvider provider) { if (currentTimes.ContainsKey(intervSpan) && currentDatas.ContainsKey(intervSpan)) { DateTime lastTime = currentTimes[intervSpan]; DateTime currTime = AppUtil.GetCurrentIntervalTime(lastTime, time, intervSpan); TimeSpan span = time.Subtract(lastTime); Console.WriteLine(" currentTimes[TInterval.MIN1] span " + span + " lastTime " + lastTime + " real time " + time + " currTime " + currTime); LogUtil.Info(" currentTimes[TInterval.MIN1] span " + span + " lastTime " + lastTime + " real time " + time + " currTime " + currTime); if (lastTime.CompareTo(time) > 0) { return; } else if (span >= AppConst.AppTimeSpans[intervSpan]) { lastTime = AppUtil.GetLatestIntervalTime(lastTime, time, intervSpan); Console.WriteLine(" span > interval span::: " + span + " lastTime " + lastTime + " real time " + time); BarData barData = dataUnits[intervSpan][dataUnits[intervSpan].Count - 1]; barData.DateTime = lastTime; barData.Open = intvData.Open; barData.Close = intvData.Close; barData.Low = intvData.Min; barData.High = intvData.Max; barData.SignalList = intvData.SignalList; Console.WriteLine(" BarData #### time " + barData); List <CandleSignal> currSignalList = new List <CandleSignal>(); Signal[] signals = null; lock (AppConst.SignalDatasLocker) { signals = new Signal[AppContext.SignalDatas.Count]; AppContext.SignalDatas.CopyTo(signals); } if (signals != null) { int count = 0; Array.Sort(signals); foreach (Signal s in signals) { if (s.Symbol == provider.Symbol && s.Interval == provider.CurrentTInterval) { if (s.ActTime.CompareTo(lastTime) == 0 && s.Arrow != 0) { CandleSignal cs = new CandleSignal(s, 1); if (!barData.SignalList.Contains(cs)) { barData.SignalList.Add(cs); } } if (s.Arrow != 0 && s.ActTime.CompareTo(currTime) == 0) { CandleSignal cs = new CandleSignal(s, 1); currSignalList.Add(cs); } if (s.StopLoss != 0 && s.StopLossTime.CompareTo(lastTime) == 0) { CandleSignal cs = new CandleSignal(s, 3); if (!barData.SignalList.Contains(cs)) { barData.SignalList.Add(cs); } } if (s.StopLoss != 0 && s.StopLossTime.CompareTo(currTime) == 0) { CandleSignal cs = new CandleSignal(s, 3); currSignalList.Add(cs); } if (s.GainTip != 0 && s.GainTipTime.CompareTo(lastTime) == 0) { CandleSignal cs = new CandleSignal(s, 2); if (!barData.SignalList.Contains(cs)) { barData.SignalList.Add(cs); } } if (s.GainTip != 0 && s.GainTipTime.CompareTo(currTime) == 0) { CandleSignal cs = new CandleSignal(s, 2); currSignalList.Add(cs); } if (s.StopGain != 0 && s.StopGainTime.CompareTo(lastTime) == 0) { CandleSignal cs = new CandleSignal(s, 4); if (!barData.SignalList.Contains(cs)) { barData.SignalList.Add(cs); } } if (s.StopGain != 0 && s.StopGainTime.CompareTo(currTime) == 0) { CandleSignal cs = new CandleSignal(s, 4); currSignalList.Add(cs); } if (count > 5) { break; } count++; } } } barData.RefreshExValues(); Console.WriteLine(" BarData ############ time " + barData); LogUtil.Info(" Last BarData ##### " + barData); SAR sar = null; CR cr = null; RSI rsi = null; RSI rsi2 = null; RSI rsi3 = null; RSI rsi4 = null; ARBR arbr = null; ARBR arbr2 = null; CCI cci = null; CCI cci2 = null; CCI cci3 = null; WR wr = null; WR wr2 = null; LWR lwr = null; BOLL boll = null; if (!provider.Initializing && provider.Initialized) { sar = iSARs[intervSpan]; cr = iCRs[intervSpan]; rsi = iRISs[intervSpan]; rsi2 = iRISs2[intervSpan]; rsi3 = iRISs3[intervSpan]; rsi4 = iRISs4[intervSpan]; arbr = iARBRs[intervSpan]; arbr2 = iARBRs2[intervSpan]; cci = iCCIs[intervSpan]; cci2 = iCCIs2[intervSpan]; cci3 = iCCIs3[intervSpan]; wr = iWRs[intervSpan]; wr2 = iWRs2[intervSpan]; lwr = iLWRs[intervSpan]; boll = iBOLLs[intervSpan]; sar.handleFullCandle(ref barData); rsi.handleFullCandle(ref barData, true, 1); rsi2.handleFullCandle(ref barData, true, 2); rsi3.handleFullCandle(ref barData, true, 3); rsi4.handleFullCandle(ref barData, true, 4); cr.handleFullCandle(ref barData); arbr.handleFullCandle(ref barData, 1); arbr2.handleFullCandle(ref barData, 2); cci.handleFullCandle(ref barData, 1); cci2.handleFullCandle(ref barData, 2); cci3.handleFragCandle(ref barData, 3); wr.handleFullCandle(ref barData, 1); wr2.handleFullCandle(ref barData, 2); lwr.handleFullCandle(ref barData, 0); boll.handleFullCandle(ref barData, 0); } if (dataUnits.ContainsKey(intervSpan)) { dataUnits[intervSpan][dataUnits[intervSpan].Count - 1] = (barData); } else { List <BarData> list = new List <BarData>(); list.Add(barData); dataUnits.Add(intervSpan, list); } if (provider.CurrentTInterval == intervSpan) { provider.IsUpdateCandle = false; provider.IsAddCandle = true; } Console.WriteLine(" New BarData #### time " + currTime); currentTimes[intervSpan] = currTime; Console.WriteLine(" currentTimes[" + intervSpan + "] " + currentTimes[intervSpan]); Console.WriteLine(" NEW RTD.symbol time " + time + " price " + prices[0]); intvData = new IntervalData(0); double p = prices[0]; intvData.Max = p; intvData.Min = p; intvData.Open = p; intvData.Close = p; intvData.PriceList.Clear(); foreach (double price in prices) { intvData.PriceList.Add(price); intvData.Max = Math.Max(intvData.Max, price); intvData.Min = Math.Min(intvData.Min, price); } barData = new BarData(currTime, intvData.Open, intvData.Close, intvData.Min, intvData.Max, 0); barData.SignalList = currSignalList; barData.RefreshExValues(); if (!provider.Initializing && provider.Initialized) { barData.Sar = sar.getNextSAR(); rsi.handleFullCandle(ref barData, false, 1); rsi2.handleFullCandle(ref barData, false, 2); rsi3.handleFullCandle(ref barData, false, 3); rsi4.handleFullCandle(ref barData, false, 4); cr.handleFullCandle(ref barData); cci.handleFragCandle(ref barData, 2); cci2.handleFragCandle(ref barData, 2); iSARs[intervSpan] = sar; iRISs[intervSpan] = rsi; iRISs2[intervSpan] = rsi2; iRISs3[intervSpan] = rsi3; iRISs4[intervSpan] = rsi4; iCRs[intervSpan] = cr; iARBRs[intervSpan] = arbr; iARBRs2[intervSpan] = arbr2; iCCIs[intervSpan] = cci; iCCIs2[intervSpan] = cci2; iCCIs3[intervSpan] = cci3; iWRs[intervSpan] = wr; iWRs2[intervSpan] = wr2; iLWRs[intervSpan] = lwr; iBOLLs[intervSpan] = boll; } LogUtil.Info(" New BarData #### " + barData); dataUnits[intervSpan].Add(barData); Console.WriteLine(" New intvData ############ op " + intvData.Open + " cls " + intvData.Close + " max " + intvData.Max + " low " + intvData.Min); Console.WriteLine(" allDataUnits[provider.Symbol][intervSpan]..Count ::::::::::::::::::::::::::: " + dataUnits[intervSpan].Count); } else { Console.WriteLine(" IN currentTimes[" + intervSpan + "] " + currentTimes[intervSpan]); foreach (double price in prices) { intvData.PriceList.Add(price); intvData.Max = Math.Max(intvData.Max, price); intvData.Min = Math.Min(intvData.Min, price); } Signal[] signals = null; lock (AppConst.SignalDatasLocker) { signals = new Signal[AppContext.SignalDatas.Count]; AppContext.SignalDatas.CopyTo(signals); } if (signals != null) { Array.Sort(signals); int count = 0; foreach (Signal s in signals) { if (s.Symbol == provider.Symbol && s.Interval == provider.CurrentTInterval) { if (s.Arrow != 0 && s.ActTime.CompareTo(lastTime) == 0) { CandleSignal cs = new CandleSignal(s, 1); if (!intvData.SignalList.Contains(cs)) { intvData.SignalList.Add(cs); } } if (s.GainTip != 0 && s.GainTipTime.CompareTo(lastTime) == 0) { CandleSignal cs = new CandleSignal(s, 2); if (!intvData.SignalList.Contains(cs)) { intvData.SignalList.Add(cs); } } if (s.StopLoss != 0 && s.StopLossTime.CompareTo(lastTime) == 0) { CandleSignal cs = new CandleSignal(s, 3); if (!intvData.SignalList.Contains(cs)) { intvData.SignalList.Add(cs); } } if (s.StopGain != 0 && s.StopGainTime.CompareTo(lastTime) == 0) { CandleSignal cs = new CandleSignal(s, 4); if (!intvData.SignalList.Contains(cs)) { intvData.SignalList.Add(cs); } } if (count > 5) { break; } count++; } } } intvData.Close = intvData.PriceList.Last <double>(); //intvData.isInitialized = true; if (provider.CurrentTInterval == intervSpan) { provider.IsUpdateCandle = true; provider.IsAddCandle = false; } LogUtil.Info(" Updated intvData ############ " + intvData); } Console.WriteLine(" Update intvData ############ op " + intvData.Open + " cls " + intvData.Close + " max " + intvData.Max + " low " + intvData.Min); //} //intvData.isUpdated = true; } }