void Piramid() // докупаем в позицию SELL при снижении рынка { List <Position> positions = _tab.PositionsOpenAll; Percent_birgi(); if (price < _tab.PositionsLast.EntryPrice - _kom - do_piram.ValueDecimal) { Console.WriteLine("Цена опустилась НА - " + (_tab.PositionsLast.EntryPrice - _kom - do_piram.ValueDecimal)); if (positions.Count != 0) { decimal vol = tovar / part_tovara.ValueInt; if (vol > min_lot.ValueDecimal) { _tab.SellAtMarketToPosition(positions[0], Okruglenie(vol)); Console.WriteLine("Допродали Битка НА - " + vol * price + " $"); Thread.Sleep(1500); } } } }
/// <summary> /// логика торговли /// </summary> /// <param name="candles"></param> private void LogicOpenPosition(List <Candle> candles) { if (_lines == null || _lines.Count == 0) { return; } // 1 выясняем каким объёмом и в какую сторону нам надо заходить decimal totalDeal = 0; decimal lastPrice = candles[candles.Count - 2].Close; decimal nowPrice = candles[candles.Count - 1].Close; for (int i = 0; i < _lines.Count; i++) { if (lastPrice < _lines[i] && nowPrice > _lines[i]) { // пробой снизу вверх totalDeal--; } if (lastPrice > _lines[i] && nowPrice < _lines[i]) { // пробой сверху вниз totalDeal++; } } if (totalDeal == 0) { return; } // 2 заходим в нужную сторону if (totalDeal > 0) { // нужно лонговать List <Position> positionsShort = _tab.PositionOpenShort; if (positionsShort != null && positionsShort.Count != 0) { if (positionsShort[0].OpenVolume <= totalDeal) { _tab.CloseAtMarket(positionsShort[0], positionsShort[0].OpenVolume); totalDeal -= positionsShort[0].OpenVolume; } else { _tab.CloseAtMarket(positionsShort[0], totalDeal); totalDeal = 0; } } if (totalDeal > 0 && totalDeal != 0) { List <Position> positionsLong = _tab.PositionOpenLong; if (positionsLong != null && positionsLong.Count != 0) { _tab.BuyAtMarketToPosition(positionsLong[0], totalDeal); } else { _tab.BuyAtMarket(totalDeal); } } } if (totalDeal < 0) { // нужно шортить totalDeal = Math.Abs(totalDeal); List <Position> positionsLong = _tab.PositionOpenLong; if (positionsLong != null && positionsLong.Count != 0) { if (positionsLong[0].OpenVolume <= totalDeal) { _tab.CloseAtMarket(positionsLong[0], positionsLong[0].OpenVolume); totalDeal -= positionsLong[0].OpenVolume; } else { _tab.CloseAtMarket(positionsLong[0], totalDeal); totalDeal = 0; } } if (totalDeal > 0) { List <Position> positionsShort = _tab.PositionOpenShort; if (positionsShort != null && positionsShort.Count != 0) { _tab.SellAtMarketToPosition(positionsShort[0], totalDeal); } else { _tab.SellAtMarket(totalDeal); } } } }
/// <summary> /// trade logic / /// логика торговли /// </summary> /// <param name="candles"></param> private void LogicOpenPosition(List <Candle> candles) { if (_lines == null || _lines.Count == 0) { return; } // 1 find out how much and in what direction we need to go // 1 выясняем каким объёмом и в какую сторону нам надо заходить decimal totalDeal = 0; decimal lastPrice = candles[candles.Count - 2].Close; decimal nowPrice = candles[candles.Count - 1].Close; for (int i = 0; i < _lines.Count; i++) { if (lastPrice < _lines[i] && nowPrice > _lines[i]) { totalDeal--; } if (lastPrice > _lines[i] && nowPrice < _lines[i]) { totalDeal++; } } if (totalDeal == 0) { return; } // 2 go in the right direction // 2 заходим в нужную сторону if (totalDeal > 0) { List <Position> positionsShort = _tab.PositionOpenShort; if (positionsShort != null && positionsShort.Count != 0) { if (positionsShort[0].OpenVolume <= totalDeal) { _tab.CloseAtMarket(positionsShort[0], positionsShort[0].OpenVolume); totalDeal -= positionsShort[0].OpenVolume; } else { _tab.CloseAtMarket(positionsShort[0], totalDeal); totalDeal = 0; } } if (totalDeal > 0 && totalDeal != 0) { List <Position> positionsLong = _tab.PositionOpenLong; if (positionsLong != null && positionsLong.Count != 0) { _tab.BuyAtMarketToPosition(positionsLong[0], totalDeal); } else { _tab.BuyAtMarket(totalDeal); } } } if (totalDeal < 0) { totalDeal = Math.Abs(totalDeal); List <Position> positionsLong = _tab.PositionOpenLong; if (positionsLong != null && positionsLong.Count != 0) { if (positionsLong[0].OpenVolume <= totalDeal) { _tab.CloseAtMarket(positionsLong[0], positionsLong[0].OpenVolume); totalDeal -= positionsLong[0].OpenVolume; } else { _tab.CloseAtMarket(positionsLong[0], totalDeal); totalDeal = 0; } } if (totalDeal > 0) { List <Position> positionsShort = _tab.PositionOpenShort; if (positionsShort != null && positionsShort.Count != 0) { _tab.SellAtMarketToPosition(positionsShort[0], totalDeal); } else { _tab.SellAtMarket(totalDeal); } } } }