public static UpDownPatternEnum GetOneLineUpDownPatternL(LimitedList <double> yList) { UpDownPatternEnum upDownPattern = UpDownPatternEnum.None; var list = yList.ToList(); if (list.Count < 10) { return(upDownPattern); } double avgPoint = list.Average(); double highAvgPoint = (list.Max() + avgPoint) / 2.0; double lowAvgPoint = (list.Min() + avgPoint) / 2.0; return(GetUpDownPattern(yList, lowAvgPoint)); }
public static string GetUpDownPatternToChars(UpDownPatternEnum upDownPattern) { string result = ""; if (upDownPattern == UpDownPatternEnum.UpDownUpDownUpDownUp) { result = "UDUDUDU"; } else if (upDownPattern == UpDownPatternEnum.DownUpDownUpDownUpDown) { result = "DUDUDUD"; } else if (upDownPattern == UpDownPatternEnum.UpDownUpDownUpDown) { result = "UDUDUD"; } else if (upDownPattern == UpDownPatternEnum.DownUpDownUpDownUp) { result = "DUDUDU"; } else if (upDownPattern == UpDownPatternEnum.UpDownUpDownUp) { result = "UDUDU"; } else if (upDownPattern == UpDownPatternEnum.DownUpDownUpDown) { result = "DUDUD"; } else if (upDownPattern == UpDownPatternEnum.UpDownUpDown) { result = "UDUD"; } else if (upDownPattern == UpDownPatternEnum.DownUpDownUp) { result = "DUDU"; } else if (upDownPattern == UpDownPatternEnum.UpDownUp) { result = "UDU"; } else if (upDownPattern == UpDownPatternEnum.DownUpDown) { result = "DUD"; } else if (upDownPattern == UpDownPatternEnum.UpDown) { result = "UD"; } else if (upDownPattern == UpDownPatternEnum.DownUp) { result = "DU"; } else if (upDownPattern == UpDownPatternEnum.Up) { result = "U"; } else if (upDownPattern == UpDownPatternEnum.Down) { result = "D"; } return(result); }
public static bool IsMatchedUpDownPattern(LimitedList <double> yList, double upPrice, double downPrice, UpDownPatternEnum pattern) { string pattStr = EnumUtil.GetUpDownPatternToChars(pattern); if (pattStr.Length == 0) { return(false); } var list = yList.ToList(); if (list.Count < 3) { return(false); } string result = ""; string lastResult = ""; int idx = 0; try { if (list[0] < upPrice && list[0] > downPrice) { return(false); } for (; idx < list.Count; idx++) { if (upPrice <= list[idx] && lastResult != "U") { result += "U"; lastResult = "U"; } else if (downPrice >= list[idx] && lastResult != "D") { result += "D"; lastResult = "D"; } if (result.Length == pattStr.Length) { break; } } result = ReverseXor(result); return(result == pattStr); } catch (Exception) { return(false); } }
public static UpDownPatternEnum GetUpDownPattern(LimitedList <double> yList, List <double> upPrices, List <double> downPrices) { UpDownPatternEnum upDownPattern = UpDownPatternEnum.None; var list = yList.ToList(); if (list.Count < 3) { return(upDownPattern); } upPrices.Remove(0); upPrices.Remove(0); upPrices.Remove(0); downPrices.Remove(0); downPrices.Remove(0); downPrices.Remove(0); string result = ""; string lastResult = ""; int idx = 0; int pIdx = upPrices.Count - 1; int totalMatched = 0; try { if (list[0] < upPrices[0] && list[0] > downPrices[0]) { return(upDownPattern); } for (; pIdx >= 0; pIdx--) { double upPrice = upPrices[pIdx]; double downPrice = downPrices[pIdx]; int matched = 0; for (; idx < list.Count; idx++) { if (upPrice <= list[idx] && lastResult != "U") { result += "U"; lastResult = "U"; matched++; } else if (downPrice >= list[idx] && lastResult != "D") { result += "D"; lastResult = "D"; matched++; } if (matched == 2) { totalMatched++; break; } } if (result.Length == (upPrices.Count * 2) + 1) { break; } } if (pIdx == -1) { result = ReverseXor(result); if (result == "UDUDUDU") { upDownPattern = UpDownPatternEnum.UpDownUpDownUpDownUp; } else if (result == "DUDUDUD") { upDownPattern = UpDownPatternEnum.DownUpDownUpDownUpDown; } else if (result == "UDUDUD") { upDownPattern = UpDownPatternEnum.UpDownUpDownUpDown; } else if (result == "DUDUDU") { upDownPattern = UpDownPatternEnum.DownUpDownUpDownUp; } else if (result == "UDUDU") { upDownPattern = UpDownPatternEnum.UpDownUpDownUp; } else if (result == "DUDUD") { upDownPattern = UpDownPatternEnum.DownUpDownUpDown; } else if (result == "UDUD") { upDownPattern = UpDownPatternEnum.UpDownUpDown; } else if (result == "DUDU") { upDownPattern = UpDownPatternEnum.DownUpDownUp; } else if (result == "UDU") { upDownPattern = UpDownPatternEnum.UpDownUp; } else if (result == "DUD") { upDownPattern = UpDownPatternEnum.DownUpDown; } else if (result == "UD") { upDownPattern = UpDownPatternEnum.UpDown; } else if (result == "DU") { upDownPattern = UpDownPatternEnum.DownUp; } else if (result == "U") { upDownPattern = UpDownPatternEnum.Up; } else if (result == "D") { upDownPattern = UpDownPatternEnum.Down; } } } catch (Exception) { } return(upDownPattern); }
public static UpDownPatternEnum GetUpDownPattern(LimitedList <double> yList, double upPrice, double downPrice) { UpDownPatternEnum upDownPattern = UpDownPatternEnum.None; var list = yList.ToList(); if (list.Count < 3) { return(upDownPattern); } string result = ""; string lastResult = ""; int idx = 0; try { if (list[0] < upPrice && list[0] > downPrice) { return(upDownPattern); } for (; idx < list.Count; idx++) { if (upPrice <= list[idx] && lastResult != "U") { result += "U"; lastResult = "U"; } else if (downPrice >= list[idx] && lastResult != "D") { result += "D"; lastResult = "D"; } if (result.Length >= 7) { result = result.Substring(0, 7); break; } } result = ReverseXor(result); if (result == "UDUDUDU") { upDownPattern = UpDownPatternEnum.UpDownUpDownUpDownUp; } else if (result == "DUDUDUD") { upDownPattern = UpDownPatternEnum.DownUpDownUpDownUpDown; } else if (result == "UDUDUD") { upDownPattern = UpDownPatternEnum.UpDownUpDownUpDown; } else if (result == "DUDUDU") { upDownPattern = UpDownPatternEnum.DownUpDownUpDownUp; } else if (result == "UDUDU") { upDownPattern = UpDownPatternEnum.UpDownUpDownUp; } else if (result == "DUDUD") { upDownPattern = UpDownPatternEnum.DownUpDownUpDown; } else if (result == "UDUD") { upDownPattern = UpDownPatternEnum.UpDownUpDown; } else if (result == "DUDU") { upDownPattern = UpDownPatternEnum.DownUpDownUp; } else if (result == "UDU") { upDownPattern = UpDownPatternEnum.UpDownUp; } else if (result == "DUD") { upDownPattern = UpDownPatternEnum.DownUpDown; } else if (result == "UD") { upDownPattern = UpDownPatternEnum.UpDown; } else if (result == "DU") { upDownPattern = UpDownPatternEnum.DownUp; } else if (result == "U") { upDownPattern = UpDownPatternEnum.Up; } else if (result == "D") { upDownPattern = UpDownPatternEnum.Down; } } catch (Exception) { } return(upDownPattern); }
public static bool IsMatchedUpDownPattern(LimitedList <double> yList, List <double> upPrices, List <double> downPrices, UpDownPatternEnum pattern) { string pattStr = EnumUtil.GetUpDownPatternToChars(pattern); if (pattStr.Length == 0) { return(false); } var list = yList.ToList(); if (list.Count < 3) { return(false); } upPrices.Remove(0); upPrices.Remove(0); upPrices.Remove(0); downPrices.Remove(0); downPrices.Remove(0); downPrices.Remove(0); string result = ""; string lastResult = ""; int idx = 0; int pIdx = upPrices.Count - 1; int totalMatched = 0; try { if (list[0] < upPrices[0] && list[0] > downPrices[0]) { return(false); } for (; pIdx >= 0; pIdx--) { double upPrice = upPrices[pIdx]; double downPrice = downPrices[pIdx]; int matched = 0; for (; idx < list.Count; idx++) { if (upPrice <= list[idx] && lastResult != "U") { result += "U"; lastResult = "U"; matched++; } else if (downPrice >= list[idx] && lastResult != "D") { result += "D"; lastResult = "D"; matched++; } if (matched == 2) { totalMatched++; break; } } if (result.Length == (upPrices.Count * 2) + 1) { break; } } if (pIdx == -1) { result = ReverseXor(result); return(result == pattStr); } return(false); } catch (Exception) { return(false); } }