public void CalcDeal_MACD(Stock stock, TickData tickData, Deal deal) { TrendData trend = stock.trend_day; StrategyData strategyData = trend.mStrategyData; if (times == 0) { if (strategyData.ma10.ma == 0) { return; } if (trend.mPartData.close < strategyData.ma10.ma && tickData.price > strategyData.ma10.ma) { deal.buy_price = tickData.price; deal.buy_shares = deal.getBuyShares(StartMoney); if (!deal.canAfford()) { return; } deal.eType = Deal.EBuy; } } else if (times > 0) { double sPrice = stock.position.getCostPrice() * SellPriceRate; double bPrice = stock.position.getCostPrice() * BuyPriceRate; if (tickData.price > stock.position.getCostPrice() * SellPriceRate) { if (stock.position.shares_available != stock.position.shares) { return; } if (tickData.price > strategyData.ma10.ma) { return; } deal.sell_shares = stock.position.shares; deal.sell_price = tickData.price; //if (deal.sell_shares > stock.position.shares_available) return; deal.eType = Deal.ESell; } else if (tickData.price < stock.position.getCostPrice() * BuyPriceRate) { //if (times == 10) { return; } deal.buy_price = tickData.price; deal.buy_shares = deal.getBuyShares(StartMoney); if (deal.buy_shares == 0) { return; } if (!deal.canAfford()) { return; } deal.eType = Deal.EBuy; } } }
public void CalcDeal_HighFrequency(Stock stock, TickData tickData, Deal deal) { TrendData trend = stock.trend_day; StrategyData strategyData = trend.mStrategyData; //sell if (stock.position.shares_available > 0) { if (openPrice == 0) { openPrice = tickData.price; } if (tickData.price > highPrice) { highPrice = tickData.price; } double costPrice = stock.position.getCostPrice(); double diff = highPrice - costPrice; if (diff >= 0.03) { double sPrice = openPrice + Math.Floor(diff / 1.6 * 100) / 100; if (tickData.price < sPrice) { deal.sell_shares = stock.position.shares_available; deal.sell_price = tickData.price; deal.eType = Deal.ESell; } } //final wall /* * DateTime endDt = new DateTime(tickData.dt.Year, tickData.dt.Month, tickData.dt.Day, 14, 50, 0); * if (tickData.dt.Ticks > endDt.Ticks) * { * deal.sell_shares = stock.position.shares_available; * deal.sell_price = tickData.price; * deal.eType = Deal.ESell; * } */ } //buy if (stock.position.shares == 0) { if (tickData.price <= strategyData.ma5.low) { deal.buy_price = tickData.price; deal.buy_shares = deal.getBuyShares(StartMoney * 10); if (deal.buy_shares == 0) { return; } if (!deal.canAfford()) { return; } deal.eType = Deal.EBuy; } } }