public SelectResult select(DataStoreHelper dsh, SelectMode selectMode, int date, List <IStrategy> strategyList, SelectHint hint = null) { bool bShowProgress = date == Utils.NowDate(); if (bShowProgress) { App.host_.uiStartProcessBar(); } SelectResult re = new SelectResult(); dsh.iSZIndex_ = App.ds_.index(App.ds_.szListData_, date); for (int isk = 0; isk < App.ds_.stockList_.Count; ++isk) { Stock sk = App.ds_.stockList_[isk]; if (bShowProgress) { App.host_.uiSetProcessBar(String.Format("正在检测是否选择{0}", sk.code_), isk * 100 / App.ds_.stockList_.Count); } int iDateIndexHint = -1; if (hint != null) { iDateIndexHint = hint.nextWantedIndexHintDict_[sk]; } dsh.setStock(sk); for (int i = 0; i < strategyList.Count; ++i) { IStrategy stra = strategyList[i]; Dictionary <String, String> rateItemDict = null; String sigInfo = ""; try { int iIndex = App.ds_.index(sk, date, iDateIndexHint); if (iIndex == -1) { continue; } if (hint != null) { hint.nextWantedIndexHintDict_[sk] = iIndex + 1; } dsh.iIndex_ = iIndex; if (dsh.dataList_[iIndex] == Data.NowInvalidData) { continue; } FocusOn fon = stra.focusOn(); int beforDateCount = sk.dataList_.Count - iIndex; bool isNewStock = beforDateCount < Setting.MyNewStockLimit; switch (fon) { case FocusOn.FO_Old: if (isNewStock) { continue; } break; case FocusOn.FO_All: break; case FocusOn.FO_New: if (!isNewStock) { continue; } break; default: throw new ArgumentException("Unknown focusOn"); } if (!isNewStock && dsh.MA(Info.A, 5, 1) < 20000) { continue; } rateItemDict = stra.select(dsh, selectMode, ref sigInfo); if (rateItemDict == null) { continue; } } catch (DataException /*ex*/) { continue; } SelectItem selItem = new SelectItem(); selItem.code_ = sk.code_; selItem.date_ = date; selItem.sigInfo_ = sigInfo; selItem.strategyName_ = stra.name(); selItem.rateItemDict_ = rateItemDict; re.selItems_.Add(selItem); } } Dictionary <String, int> strategySelCountDict = new Dictionary <String, int>(); foreach (var item in re.selItems_) { if (strategySelCountDict.ContainsKey(item.strategyName_)) { ++strategySelCountDict[item.strategyName_]; } else { strategySelCountDict.Add(item.strategyName_, 1); } } foreach (var item in re.selItems_) { item.sameDayStrategySelCount_ = strategySelCountDict[item.strategyName_]; item.sameDaySelCount_ = re.selItems_.Count; } if (bShowProgress) { App.host_.uiFinishProcessBar(); } return(re); }
Dictionary <String, String> IStrategy.select(DataStoreHelper dsh, SelectMode selectMode, ref String sigInfo) { var zf = dsh.Ref(Info.ZF); if (zf > 0 || zf < -0.06) { return(null); } if (dsh.Ref(Info.OF, 1) < -0.03) { return(null); } if (dsh.Ref(Info.ZF, 1) > 0) { return(null); } int iSigDateIndex = -1; int nUpCount = 0; int nUStopCount = 0; int nDStopCount = 0; bool bMeetRealUp = false; bool bHasUpShadowTooHight = false; bool bHasDownShadowTooLow = false; float otherMaxVol = float.MinValue; float otherMaxZF = float.MinValue; float otherMaxC = 0; float otherMaxH = 0; float sigDateVol = 0; float sigZF = 0; float minDownShadow = float.MaxValue; float maxUpShadow = float.MinValue; float totalUp = 0; float totalDown = 0; float otherMinZF = float.MaxValue; float otherMaxCO = float.MinValue; bool bMeetTradeSigAllready = false; int nNotRealCount = 0; for (int i = 1; i < 8; ++i) { var curOf = dsh.Ref(Info.OF, i); var curHf = dsh.Ref(Info.HF, i); var curLf = dsh.Ref(Info.LF, i); var curZf = dsh.Ref(Info.ZF, i); var curPreZf = dsh.Ref(Info.ZF, i + 1); var vol = dsh.Ref(Info.V, i); var coRate = dsh.Ref(Info.CO, i) / dsh.Ref(Info.C, i + 1); if (curZf > 0 && curZf < 0.095 && coRate > 0.05 && vol > dsh.MA(Info.V, 5, i + 1) && dsh.HH(Info.CO, 30, i) == i) { for (int j = i + 1; j < i + 6; ++j) { if (dsh.Ref(Info.V, j) > vol && dsh.Ref(Info.C, j) < dsh.Ref(Info.O, j)) { return(null); } } if (dsh.AccZF(8, i + 1) < -0.1) { return(null); } if (dsh.AccZF(3, i + 1) > 0.095) { return(null); } int iMaxVolIndex = dsh.HH(Info.V, 20, i); if (dsh.Ref(Info.C, iMaxVolIndex) > dsh.Ref(Info.O, iMaxVolIndex)) { iSigDateIndex = i; sigDateVol = vol; sigZF = curZf; break; } } if (curOf < -0.04) { return(null); } if (curZf > 0 && dsh.IsReal(i)) { nUpCount++; } if (!dsh.IsReal(i)) { ++nNotRealCount; } if (curZf > 0.095) { nUStopCount++; } else if (curZf < -0.095) { nDStopCount++; } else if (curZf > 0.012) { bMeetRealUp = true; } if (curZf < -0.03 && dsh.Ref(Info.ZF, i - 1) > 0) { bMeetTradeSigAllready = true; } float upShadow = dsh.UpShadow(i); float downShadow = dsh.DownShadow(i); if (upShadow > maxUpShadow) { maxUpShadow = upShadow; } if (downShadow < minDownShadow) { minDownShadow = downShadow; } if (curZf > 0) { totalUp += curZf; } else { totalDown += curZf; } otherMaxVol = Math.Max(vol, otherMaxVol); otherMaxZF = Math.Max(otherMaxZF, curZf); otherMaxC = Math.Max(dsh.Ref(Info.C, i), otherMaxC); otherMaxH = Math.Max(dsh.Ref(Info.H, i), otherMaxH); otherMinZF = Math.Min(otherMinZF, curZf); otherMaxCO = Math.Max(otherMaxCO, dsh.Ref(Info.CO, i)); } if (iSigDateIndex == -1) { return(null); } sigInfo = dsh.Date(iSigDateIndex).ToString(); if (otherMinZF > 0.02) { return(null); } if (nNotRealCount > 1) { return(null); } if (totalDown + totalUp < -0.01) { return(null); } if (maxUpShadow > 0.03) { bHasUpShadowTooHight = true; } if (minDownShadow < -0.03) { bHasDownShadowTooLow = true; } if (nUpCount < 2) { return(null); } if (otherMaxH < dsh.Ref(Info.H, iSigDateIndex)) { return(null); } if (/*nUStopCount > 0 ||*//* nDStopCount > 0 || */ bMeetTradeSigAllready || !bMeetRealUp) { return(null); } float maxUpF = (otherMaxC - dsh.Ref(Info.C, iSigDateIndex)) / dsh.Ref(Info.C, iSigDateIndex); if (maxUpF < 0.015 /* || maxUpF > 0.04*/) { return(null); } if (dsh.Ref(Info.C) < dsh.Ref(Info.L, iSigDateIndex)) { return(null); } if (bHasUpShadowTooHight || bHasDownShadowTooLow) { return(null); } if ( dsh.Ref(Info.ZF, 2) < 0.005 && dsh.Ref(Info.ZF, 3) < 0.005) { return(null); } if (sigDateVol < otherMaxVol * 1.2) { return(null); } if (sigDateVol > otherMaxVol * 2) { return(null); } if (otherMaxZF + zf > 0) { return(null); } if (otherMaxZF + zf < -0.02) { return(null); } if (dsh.Ref(Info.LF) < -0.06) { return(null); } var delta = (dsh.Ref(Info.C) - dsh.Ref(Info.O, 1)) / dsh.Ref(Info.C, 1); if (delta > -0.01) { return(null); } if (!selectBySZ(dsh)) { return(null); } var ret = new Dictionary <String, String>(); ret[String.Format("delta/{0}", delta < -0.02 ? "1" : "0")] = ""; ret[String.Format("maxUp/{0}", maxUpF > 0.02 ? "1" : "0")] = ""; return(ret); }
Dictionary <String, String> IStrategy.select(DataStoreHelper dsh, SelectMode selectMode, ref String sigInfo) { var zf = dsh.Ref(Info.ZF); if (zf > 0 || zf < -0.095) { return(null); } if (!dsh.IsReal()) { return(null); } if (dsh.Ref(Info.OF, 1) < -0.03) { return(null); } if (dsh.Ref(Info.LF) < -0.06) { return(null); } int iSigDateIndex = -1; int nUpCount = 0; int nDownCount = 0; int nUStopCount = 0; int nDStopCount = 0; bool bMeetTradeSigAllready = false; bool bMeetRealUp = false; float sigDateVol = 0; float otherMaxVol = 0; bool bHasUpShadowTooHight = false; bool bHasDownShadowTooLow = false; float otherMaxZF = 0; float otherMinZF = float.MaxValue; float otherMaxC = 0; float otherMaxH = 0; float sumOfSigDateZF = 0; float otherMaxDownV = 0; float minSigV = float.MaxValue; float totalUp = 0; float totalDown = 0; for (int i = 1; i < 8; ++i) { var curOf = dsh.Ref(Info.OF, i); var curHf = dsh.Ref(Info.HF, i); var curZf = dsh.Ref(Info.ZF, i); var curPreZf = dsh.Ref(Info.ZF, i + 1); var vol = dsh.Ref(Info.V, i); var preVol = dsh.Ref(Info.V, i + 1); if (dsh.Ref(Info.OF, i) > 0.03 && curZf < 0) { return(null); } float ma5 = dsh.MA(Info.V, 10, i + 2); float hhv = dsh.Ref(Info.V, dsh.HH(Info.V, 5, i + 2)); if (curZf > 0.01 && curPreZf > 0.01 && vol > 1.3 * hhv && preVol > 1.3 * hhv && (vol < vRate_ * preVol && preVol < vRate_ * vol) && vol / ma5 > vRate_ && preVol / ma5 > vRate_ && dsh.Ref(Info.ZF, i + 2) < 0.05 && dsh.Ref(Info.V, i + 2) / dsh.MA(Info.V, 5, i + 3) < vRate_) { for (int j = i + 2; j < i + 7; j++) { if (dsh.Ref(Info.ZF, j) < -0.095) { return(null); } } if (dsh.AccZF(2, i) < 0.05) { return(null); } { iSigDateIndex = i; sigDateVol = Math.Max(dsh.Ref(Info.V, i + 1), vol); minSigV = Math.Min(dsh.Ref(Info.V, i + 1), vol); break; } } otherMaxVol = Math.Max(vol, otherMaxVol); if (curZf > 0.005 && dsh.IsReal(i)) { nUpCount++; } else if (curZf < -0.005 && dsh.IsReal(i)) { nDownCount++; } if (curZf > 0.095) { nUStopCount++; } else if (curZf < -0.095) { nDStopCount++; } if (curZf < -0.03) { bMeetTradeSigAllready = true; } if (curZf > 0) { totalUp += curZf; } else { totalDown += curZf; } if (curZf > 0.012) { bMeetRealUp = true; } if (dsh.UpShadow(i) > 0.03) { bHasUpShadowTooHight = true; } if (dsh.DownShadow(i) < -0.03) { bHasDownShadowTooLow = true; } otherMaxZF = Math.Max(otherMaxZF, curZf); otherMinZF = Math.Min(otherMinZF, curZf); otherMaxC = Math.Max(dsh.Ref(Info.C, i), otherMaxC); otherMaxH = Math.Max(dsh.Ref(Info.H, i), otherMaxH); if (curZf < 0) { otherMaxDownV = Math.Max(otherMaxDownV, vol); } } if (iSigDateIndex == -1) { return(null); } // sigInfo = dsh.Date(iSigDateIndex).ToString(); if (totalDown + totalUp < -0.01) { return(null); } if (nUpCount < 2) { return(null); } if (/*nUStopCount > 0 ||*//* nDStopCount > 0 || */ bMeetTradeSigAllready || !bMeetRealUp) { return(null); } float maxUpF = (otherMaxC - dsh.Ref(Info.C, iSigDateIndex)) / dsh.Ref(Info.C, iSigDateIndex); if (maxUpF < 0.015 /* || maxUpF > 0.04*/) { return(null); } if (sigDateVol < otherMaxVol * 1.2) { return(null); } if (otherMaxZF + zf > 0) { return(null); } sigInfo = (otherMaxZF + zf).ToString("F4"); if (otherMaxZF + zf < -0.02) { return(null); } if (bHasUpShadowTooHight || bHasDownShadowTooLow) { return(null); } if ( dsh.Ref(Info.ZF, 2) < 0.005 && dsh.Ref(Info.ZF, 3) < 0.005) { return(null); } if (dsh.Ref(Info.C, iSigDateIndex) < dsh.Ref(Info.O, iSigDateIndex)) { return(null); } if (dsh.Ref(Info.C, iSigDateIndex + 1) < dsh.Ref(Info.O, iSigDateIndex + 1)) { return(null); } if (Math.Min(dsh.Ref(Info.ZF, iSigDateIndex), dsh.Ref(Info.ZF, iSigDateIndex + 1)) + dsh.Ref(Info.ZF, iSigDateIndex + 2) < -0.01) { return(null); } var delta = (dsh.Ref(Info.C) - dsh.Ref(Info.O, 1)) / dsh.Ref(Info.C, 1); if (delta > -0.01) { return(null); } var szZF = dsh.SZRef(Info.ZF); if (szZF > 0 && szZF < 0.011 && dsh.SZAcc(Info.ZF, 7, 1) > 0.03) { return(null); } if (!selectBySZ(dsh)) { return(null); } var ret = new Dictionary <String, String>(); ret[String.Format("sumSig/{0}", sumOfSigDateZF > 0.12 ? "1" : "0")] = ""; ret[String.Format("delta/{0}", delta < -0.02 ? "1" : "0")] = ""; ret[String.Format("maxUp/{0}", maxUpF > 0.02 ? "1" : "0")] = ""; ret[String.Format("maxZF/{0}", otherMaxZF + zf > -0.01 ? "1" : "0")] = ""; ret[String.Format("diffzf/{0}", otherMaxZF + zf > -0.02 ? "1" : "0")] = ""; return(ret); }