// public static TradeDecisionData makeDecision(Account ac, int i, double kairi, double nanpin, double pt, double lc) { TradeDecisionData tdd = new TradeDecisionData(); return(tdd); }
//lc > nanpin //nanpin: entry when pirce was changed from ave_price more than nanpin, entry lot = num_btc * 2 public static TradeDecisionData makeDecision(Account ac, int i, double kairi_kijun, double pt, double lc, double nanpin) { TradeDecisionData tdd = new TradeDecisionData(); tdd.decision = "None"; if (lc <= nanpin) { System.Windows.Forms.MessageBox.Show("Invalid LC & Nanpin in StrategyNanpin, lc has to be larger than nanpin"); } else { if (ac.getIjiritsu >= 1.0) { if (ac.getPosition == "Long") { if (ac.getAvePrice * (1 + pt) <= PriceData.close[i]) //check for pt { tdd.decision = "PT Long"; tdd.price = 0; tdd.lot = ac.getNumBTC; } else if (ac.getAvePrice * (1 - lc) >= PriceData.close[i]) //check for lc { tdd.decision = "LC Long"; tdd.price = 0; tdd.lot = ac.getNumBTC; } else if ((ac.getAvePrice * (1 - nanpin) >= PriceData.close[i]) && (ac.getMoney > ac.calcEstimatedRequiredShokokin(PriceData.close[i], ac.getNumBTC * 2.0))) //check for nanpin { tdd.decision = "Nanpin Long"; tdd.price = 0; tdd.lot = ac.getNumBTC * 2.0; } else { tdd.decision = "Hold"; tdd.price = 0; tdd.lot = 0; } } else if (ac.getPosition == "Short") { if (ac.getAvePrice * (1 - pt) >= PriceData.close[i]) //check for pt { tdd.decision = "PT Short"; tdd.price = 0; tdd.lot = ac.getNumBTC; } else if (ac.getAvePrice * (1 + lc) <= PriceData.close[i]) //check for lc { tdd.decision = "LC Short"; tdd.price = 0; tdd.lot = ac.getNumBTC; } else if ((ac.getAvePrice * (1 + nanpin) <= PriceData.close[i]) && (ac.getMoney > ac.calcEstimatedRequiredShokokin(PriceData.close[i], ac.getNumBTC * 2.0))) //check for nanpin { tdd.decision = "Nanpin Short"; tdd.price = 0; tdd.lot = ac.getNumBTC * 2.0; } else { tdd.decision = "Hold"; tdd.price = 0; tdd.lot = 0; } } else if (ac.getPosition == "None") { double kairi = IndexData.getMA1000[i] / PriceData.close[i]; if (kairi >= kairi_kijun) { double lot = ac.calcEstimatedMaxLot(i, PriceData.close[i]); tdd.decision = "Entry Long"; tdd.price = 0; tdd.lot = lot / 7.1; } else if (kairi <= kairi_kijun * -1) { double lot = ac.calcEstimatedMaxLot(i, PriceData.close[i]); tdd.decision = "Entry Short"; tdd.price = 0; tdd.lot = lot / 7.1; } else { tdd.decision = "Hold"; } } } } return(tdd); }
public SimLog simStrategyNanpin(int from, int to, double pt, double lc, double nanpin, double kairi_kijun, bool writelog) { SimLog sl = new SimLog(); if (from > 1000 && to <= PriceData.date.Count - 1 && lc > nanpin) { Account ac = new Account(); TradeDecisionData tdd = new TradeDecisionData(); string d = "Hold"; double lot = 0; for (int i = from; i < to; i++) { tdd.initialize(); if (d == "Entry Long") { string message = Trade.entryLong(ac, i, tdd.lot); sl.trade_log.Add(i, message); lot = 0; d = "Hold"; } else if (d == "Entry Short") { string message = Trade.entryShort(ac, i, tdd.lot); sl.trade_log.Add(i, message); lot = 0; d = "Hold"; } else if (d == "Exit Long") { string message = Trade.exitLong(ac, i, tdd.lot); sl.trade_log.Add(i, message); d = "Hold"; } else if (d == "Exit Short") { string message = Trade.exitShort(ac, i, tdd.lot); sl.trade_log.Add(i, message); d = "Hold"; } tdd = StrategyNanpin.makeDecision(ac, i, kairi_kijun, pt, lc, nanpin); if (tdd.decision == "Entry Long" || tdd.decision == "Nanpin Long") { sl.decision_log.Add(i, tdd.decision); d = "Entry Long"; lot = tdd.lot; } else if (tdd.decision == "Entry Short" || tdd.decision == "Nanpin Short") { sl.decision_log.Add(i, tdd.decision); d = "Entry Short"; lot = tdd.lot; } else if (tdd.decision == "PT Long" || tdd.decision == "LC Long") { sl.decision_log.Add(i, tdd.decision); d = "Exit Long"; lot = 0; } else if (tdd.decision == "PT Short" || tdd.decision == "LC Short") { sl.decision_log.Add(i, tdd.decision); d = "Exit Short"; lot = 0; } else if (tdd.decision == "Hold") { sl.decision_log.Add(i, tdd.decision); d = "Hold"; lot = 0; } ac.moveToNext(i); sl.takeDailyLog(ac, i); } } else { System.Windows.Forms.MessageBox.Show("Invalid input values in simStrategyNanin!"); } return(sl); }