public static DecisionData contrarianSashine(AccountGA ac, int i, double exit_time_sec, int kairi_term, double entry_kairi, double rikaku_percentage) { DecisionData dd = new DecisionData(); double kairi = (TickData.price[i] - TickData.price[i - kairi_term]) / TickData.price[i - kairi_term]; string entry_sign = ""; if (kairi >= entry_kairi) { entry_sign = "Short"; } else if (kairi <= -entry_kairi) { entry_sign = "Long"; } if (entry_sign != "") { if (ac.holding_position == "None" && ac.price_tracing_order_flg == false) { dd = makeDDForEntryPriceTracingOrder(i, entry_sign, true, 0.05); } else if (ac.holding_position != "None" && entry_sign != ac.holding_position && ac.price_tracing_order_flg && ac.cancel_all_orders == false) { dd = makeDDForEntryPriceTracingOrder(i, "Cancel_PriceTracingOrder", false, 0); } else if (ac.holding_position != "None" && entry_sign != ac.holding_position && ac.price_tracing_order_flg == false && ac.cancel_all_orders == false) { dd = makeDDForEntryPriceTracingOrder(i, entry_sign, true, ac.ave_holding_lot + 0.05); } else if (entry_sign == ac.holding_position && ac.unexe_position.Count == 0) { dd.position = (entry_sign == "Long") ? "Short" : "Long"; dd.cancel_index = -1; dd.price_tracing_order = false; dd.price = (ac.holding_position == "Long") ? Math.Round(ac.ave_holding_price * (1 + rikaku_percentage)) : Math.Round(ac.ave_holding_price * (1 - rikaku_percentage)); dd.lot = ac.ave_holding_lot; } else if (entry_sign == ac.holding_position && ac.unexe_position.Count == 0 && (TickData.time[i] - ac.last_entry_time).TotalSeconds >= exit_time_sec) { dd = makeDDForEntryPriceTracingOrder(i, (ac.holding_position == "Long") ? "Short" : "Long", true, ac.ave_holding_lot); } } else if (ac.holding_position != "None") { // dd.position = "Exit_All"; } return(dd); }
public AccountGA startContrarianSashine(int from, int to, double exit_time_sec, int kairi_term, double entry_kairi, double rikaku) { AccountGA ac = new AccountGA(); for (int i = from; i < to; i++) { var tdd = StrategyGA.contrarianSashine(ac, i, exit_time_sec, kairi_term, entry_kairi, rikaku); if (tdd.position == "Exit_All") { ac.exitAllOrder(i); } else if (tdd.price_tracing_order) { if (tdd.position == "Long" || tdd.position == "Short") { ac.entryPriceTracingOrder(i, tdd.position, tdd.lot); } } else { if (tdd.position == "Cancel" && tdd.cancel_index >= 0) { ac.cancelOrder(i, tdd.cancel_index); } else if (tdd.position == "Cancel_All") { ac.cancelAllOrders(i); } else if (tdd.position == "Cancel_PriceTracingOrder") { ac.cancelPriceTracingOrder(i); } else if (tdd.position == "Long" || tdd.position == "Short") { ac.entryOrder(i, tdd.position, tdd.price, tdd.lot); } } ac.moveToNext(i); } ac.lastDayOperation(to); return(ac); }
public void addAcList(int i, AccountGA ac) { lock (lockobj) ac_list.Add(i, ac); }