private void DoDayTradeMACD(List <KLine> KLineData) { if (!bDoTrading) { return; } if (g_bWaitingDeal != waitDealMode.notWaiting) { return; } KLine _KL = KLineData[KLineData.Count - 2]; double tdiff = (g_CurTime - _KL.datetime).TotalSeconds; // 發現已經有新K棒剛剛成形 if ((tdiff < (THIRTY_MINUTE + 3)) && (tdiff >= THIRTY_MINUTE)) { double _ema11 = EMA11.Value(); double _ema22 = EMA22.Value(); double _his = m_iMACD.HistRecords[m_iMACD.HistRecords.Count - 1]; bool bEmaPositive = _ema11 > _ema22; bool bMACDPositive = _his > 0; if (g_CurDeposit > 0) { // 出場,只要macd方向變就出 if (g_b1MinTradePositive != bMACDPositive) { doCleanInventory(_KL, cleanupMode.cleanupMode_KLEnd); } } else { // 進場,macd方向跟均線皆同向 if (bMACDPositive == bEmaPositive) { doBuildInventory(_KL, bMACDPositive); } } } }
public void DoTrendFollowingTrade() { // 小時線要有方向才做 if (m_KLdata_1Hour.Count < 22) { return; } if (g_curDeposite > 0) { return; } KLine _curKL30min = m_KLdata_30Min[m_KLdata_30Min.Count - 1]; // 研判趨勢多空 bool b30minPositive = m_ema11_30Min.Value() > m_ema22_30Min.Value(); bool b30minMacdPositive = m_macd_30Min.HistRecords[m_macd_30Min.HistRecords.Count - 1] > 0; bool b1hourPositive = m_ema11_1Hour.Value() > m_ema22_1Hour.Value(); bool bTrendFound = (b30minPositive == b30minMacdPositive) && (b30minMacdPositive == b1hourPositive); // 如果30分K棒發生逆趨勢線生長,進場 bool bDoTrading = false; if (bTrendFound) { double oneThrd = Math.Abs(m_ema11_30Min.Value() - m_ema22_30Min.Value()) / 3.0; if (b30minPositive) { if (_curKL30min.close < m_ema11_30Min.Value() - oneThrd) { bDoTrading = true; } } else { if (_curKL30min.close > m_ema11_30Min.Value() + oneThrd) { bDoTrading = true; } } } if (bDoTrading) { g_curDeposite++; g_lastDealPrice = _curKL30min.close; g_lastDealTime = _curKL30min.datetime; g_bTradePositive = b30minPositive; totalTradTimes++; if (g_bTradePositive) { Console.WriteLine("建倉買進 時間:" + _curKL30min.datetime.ToString()); } else { Console.WriteLine("建倉賣出 時間:" + _curKL30min.datetime.ToString()); } } }