Пример #1
0
 public AccountStatus StopLoss(FlipperDataModel fdm, TradeDecision td, ITradeApi tradeApi)
 {
     if (td.doTrade)
     {
         Ticker        te   = fdm.ticker.FirstOrDefault();
         AccountStatus stat = new AccountStatus
         {
             CurrentBalance    = (fdm.stats.Volume * te.last),
             LastPurchasePrice = fdm.stats.LastPurchasePrice,
             LastSalePrice     = te.last,
             StartingBalance   = fdm.stats.StartingBalance,
             StatDate          = DateTime.Now,
             Volume            = 0,
             IsSimulator       = true,
             TransactionType   = TransactionType.Sell,
             Source            = TransactionSource.Simulator,
             LastOrderDate     = DateTime.Now
         };
         TickerDAL.InsertTransaction(stat);
         return(stat);
     }
     else
     {
         return(fdm.stats);
     }
 }
Пример #2
0
        protected override TradeDecision ShouldBuyImpl(FlipperDataModel fdm)
        {
            Ticker te = fdm.ticker.FirstOrDefault();
            //Decimal threshold = 0.03M;
            decimal saftey    = ((te.high - te.low) * .8M) + te.low;
            decimal safteyLow = ((te.high - te.low) * .2M) + te.low;

            decimal avgHigh = fdm.macdIntervalSlow.CurrentHighPriceThresh();
            decimal avgLow  = fdm.macdIntervalSlow.CurrentLowPriceThresh();
            var     td      = new TradeDecision {
                doTrade = false, useMarket = false
            };


            if (fdm.macdIntervalSlow.isShortSMAGoingUp() /*&& macdIntervalFast.isMacdPositive() && fdm.macdIntervalSlow.isMacdGoingUp()*/)
            {
                td.doTrade   = true;
                td.useMarket = true;
                // td.price = fdm.macdIntervalSlow[0].AveragePrice + fdm.algoConfig.BuyThreshold;
            }



            return(td);
            //    }
            //  else return false;

            // return ((te.last < (average + algoConfig.BuyThreshold)) && stats.CurrentBalance > 0);
        }
