private static List<DataStruct> ProcessPerMin(List<string[]> lstEntity) { List<DataStruct> QminList = new List<DataStruct>(); try { int lstLen = lstEntity.Count; int tw = TimeWindow; string data; string time; int startIndex=0; //double price; //double volume; InputStr tInput = new InputStr(); TimeProc timeProc = new TimeProc(); DataStruct item; int lastTime= timeProc.time2int("9:15:00"); // 9:14:00 string lastData = ""; List<InputStr> list = new List<InputStr>(); if (Mode == 1) { list.Clear(); int index; for (index = 0; index < lstLen; index++) { string[] ht = lstEntity[index]; tInput = new InputStr(); time = ht[1]; data = ht[0]; tInput.setTime(time); tInput.setData(data); tInput.setPrice(double.Parse(ht[2])); tInput.setVolume(int.Parse(ht[3])); int now = timeProc.time2int(time); if (now-lastTime >=tw ) // collect a set in 1 minute { item = new DataStruct(); item.setNextMinIndex(index); item.setStartMinIndex(startIndex); ProcessList(list, ref item); list.Clear(); QminList.Add(item); startIndex = index; while (lastTime + tw <= now) { lastTime += tw; if (lastTime > 41400 && lastTime < 46800) // 41400 = 11:30:00 lastTime = 46800; // 46800 = 13:00:00 } } lastData = data; list.Add(tInput); } // add the last minute item = new DataStruct(); item.setNextMinIndex(index); item.setStartMinIndex(startIndex); ProcessList(list, ref item); list.Clear(); QminList.Add(item); } else // time window { int index; for (index = 0; index < lstLen;) { int t = 0; while (index < lstLen) { time = lstEntity[index][1]; t = timeProc.time2int(time); if (index < lstLen && t >= lastTime) break; index++; } while (t >= lastTime + tw) { lastTime++; if (lastTime > 41400 && lastTime < 46800) lastTime = 46800; if (lastTime > timeProc.time2int("15:15:00")) break; } list.Clear(); int si; for (si = index; si < lstLen; si++) { time = lstEntity[si][1]; if (timeProc.time2int(time) < lastTime + tw) { string[] ht = lstEntity[si]; tInput = new InputStr(); time = ht[1]; data = ht[0]; tInput.setTime(time); tInput.setData(data); tInput.setPrice(double.Parse(ht[2])); tInput.setVolume(int.Parse(ht[3])); list.Add(tInput); } else { item = new DataStruct(); item.setNextMinIndex(si); item.setStartMinIndex(index); ProcessList(list, ref item); QminList.Add(item); list.Clear(); lastTime++; break; } } if (list.Count > 0) // the last list { item = new DataStruct(); item.setNextMinIndex(si); item.setStartMinIndex(index); ProcessList(list, ref item); list.Clear(); QminList.Add(item); lastTime++; } } } } catch (System.Exception ex) { MessageBox.Show(ex.ToString()); } return QminList; }
private static void ProcessList(List<InputStr> List, ref DataStruct item) { item.setStartTime(List[0].getTime()); item.setData(List[0].getData()); item.setPiOpen(List[0].getPrice()); int len = List.Count; item.setEndTime(List[len - 1].getTime()); item.setPiEnd(List[len - 1].getPrice()); double minPrice = 999999999; double maxPrice = 0; string maxPriceTime = ""; int Qi=0; int MaxPriceTotal = 0; int MinPriceTotal = 0; TimeProc tp = new TimeProc(); item.setQiTime(tp.getMinute(List[0].getTime())); for (int i = 0; i < len; i++ ) { InputStr itr = List[i]; Qi += itr.getVolume(); if (itr.getPrice() > maxPrice) { maxPrice = itr.getPrice(); maxPriceTime = itr.getTime(); MaxPriceTotal = Qi; } if (itr.getPrice() < minPrice) { minPrice = itr.getPrice(); MinPriceTotal = Qi; } } item.setPiMax(maxPrice); item.setPiMin(minPrice); item.setPiTime(maxPriceTime); item.setQi(Qi); if (gzRadioMode==1 && item.getPiEnd()>item.getPiOpen() || gzRadioMode==2 && max(item.getPiEnd(),item.getPiMax())>=item.getPiOpen()) { item.setType("��"); item.setPiTotal(MaxPriceTotal); } else { item.setType("��"); item.setPiTotal(MinPriceTotal); } }
private static double getNextNMin(ref List<DataStruct> Qlist, ref List<string[]> lstEntity, int index) { TimeProc tproc = new TimeProc(); int len = lstEntity.Count; double m = 999999999; int c = Next; int startTime = tproc.time2int(lstEntity[Qlist[index].getNextMinIndex()][1]); for (int i = Qlist[index].getNextMinIndex(); i < len && (tproc.time2int(lstEntity[i][1]) - startTime < c); i++) if (double.Parse(lstEntity[i][2]) < m) m = double.Parse(lstEntity[i][2]); return m; }
private static double getPrevNMin(ref List<DataStruct> Qlist, ref List<string[]> lstEntity, int index) { TimeProc tproc = new TimeProc(); double m = 999999999; int c = Prev; int startTime = tproc.time2int(lstEntity[Qlist[index].getStartMinIndex()][1]); for (int i = Qlist[index].getStartMinIndex(); i >= 0 && (startTime - tproc.time2int(lstEntity[i][1]) < c); i--) if (double.Parse(lstEntity[i][2]) < m) m = double.Parse(lstEntity[i][2]); return m; }
private static void completeQ(ref List<DataStruct> Qlist, ref List<string[]> lstEntity, int i) { int QlistLen = Qlist.Count; int len = lstEntity.Count; if (Qlist[i].getType() == "��" && i > 0 && i < QlistLen - 1) { double prevMin = getPrevNMin(ref Qlist, ref lstEntity, i); double nextMax = getNextNMax(ref Qlist, ref lstEntity, i); Qlist[i].setPiBefore(prevMin); Qlist[i].setPiNext(nextMax); Qlist[i].setP3(getP3NextMin(ref Qlist, i + 1)); Qlist[i].setPStopProfit(Qlist[i].getPiMax() - (Qlist[i].getPiMax() - Qlist[i-1].getPiMin()) * Ratio1); Qlist[i].setPStopLoss(Qlist[i].getPiMax() + (Qlist[i].getPiMax() - Qlist[i-1].getPiMin()) * Ratio2); } if (Qlist[i].getType() == "��" && i > 0 && i < QlistLen - 1) { double prevMax = getPrevNMax(ref Qlist, ref lstEntity, i); double nextMin = getNextNMin(ref Qlist, ref lstEntity, i); Qlist[i].setPiBefore(prevMax); Qlist[i].setPiNext(nextMin); Qlist[i].setP3(getP3NextMax(ref Qlist, i + 1)); Qlist[i].setPStopProfit(Qlist[i].getPiMin() + (Qlist[i-1].getPiMax() - Qlist[i].getPiMin()) * Ratio1); Qlist[i].setPStopLoss(Qlist[i].getPiMin() - (Qlist[i-1].getPiMax() - Qlist[i].getPiMin()) * Ratio2); } string today = Qlist[i].getData(); int j = Qlist[i].getNextMinIndex(); TimeProc tp = new TimeProc(); int cc = 0; for (; j<len && cc<3; j++) { string[] ht = lstEntity[j]; if (floatEqual(double.Parse(ht[2]), Qlist[i].getPStopProfit())) { Qlist[i].setPStopProfitTime(ht[1]); cc++; } if (floatEqual(double.Parse(ht[2]), Qlist[i].getPStopLoss())) { Qlist[i].setPStopLossTime(ht[1]); cc++; } if (floatEqual(double.Parse(ht[2]), Qlist[i].getP3())) { Qlist[i].setP3Time(ht[1]); cc++; } } }