public OrderParameter ReadOrderParameters(string strTitle, int nCount, int nNumber)
        {
            if (!m_bOpened)
            {
                return(null);
            }
            try
            {
                string strTitleCellName = "A";
                int    nIndex           = 1;
                bool   bFound           = false;
                while (true)
                {
                    string CellTitle = sheet.Cell(strTitleCellName + nIndex.ToString()).Value.ToString();
                    if (CellTitle == strTitle)
                    {
                        bFound = true;
                        break;
                    }
                    if (CellTitle == null || CellTitle == "")
                    {
                        break;
                    }
                    nIndex++;
                }
                if (bFound)
                {
                    if (sheet.Cell(nIndex - 1, 1).ToInteger() < nCount)
                    {
                        return(null);
                    }
                    string strPrice = sheet.Cell(nIndex - 1, 3 + 6 * ((nCount - 1) * 3 + nNumber)).Value.ToString();
                    if (strPrice != "Low" && strPrice != "High" && strPrice != "Open" && strPrice != "Close")
                    {
                        return(null);
                    }
                    double LotSize    = sheet.Cell(nIndex - 1, 4 + 6 * ((nCount - 1) * 3 + nNumber)).ToDouble();
                    double StopLoss   = sheet.Cell(nIndex - 1, 5 + 6 * ((nCount - 1) * 3 + nNumber)).ToDouble();
                    double TakeProfit = sheet.Cell(nIndex - 1, 6 + 6 * ((nCount - 1) * 3 + nNumber)).ToDouble();
                    double X          = sheet.Cell(nIndex - 1, 7 + 6 * ((nCount - 1) * 3 + nNumber)).ToDouble();
                    double Expire     = sheet.Cell(nIndex - 1, 8 + 6 * ((nCount - 1) * 3 + nNumber)).ToDouble();

                    OrderParameter Param = new OrderParameter();
                    Param.strPrice    = strPrice;
                    Param.dLot        = LotSize;
                    Param.dStopLoss   = StopLoss;
                    Param.dTakeProfit = TakeProfit;
                    Param.dX          = X;
                    Param.expireTime  = Expire;
                    return(Param);
                }
            }
            catch
            {
            }
            return(null);
        }
示例#2
0
        private void m_Timer_Tick(object sender, EventArgs e)
        {
            try
            {
                TitleCommand Command = m_GmailReader.ReadGmail();
                if (Command == null)
                {
                    return;
                }
                if (!m_Dic.ContainsKey(Command.OriginTitle))
                {
                    m_Dic.Add(Command.OriginTitle, 1);
                }
                else
                {
                    m_Dic[Command.OriginTitle]++;
                }

                string strLog = "================= EMAIL RECEIVED! =================\n";
                strLog += "Title : " + Command.OriginTitle +
                          "\nCount: " + m_Dic[Command.OriginTitle].ToString();
                Log(strLog);

                ShowEmailTitleCount();

                for (int i = 0; i < 3; i++)
                {
                    OrderParameter Param = m_XLSReader.ReadOrderParameters(Command.OriginTitle, m_Dic[Command.OriginTitle], i);
                    if (Param == null)
                    {
                        Log("################## Can't Search Information in Xls File! #####################");
                        return;
                    }

                    strLog  = "====================== INFORMATION FROM XLS FILE! ==========================\n";
                    strLog += "Price: " + Param.strPrice +
                              "\nLot: " + Param.dLot.ToString() +
                              "\nStopLoss: " + Param.dStopLoss.ToString() +
                              "\nTakeProfit: " + Param.dTakeProfit.ToString() +
                              "\nX: " + Param.dX.ToString() +
                              "\nExpireTime: " + Param.expireTime.ToString();
                    Log(strLog);

                    CandleStick Stick = m_MT4Controller.GetLastCandleStick(Command.Symbol, Command.Period);
                    if (Stick == null)
                    {
                        return;
                    }

                    strLog  = "=================== LASTEST CANDLE VALUES =====================\n";
                    strLog += "Low: " + Stick.Low.ToString() +
                              "\nHigh: " + Stick.High.ToString() +
                              "\nOpen: " + Stick.Open.ToString() +
                              "\nClose: " + Stick.Close.ToString();
                    Log(strLog);

                    double dPrice      = 0;
                    double dTakeProfit = 0;
                    double dStopLoss   = 0;
                    if (Param.strPrice == "Low")
                    {
                        dPrice = Stick.Low;
                    }
                    if (Param.strPrice == "High")
                    {
                        dPrice = Stick.High;
                    }
                    if (Param.strPrice == "Open")
                    {
                        dPrice = Stick.Open;
                    }
                    if (Param.strPrice == "Close")
                    {
                        dPrice = Stick.Close;
                    }

                    dPrice += Param.dX;

                    if (Command.Operation == "BUY")
                    {
                        dTakeProfit = dPrice + Param.dTakeProfit;
                        dStopLoss   = dPrice - Param.dStopLoss;
                    }
                    else if (Command.Operation == "SELL")
                    {
                        dTakeProfit = dPrice - Param.dTakeProfit;
                        dStopLoss   = dPrice + Param.dStopLoss;
                    }

                    DateTime expireTime = m_MT4Controller.GetCurrentMT4Time();
                    expireTime = expireTime.AddHours(Param.expireTime);

                    strLog  = "=================== ORDER PARAMETERS =====================\n";
                    strLog += "Symbol: " + Command.Symbol +
                              "\nOperation: " + Command.Operation +
                              "\nLot: " + Param.dLot.ToString() +
                              "\nPrice: " + dPrice.ToString() +
                              "\nExpireTime: " + expireTime.ToString() +
                              "\nTakeProfit: " + dTakeProfit.ToString() +
                              "\nStopLoss: " + dStopLoss.ToString() +
                              "\nSlippage: 20" +
                              "\nAskPrice: " + m_MT4Controller.GetAskPrice(Command.Symbol).ToString() +
                              "\nBidPrice: " + m_MT4Controller.GetBidPrice(Command.Symbol).ToString();
                    Log(strLog);

                    m_MT4Controller.SendOrder(Command.Symbol, Command.Operation, Param.dLot, dPrice, expireTime, dTakeProfit, dStopLoss);
                }
            }
            catch (Exception ex)
            {
                Log("############## SOME ERROR HAPPEND! ##############");
                Log(ex.ToString());
            }
        }