Пример #3
0
        public void Simulate(DateTime from, DateTime to)
        {
            DateTime dateTime = from;

            TradePosition tradePosition = null;

            while (dateTime < to)
            {
                Candle candle = _candleCollection.GetCandle(dateTime);
                if (candle == null)
                {
                    dateTime = dateTime.AddSeconds(5);
                    continue;
                }

                if (tradePosition != null)
                {
                    tradePosition.Evaluate(candle.Close);

                    if (tradePosition.IsClosed)
                    {
                        _activity.Add(tradePosition);
                        tradePosition = null;
                    }
                }
                else
                {
                    TradeDecision decision = _tradeStrategy.Evaluate(candle);
                    if (decision.ShouldTrade)
                    {
                        tradePosition = new TradePosition(dateTime, candle.Close, decision);
                    }
                }

                dateTime = dateTime.AddSeconds(5);

                var currentWin  = _activity.Sum(c => c.Win);
                var currentLoss = _activity.Sum(c => c.Loss);

                var currentProfit    = currentWin + currentLoss;
                var currentwincount  = _activity.Count(c => c.Win > 0);
                var currentlossCount = _activity.Count(c => c.Loss < 0);
            }

            var Win      = _activity.Sum(c => c.Win);
            var wincount = _activity.Count(c => c.Win > 0);

            var Loss      = _activity.Sum(c => c.Loss);
            var lossCount = _activity.Count(c => c.Loss < 0);

            var profit = Win + Loss;

            double profitPercent = (double)wincount / (double)_activity.Count;

            Console.WriteLine($"\tProfit {profit}({profitPercent:#.##}) Win {Win}({wincount}) Loss {Loss}({lossCount}) trades {_activity.Count}");
        }
        protected override TradeDecision ShouldSellImpl(FlipperDataModel fdm)
        {
            var td = new TradeDecision {
                doTrade = false, useMarket = false
            };

            if (fdm.macdIntervalFast[0].CompareShortPrice > currentHighPrice)
            {
                currentHighPrice = fdm.macdIntervalFast[0].CompareShortPrice;
            }

            Ticker te = fdm.ticker.FirstOrDefault();

            if (fdm.macd.Count > 5)
            {
                //   if (te.last > stats.LastPurchasePrice)
                // {



                // if (!fdm.macdIntervalFast.isMacdGoingUp() || te.last >= (fdm.stats.LastPurchasePrice + fdm.algoConfig.FixedSellThreshold) || fdm.algoConfig.UseStrictSellThreshold)
                //     points += 4;



                if (fdm.stats.Volume > 10)
                {
                    decimal sellPrice;

                    if (fdm.algoConfig.UseStrictSellThreshold)
                    {
                        sellPrice        = fdm.stats.LastPurchasePrice + fdm.algoConfig.FixedSellThreshold;
                        td.doTrade       = true;
                        td.useMarket     = false;
                        td.price         = sellPrice;
                        currentHighPrice = 0;
                    }
                    else if (fdm.macdIntervalFast[0].ClosePrice < (fdm.algoConfig.StopLossPercentage * currentHighPrice) || (!fdm.macdIntervalFast.isShortSMAOnTop()))
                    {
                        sellPrice        = fdm.ticker[0].buy;
                        td.doTrade       = true;
                        td.useMarket     = false;
                        td.price         = sellPrice;
                        currentHighPrice = 0;
                    }
                }
            }
            return(td);
        }
        protected override TradeDecision ShouldBuyImpl(FlipperDataModel fdm)
        {
            Ticker te = fdm.ticker.FirstOrDefault();
            //Decimal threshold = 0.03M;
            decimal saftey    = ((te.high - te.low) * .8M) + te.low;
            decimal safteyLow = ((te.high - te.low) * .2M) + te.low;

            decimal avgHigh = fdm.macdIntervalSlow.CurrentHighPriceThresh();
            decimal avgLow  = fdm.macdIntervalSlow.CurrentLowPriceThresh();
            var     td      = new TradeDecision {
                doTrade = false, useMarket = false
            };

            if (fdm.macdIntervalSlow.isShortSMAGoingUp() && fdm.macdIntervalSlow.isShortSMAOnTop() && (fdm.macdIntervalSlow[1].BBHigh - fdm.macdIntervalSlow[1].BBLow > 4))
            {
                td.doTrade   = true;
                td.useMarket = true;
            }

            return(td);
        }
Пример #6
0
        public TradePosition(DateTime dateTime, decimal close, TradeDecision decision)
        {
            this.dateTime = dateTime;
            this.open     = close;
            this.decision = decision;
            IsClosed      = false;

            switch (decision.TradeDecisionKind)
            {
            case TradeDecisionKind.Long:
                open          = open - 0.00015m; //spread
                StopWinPrice  = open + (0.0001m * decision.StopWinPrice);
                StopLossPrice = open - (0.0001m * decision.StopLossPrice);

                break;

            case TradeDecisionKind.Short:
                open          = open + 0.00015m; //spread
                StopWinPrice  = open - (0.0001m * decision.StopWinPrice);
                StopLossPrice = open + (0.0001m * decision.StopLossPrice);
                break;
            }
        }
Пример #7
0
        protected override Model.TradeDecision ShouldSellImpl(Model.FlipperDataModel fdm)
        {
            var td = new TradeDecision {
                doTrade = false, useMarket = false
            };

            if (fdm.macdIntervalFast[0].CompareShortPrice > currentHighPrice)
            {
                currentHighPrice = fdm.macdIntervalFast[0].CompareShortPrice;
            }

            decimal calculatedMarketPrice = fdm.depth.ActualMarketBid(fdm.stats.Volume - fdm.algoConfig.ReservedCoin).Price;

            if (fdm.macd.Count > 5)
            {
                if (fdm.stats.Volume > 10)
                {
                    decimal sellPrice;

                    if (fdm.algoConfig.UseStrictSellThreshold)
                    {
                        sellPrice    = fdm.stats.LastPurchasePrice + fdm.algoConfig.FixedSellThreshold;
                        td.doTrade   = true;
                        td.useMarket = false;
                        td.price     = sellPrice;
                    }
                    else if (calculatedMarketPrice < (fdm.algoConfig.StopLossPercentage * currentHighPrice))
                    {
                        sellPrice    = calculatedMarketPrice;
                        td.doTrade   = true;
                        td.useMarket = true;
                        td.price     = sellPrice;
                    }
                }
            }
            return(td);
        }