/// <summary> /// Check if buying coins or not /// </summary> /// <param name="candleStick">current Candlestick object</param> /// <param name="previousStick">previous Candlestick object</param> /// <returns>Boolean if trade made</returns> private bool BuyCryptoCheck(Candlstick candleStick, Candlstick previousStick) { var tradeType = TankingCheck(candleStick, TradeType.BUY); if (tradeType != TradeType.NONE || _tradeNumber == 0) { //if (_tradeNumber == 0) // tradeType = TradeType.BUY; var buyStatus = _trader.BuyCrypto(_moonTankPrice, tradeType); _lastBuy = _moonTankPrice; if (buyStatus) { _lastBuy = _moonTankPrice; _tradeType = TradeType.SELL; _lastTrade = tradeType; _tradeNumber++; } return(buyStatus); } else { return(false); } }
/// <summary> /// Run Trading Bot /// </summary> /// <param name="interval">Candlestick Interval</param> /// <param name="cycles">Int of cycles to run (default -1, run infinitely)</param> /// <param name="tradingStatus">Bool of trading status (default null, use setting)</param> /// <returns>Boolean when complete</returns> public bool RunBot(Interval interval, int cycles = -1, bool?tradingStatus = null) { _trader.SetupRepository(); _tradeType = TradeType.BUY; var currentStick = new Candlstick(); var previousStick = new Candlstick(); bool currentlyTrading = tradingStatus != null ? (bool)tradingStatus : _currentlyTrading; _trader.SetBalances(); _tradeType = _trader.GetInitialTradeType(); while (currentlyTrading) { Task.WaitAll(Task.Delay(_botSettings.priceCheck)); if (cycles % 20 == 0) { // Every 10 cycles, reset balances and check bot settings file _tradeType = _trader.GetTradingType(); _trader.UpdateBotSettings(_lastBuy, _lastSell); SetBotSettings(_trader.GetBotSettings()); currentlyTrading = _tradeType == TradeType.NONE ? false : _botSettings.runBot; } var candleStickArray = _trader.GetCandlesticks(_symbol, interval, 5); int i = candleStickArray.Length - 1; currentStick = candleStickArray[i]; if (previousStick.close == 0 && i > 2) { previousStick = candleStickArray[i - 1]; } //StoppedOutCheck(currentStick.close); if (previousStick.time != currentStick.time) { if (_tradeType == TradeType.BUY) { BuyCryptoCheck(currentStick, previousStick); } else if (_tradeType == TradeType.SELL) { SellCryptoCheck(currentStick, previousStick); } cycles++; } } return(true); }
/// <summary> /// Check if sellying coins or not /// </summary> /// <param name="candleStick">current Candlestick object</param> /// <param name="previousStick">previous Candlestick object</param> /// <returns>Boolean if trade made</returns> private bool SellCryptoCheck(Candlstick candleStick, Candlstick previousStick) { var tradeType = MooningCheck(candleStick, TradeType.SELL); if (tradeType != TradeType.NONE) { var sellStatus = _trader.SellCrypto(_moonTankPrice, tradeType); _lastSell = _moonTankPrice; if (sellStatus) { _lastSell = _moonTankPrice; _tradeType = TradeType.BUY; _lastTrade = tradeType; _tradeNumber++; } return(sellStatus); } else { return(false); } }
/// <summary> /// Check if tanking /// </summary> /// <param name="startingStick">Starting BotStick</param> /// <param name="tradeType">Trade Type</param> /// <param name="prevStick">Previous BotStick (default null)</param> /// <param name="startingPrice">decimal of starting price</param> /// <param name="iteration">Int of iteration</param> /// <returns>TradeType of result</returns> public TradeType TankingCheck(Candlstick startingStick , TradeType tradeType , Candlstick prevStick = null , decimal startingPrice = 0.00000000M , int iteration = 0) { if (_botSettings.mooningTankingTime == 0) { //return tradeType; } var sticks = GetNextCandlestick(); var currentStick = sticks[0]; var lastStick = sticks[1]; if (prevStick == null) { prevStick = lastStick; } if (iteration == 0) { startingPrice = lastStick.close; } SetLocals(currentStick.close, iteration); _lastVolume = (decimal)lastStick.volume; _moonTankPrice = currentStick.close; var volumePercentChange = _helper.GetPercent(_lastVolume, (decimal)currentStick.volume) * 100; var buyPercentReached = BuyPercentReached(currentStick.close); if (currentStick.open > currentStick.close && lastStick.close > currentStick.close && prevStick.close > currentStick.close) //&& buyPercentReached && iteration < 10) { // If current price is less than the previous check // (price is dropping) // and buy percent reached // keep checking if dropping more iteration++; TankingCheck(startingStick, tradeType, lastStick, startingPrice, iteration); } else if (buyPercentReached) { // Else if not dropping in price from previous check // or buy percent not reached // return buy percent reached _trader.LogTradeSignal(SignalType.Percent, TradeType.BUY, currentStick.close, (decimal)currentStick.volume); return(TradeType.BUY); } else if (_botSettings.mooningTankingTime > 0) { if (_lastTrade == TradeType.VOLUMESELL && currentStick.open > currentStick.close && lastStick.close > currentStick.close && _lastSell > currentStick.close && _localLow < currentStick.close) { // If last trade was volume sell and current stick is greater than last, // but less than last sell, probably reached ATL: BUY volume sell _trader.LogTradeSignal(SignalType.Volume, TradeType.VOLUMESELLBUYOFF, currentStick.close, (decimal)currentStick.volume); return(TradeType.VOLUMESELLBUYOFF); } else if (volumePercentChange > _botSettings.mooningTankingPercent && currentStick.open < currentStick.close && lastStick.close < currentStick.close && _lastSell > currentStick.close) { // If volume increased more than N% and Latest close is greater than previous close // Probably a mini-moon: BUY _trader.LogTradeSignal(SignalType.Volume, TradeType.VOLUMEBUY, currentStick.close, (decimal)currentStick.volume); return(TradeType.VOLUMEBUY); } else { return(TradeType.NONE); } } else { return(TradeType.NONE); } return(tradeType); }
/// <summary> /// Check if mooning /// </summary> /// <param name="startingStick">Starting BotStick</param> /// <param name="tradeType">Trade Type</param> /// <param name="prevStick">Previous BotStick (default null)</param> /// <param name="startingPrice">decimal of starting price</param> /// <param name="iteration">Int of iteration</param> /// <returns>TradeType of result</returns> public TradeType MooningCheck(Candlstick startingStick , TradeType tradeType , Candlstick prevStick = null , decimal startingPrice = 0.00000000M , int iteration = 0) { if (_botSettings.mooningTankingTime == 0) { //return tradeType; } var sticks = GetNextCandlestick(); var currentStick = sticks[0]; var lastStick = sticks[1]; if (prevStick == null) { prevStick = lastStick; } if (iteration == 0) { startingPrice = lastStick.close; } _lastVolume = (decimal)lastStick.volume; SetLocals(currentStick.close, iteration); _moonTankPrice = currentStick.close; var volumePercentChange = _helper.GetPercent(_lastVolume, (decimal)currentStick.volume) * 100; var sellPercentReached = SellPercentReached(currentStick.close); if (currentStick.open < currentStick.close && startingStick.close < currentStick.close && prevStick.close < currentStick.close) //&& sellPercentReached && iteration < 10) { // TODO: set the latest price as the starting price to see if it is increasing during current candle // TODO: do same on tanking // If current price is greater than the previous check // (price is increasing) // and sell percent reached // keep checking if increasing more iteration++; MooningCheck(startingStick, tradeType, lastStick, startingPrice, iteration); } else if (sellPercentReached) { // Else if not increasing in price from previous check // or sell percent not reached // return sell percent reached _trader.LogTradeSignal(SignalType.Percent, TradeType.SELL, currentStick.close, (decimal)currentStick.volume); return(TradeType.SELL); } else if (_botSettings.mooningTankingTime > 0) { if (_lastTrade == TradeType.VOLUMEBUY && currentStick.open < currentStick.close && lastStick.close < currentStick.close && _lastBuy < currentStick.close && _localHigh > currentStick.close) { // If last trade was volume buy and current stick is less than last, // but greater than last buy, probably reached ATH: SELL volume buy _trader.LogTradeSignal(SignalType.Volume, TradeType.VOLUMEBUYSELLOFF, currentStick.close, (decimal)currentStick.volume); return(TradeType.VOLUMEBUYSELLOFF); } else if (volumePercentChange > _botSettings.mooningTankingPercent && currentStick.open > currentStick.close && lastStick.close > currentStick.close && _lastBuy < currentStick.close) { // If volume increased more than N% and Latest close is less than previous close // Probably a sell off: Sell _trader.LogTradeSignal(SignalType.Volume, TradeType.VOLUMESELL, currentStick.close, (decimal)currentStick.volume); return(TradeType.VOLUMESELL); } else { return(TradeType.NONE); } } else { return(TradeType.NONE); } return(tradeType); }
/// <summary> /// Check if mooning or tanking /// </summary> /// <param name="candleStick">Current trading stick</param> /// <param name="previousStick">Previous trading stick</param> /// <param name="tradeType">Trade Type</param> /// <param name="startingPrice">decimal of starting price</param> /// <param name="iteration">Int of iteration</param> /// <returns>TradeType of result</returns> public TradeType MooningAndTankingCheck(Candlstick candleStick, Candlstick previousStick, TradeType tradeType, decimal startingPrice = 0.00000000M, int iteration = 0) { if (_botSettings.mooningTankingTime == 0) { //return tradeType; } if (iteration == 0) { startingPrice = candleStick.close; } _lastVolume = (decimal)candleStick.volume; var sticks = GetNextCandlestick(); var latestStick = sticks[0]; candleStick = sticks[1]; previousStick = sticks[1]; if (latestStick.time == candleStick.time) { // If latest stick has the same close time as current stick, make previous stick the current stick candleStick = previousStick; } _moonTankPrice = latestStick.close; var volumePercentChange = _helper.GetPercent(_lastVolume, (decimal)latestStick.volume) * 100; if (_tradeType == TradeType.BUY) { var buyPercentReached = BuyPercentReached(latestStick.close); if (candleStick.close > latestStick.close && buyPercentReached && iteration < 10) { // If current price is less than the previous check // (price is dropping) // and buy percent reached // keep checking if dropping more iteration++; MooningAndTankingCheck(latestStick, candleStick, tradeType, startingPrice, iteration); } else { if (_lastTrade == TradeType.VOLUMESELL && candleStick.close < latestStick.close && _lastSell > latestStick.close && _botSettings.mooningTankingTime > 0) { // If last trade was volume sell and current stick is greater than last, // but less than last sell, probably reached ATL: BUY volume sell _trader.LogTradeSignal(SignalType.Volume, TradeType.VOLUMESELLBUYOFF, latestStick.close, (decimal)latestStick.volume); return(TradeType.VOLUMESELLBUYOFF); } else if (volumePercentChange > _botSettings.mooningTankingPercent && candleStick.close < latestStick.close && _botSettings.mooningTankingTime > 0) { // If volume increased more than N% and Latest close is greater than previous close // Probably a mini-moon: BUY _trader.LogTradeSignal(SignalType.Volume, TradeType.VOLUMEBUY, latestStick.close, (decimal)latestStick.volume); return(TradeType.VOLUMEBUY); } else { // Else if not dropping in price from previous check // or buy percent not reached // return buy percent reached if (buyPercentReached) { _trader.LogTradeSignal(SignalType.Percent, TradeType.BUY, latestStick.close, (decimal)latestStick.volume); return(TradeType.BUY); } else { return(TradeType.NONE); } } } } else { var sellPercentReached = SellPercentReached(latestStick.close); if (candleStick.close < latestStick.close && sellPercentReached && iteration < 10) { // If current price is greater than the previous check // (price is increasing) // and sell percent reached // keep checking if increasing more iteration++; MooningAndTankingCheck(latestStick, candleStick, tradeType, startingPrice, iteration); } else if (sellPercentReached) { // Else if not increasing in price from previous check // or sell percent not reached // return sell percent reached _trader.LogTradeSignal(SignalType.Percent, TradeType.SELL, latestStick.close, (decimal)latestStick.volume); return(TradeType.SELL); } else { if (_lastTrade == TradeType.VOLUMEBUY && candleStick.close > latestStick.close && _lastBuy < latestStick.close && _botSettings.mooningTankingTime > 0) { // If last trade was volume buy and current stick is less than last, // but greater than last buy, probably reached ATH: SELL volume buy _trader.LogTradeSignal(SignalType.Volume, TradeType.VOLUMEBUYSELLOFF, latestStick.close, (decimal)latestStick.volume); return(TradeType.VOLUMEBUYSELLOFF); } else if (volumePercentChange > _botSettings.mooningTankingPercent && candleStick.close > latestStick.close && _botSettings.mooningTankingTime > 0) { // If volume increased more than N% and Latest close is less than previous close // Probably a sell off: Sell _trader.LogTradeSignal(SignalType.Volume, TradeType.VOLUMESELL, latestStick.close, (decimal)latestStick.volume); return(TradeType.VOLUMESELL); } else { return(TradeType.NONE); } } } return(tradeType); }