public static List <Cortege2 <int, float> > GetPivots(IList <CandleData> candles, float thresholdPercent, int endIndex, ZigZagSource srcType) { var pivots = new List <Cortege2 <int, float> >(); if (candles.Count == 0) { return(pivots); } var lastPivot = new Cortege2 <int, float> { a = 0, b = candles[0].open }; int lastSign = 0; // занести вершины int i = 1; for (; i <= endIndex; i++) { var candle = candles[i]; var high = srcType == ZigZagSource.HighLow ? candle.high : System.Math.Max(candle.open, candle.close); var low = srcType == ZigZagSource.HighLow ? candle.low : System.Math.Min(candle.open, candle.close); var deltaPlus = high - lastPivot.b; var deltaMinus = lastPivot.b - low; deltaPlus = deltaPlus > 0 ? 100 * deltaPlus / lastPivot.b : 0; deltaMinus = deltaMinus > 0 ? 100 * deltaMinus / lastPivot.b : 0; if (deltaPlus > thresholdPercent && ((deltaPlus > deltaMinus && lastSign == 0) || lastSign < 0)) { pivots.Add(lastPivot); lastPivot = new Cortege2 <int, float> { a = i, b = high }; lastSign = 1; continue; } if (deltaMinus > thresholdPercent && ((deltaPlus <= deltaMinus && lastSign == 0) || lastSign > 0)) { pivots.Add(lastPivot); lastPivot = new Cortege2 <int, float> { a = i, b = low }; lastSign = -1; continue; } if (lastSign > 0 && high > lastPivot.b) { lastPivot.b = high; lastPivot.a = i; continue; } if (lastSign < 0 && low < lastPivot.b) { lastPivot.b = low; lastPivot.a = i; continue; } } // последняя вершина if (lastSign != 0) { //var candleLast = candles[endIndex]; //var lastHigh = srcType == ZigZagSource.HighLow ? candleLast.high : // System.Math.Max(candleLast.open, candleLast.close); //var lastLow = srcType == ZigZagSource.HighLow ? candleLast.low : // System.Math.Min(candleLast.open, candleLast.close); //pivots.Add(new Cortege2<int, float> //{ // a = endIndex, // b = lastSign > 0 ? lastHigh : lastLow //}); pivots.Add(lastPivot); } return(pivots); }
private bool FiboLevelReached(int dealSide, float zzPercent, float checkedFiboLevel, ZigZagSource zzSource, int maxPointsToFibo, int maxCandlesPassed) { // получить точки ЗЗ var countCandles = candles.Count; var candleList = candles.ToList(); var pivots = ZigZag.GetPivots(candleList, zzPercent, zzSource); if (pivots.Count < 2) { return false; } // исключить последнюю точку ЗЗ? var deltaLast = 100 * Math.Abs(pivots[pivots.Count - 1].b - pivots[pivots.Count - 2].b) / pivots[pivots.Count - 2].b; var start = pivots.Count - 1; if (deltaLast < zzPercent) // исключаем последнюю точку start--; // поиск подходящего расширения, чтобы разрешить вход // ищем только на одну точку назад! for (var i = start; i > 0 && i >= start - 1; i--) { var b = pivots[i]; if (b.a + maxCandlesPassed < countCandles) break; var a = pivots[i - 1]; // только "поддержки" для покупок и "сопротивления" для продаж var isSupport = a.b < b.b; if ((!isSupport && dealSide > 0) || (isSupport && dealSide < 0)) continue; var level = a.b + (a.b - b.b) * (checkedFiboLevel - 1); // проверить, достигался ли уровень в пределах допустимого расстояния // любой из свечек var reached = false; for (var j = b.a + 1; j < countCandles; j++) { var delta = isSupport ? level - candleList[j].low : candleList[j].high - level; if (delta > 0) reached = true; else if (maxPointsToFibo > 0) // подсчитать сколько не дотянули в пп { var points = DalSpot.Instance.GetPointsValue(ticker, -delta); if (points < maxPointsToFibo) reached = true; } if (reached) break; } if (reached) return true; } return false; }
public static List <Cortege2 <int, float> > GetPivots(IList <CandleData> candles, float thresholdPercent, ZigZagSource srcType) { return(GetPivots(candles, thresholdPercent, candles.Count - 1, srcType)); }
public static List<Cortege2<int, float>> GetPivots(IList<CandleData> candles, float thresholdPercent, int endIndex, ZigZagSource srcType) { var pivots = new List<Cortege2<int, float>>(); if (candles.Count == 0) return pivots; var lastPivot = new Cortege2<int, float> { a = 0, b = candles[0].open }; int lastSign = 0; // занести вершины int i = 1; for (; i <= endIndex; i++) { var candle = candles[i]; var high = srcType == ZigZagSource.HighLow ? candle.high : System.Math.Max(candle.open, candle.close); var low = srcType == ZigZagSource.HighLow ? candle.low : System.Math.Min(candle.open, candle.close); var deltaPlus = high - lastPivot.b; var deltaMinus = lastPivot.b - low; deltaPlus = deltaPlus > 0 ? 100 * deltaPlus / lastPivot.b : 0; deltaMinus = deltaMinus > 0 ? 100 * deltaMinus / lastPivot.b : 0; if (deltaPlus > thresholdPercent && ((deltaPlus > deltaMinus && lastSign == 0) || lastSign < 0)) { pivots.Add(lastPivot); lastPivot = new Cortege2<int, float> { a = i, b = high }; lastSign = 1; continue; } if (deltaMinus > thresholdPercent && ((deltaPlus <= deltaMinus && lastSign == 0) || lastSign > 0)) { pivots.Add(lastPivot); lastPivot = new Cortege2<int, float> { a = i, b = low }; lastSign = -1; continue; } if (lastSign > 0 && high > lastPivot.b) { lastPivot.b = high; lastPivot.a = i; continue; } if (lastSign < 0 && low < lastPivot.b) { lastPivot.b = low; lastPivot.a = i; continue; } } // последняя вершина if (lastSign != 0) { //var candleLast = candles[endIndex]; //var lastHigh = srcType == ZigZagSource.HighLow ? candleLast.high : // System.Math.Max(candleLast.open, candleLast.close); //var lastLow = srcType == ZigZagSource.HighLow ? candleLast.low : // System.Math.Min(candleLast.open, candleLast.close); //pivots.Add(new Cortege2<int, float> //{ // a = endIndex, // b = lastSign > 0 ? lastHigh : lastLow //}); pivots.Add(lastPivot); } return pivots; }
public static List<Cortege2<int, float>> GetPivots(IList<CandleData> candles, float thresholdPercent, ZigZagSource srcType) { return GetPivots(candles, thresholdPercent, candles.Count - 1, srcType); }
public static List <ZigZagPivot> GetPivots(IList <CandleData> candles, float thresholdPercent, float correctionPercent, int endIndex, ZigZagSource srcType) { var pivots = new List <ZigZagPivot>(); if (candles.Count == 0) { return(pivots); } var lastPivot = new ZigZagPivot(0, candles[0].open); int lastSign = 0; // занести вершины int i = 1; for (; i <= endIndex; i++) { var candle = candles[i]; var high = srcType == ZigZagSource.HighLow ? candle.high : Math.Max(candle.open, candle.close); var low = srcType == ZigZagSource.HighLow ? candle.low : Math.Min(candle.open, candle.close); var deltaPlus = high - lastPivot.price; var deltaMinus = lastPivot.price - low; deltaPlus = deltaPlus > 0 ? 100 * deltaPlus / lastPivot.price : 0; deltaMinus = deltaMinus > 0 ? 100 * deltaMinus / lastPivot.price : 0; if (deltaPlus > correctionPercent && ((deltaPlus > deltaMinus && lastSign == 0) || lastSign < 0)) { pivots.Add(lastPivot); lastPivot = new ZigZagPivot(i, high); lastSign = 1; continue; } if (deltaMinus > correctionPercent && ((deltaPlus <= deltaMinus && lastSign == 0) || lastSign > 0)) { pivots.Add(lastPivot); lastPivot = new ZigZagPivot(i, low); lastSign = -1; continue; } if (lastSign > 0 && high > lastPivot.price) { lastPivot.price = high; lastPivot.index = i; continue; } if (lastSign < 0 && low < lastPivot.price) { lastPivot.price = low; lastPivot.index = i; continue; } } // последняя вершина if (lastSign != 0) { pivots.Add(lastPivot); } DetermineCorrectionOrTrend(pivots, thresholdPercent, correctionPercent); return(pivots); }
public static List <ZigZagPivot> GetPivots(IList <CandleData> candles, float thresholdPercent, int endIndex, ZigZagSource srcType) { return(GetPivots(candles, thresholdPercent, thresholdPercent, endIndex, srcType)); }