public double Calc(TrendData trend) { int index = trend.lsPartData.Count; if (trend.lsPartData.Count < CountNum) { return(0); } double sum_close = 0; double sum_low = 0; double sum_high = 0; for (int i = index - CountNum; i < index; i++) { sum_close += trend.lsPartData[i].close; sum_low += trend.lsPartData[i].low; sum_high += trend.lsPartData[i].high; } ma = Utility.Round2(sum_close / CountNum); low = Utility.Round2(sum_low / CountNum); high = Utility.Round2(sum_high / CountNum); return(ma); }
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 int ProcessData(TrendData trend) { ma5.Calc(trend); ma10.Calc(trend); ma20.Calc(trend); ma30.Calc(trend); ma90.Calc(trend); //CalcBuyInfo(trend); return(EST.EST_OK); }
public void CalcDeal(Stock stock, TickData tickData, Deal deal) { TrendData trend = stock.trend_30m; StrategyData stData = trend.mStrategyData; if (stock.position.shares == 0) { //buy if (stData.ma30.ma == 0) { return; } if (tickData.dt.Hour < 13) { return; } if (trend.mPartData.close < stData.ma30.ma && tickData.price >= stData.ma30.ma) { deal.buy_shares = StartShares; deal.buy_price = tickData.price; if (!deal.canAfford()) { return; } deal.eType = Deal.EBuy; } } else { if (stock.position.shares_available != stock.position.shares) { return; } //sell if (tickData.price < stData.ma30.ma) { deal.sell_shares = stock.position.shares; deal.sell_price = tickData.price; deal.eType = Deal.ESell; } } }
public int PreProcessData(TrendData trend) { return(EST.EST_OK); }
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; } } }
public void CalcDeal_Add(Stock stock, TickData tickData, Deal deal) { TrendData trend = stock.trend_30m; 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_shares = StartShares; deal.buy_price = tickData.price; if (!deal.canAfford()) { return; } deal.eType = Deal.EBuy; } } else if (times > 0) { if (tickData.price > stock.position.getCostPrice() * SellPriceRate) { if (stock.position.shares_available != stock.position.shares) { 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) { //EarnMoney = sMoney1 - bMoney1 = sMoney2 - bMoney1 - bMoney2; //sMoney1 = sMoney2 - bMoney2; //sPrice1*bShares1 = sPrice2*(bShares1+bShares2) - bPrice2*bShares2; //sPrice1 = bPrice1*SellPriceRate; //bPrice2 = bPrice1*BuyPriceRate; //(sPrice2-bPrice2)*bShares2 = (sPrice1-sPrice2)*bShares1 //bShares2 = bShares1 * (sPrice1-sPrice2) / (sPrice2-bPrice2) //if (times == 10) { return; } deal.buy_price = tickData.price; double bPrice1 = stock.position.getCostPrice(); double bPrice2 = deal.buy_price; double sPrice1 = sellPrice1; double sPrice2 = bPrice2 * SellPriceRate; double bShares1 = stock.position.shares; double denominator = sPrice1 - sPrice2; double numerator = sPrice2 - bPrice2; double x = denominator / numerator * bShares1; x = Math.Ceiling(x / 100) * 100; deal.buy_shares = Convert.ToInt32(x); if (deal.buy_shares == 0) { return; } if (!deal.canAfford()) { return; } deal.eType = Deal.EBuy; } } }
public void CalcDeal_Multi(Stock stock, TickData tickData, Deal deal) { TrendData trend = stock.trend_30m; 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_shares = StartShares; deal.buy_price = tickData.price; if (!deal.canAfford()) { return; } deal.eType = Deal.EBuy; } } else if (times > 0) { if (tickData.price > stock.position.getCostPrice() * SellPriceRate) { if (stock.position.shares_available != stock.position.shares) { 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) { //EarnRate = 1.01; //PriceRate = 0.02; //SellPriceRate = 1 + PriceRate; //bPrice2 = tickData.price; //SellPrice = bPrice2 * SellPriceRate; //CostMoney * EarnRate = SellMoney; //(bPrice1*bShares1 + bPrice2*bShares2)*EarnRate = SellPrice*TotalShares; //Mid = SellPrice / EarnRate; //bPrice1*bShares1 + bPrice2*bShares2 = Mid*bShares1 + Mid*bShares2; //bShares2*(bPrice2 - Mid) = bShares1*(Mid - bPrice1); //bShares2 = bShares1*(Mid - bPrice1) / (bPrice2 - Mid); if (times == TopTimes) { return; } deal.buy_price = tickData.price; double bPrice1 = stock.position.getCostPrice(); double bPrice2 = deal.buy_price; double sellPrice = bPrice2 * SellPriceRate; double mid = sellPrice / (1 + EarnRate); double denominator = mid - stock.position.getCostPrice(); double numerator = deal.buy_price - mid; double x = denominator / numerator * stock.position.shares; x = Math.Ceiling(x / 100) * 100; deal.buy_shares = Convert.ToInt32(x); if (!deal.canAfford()) { return; } deal.eType = Deal.EBuy; } } }
public bool AddTrendData(TrendData trendData) { return(true); }