Ejemplo n.º 1
0
        public void CloseAll()
        {
            m_nowCloseManually = m_deals.Count;
            foreach (var i in m_deals)
            {
                if (i.DealType == 'B')
                {
                    float cost = ((float)m_nowPrice.close - i.OpenPrice - spread) * DealsInfo.GetPointInv(m_nowPrice.close);
                    m_nowCost -= cost * i.Volume;
                }
                else if (i.DealType == 'S')
                {
                    float cost = (i.OpenPrice - (float)m_nowPrice.close - spread) * DealsInfo.GetPointInv(m_nowPrice.close);
                    m_nowCost -= cost * i.Volume;
                }
                m_nowVolume += i.Volume;
            }

            m_deals.Clear();
        }
Ejemplo n.º 2
0
        private void CalculateCurrent()
        {
            m_currentProfit = 0;
            m_currentCost   = 0;
            m_currentVolume = 0;



            foreach (var i in m_deals)
            {
                m_currentVolume += i.Volume;
                m_currentCost   += i.Cost * i.Volume;

                if (m_nowPrice.close > 0)
                {
                    if (i.DealType == 'B')
                    {
                        float cost = ((float)m_nowPrice.close - i.OpenPrice - spread) * DealsInfo.GetPointInv(m_nowPrice.close);
                        m_currentProfit -= cost * i.Volume;
                    }
                    else if (i.DealType == 'S')
                    {
                        float cost = (i.OpenPrice - (float)m_nowPrice.close - spread) * DealsInfo.GetPointInv(m_nowPrice.close);
                        m_currentProfit -= cost * i.Volume;
                    }
                }
            }
        }
Ejemplo n.º 3
0
        //private void CalculateDealClose(DealInfo i)
        //{
        //    if (m_nowPrice.low == 0 || m_nowPrice.high == 0)
        //    {
        //        throw new AssertException("nowPrice low or high is not set.");
        //    }
        //    if (i.DealType == 'B')
        //    {
        //        if (m_nowPrice.low <= i.ClosePriceSl + spread)
        //        {
        //            m_nowFp++;
        //            float cost = (i.ClosePriceSl - i.OpenPrice - spread) * GetPointInv(m_nowPrice.close);
        //            m_nowCost -= cost * i.Volume;
        //            i.CloseTime = m_nowTime;
        //            i.Cost = -cost;
        //        }
        //        else if (m_nowPrice.high >= i.ClosePriceTp - spread)
        //        {
        //            m_nowTp++;
        //            float cost = (i.ClosePriceTp - i.OpenPrice - spread) * GetPointInv(m_nowPrice.close);
        //            m_nowCost -= cost * i.Volume;
        //            i.CloseTime = m_nowTime;
        //            i.Cost = -cost;
        //        }
        //        else
        //        {
        //            float cost = (float)(m_nowPrice.close - i.OpenPrice - spread) * GetPointInv(m_nowPrice.close);
        //            m_currentProfit -= cost * i.Volume;
        //        }
        //    }
        //    else
        //    {
        //        if (m_nowPrice.high + spread > i.ClosePriceSl)
        //        {
        //            m_nowFp++;
        //            float cost = ((i.OpenPrice - i.ClosePriceSl) - spread) * GetPointInv(m_nowPrice.close);
        //            m_nowCost -= cost * i.Volume;
        //            i.CloseTime = m_nowTime;
        //            i.Cost = -cost;
        //        }
        //        else if (m_nowPrice.low + spread < i.ClosePriceTp)
        //        {
        //            m_nowTp++;
        //            float cost = ((i.OpenPrice - i.ClosePriceTp) - spread) * GetPointInv(m_nowPrice.close);
        //            m_nowCost -= cost * i.Volume;
        //            i.CloseTime = m_nowTime;
        //            i.Cost = -cost;
        //        }
        //        else
        //        {
        //            float cost = (float)((i.OpenPrice - m_nowPrice.close) - spread) * GetPointInv(m_nowPrice.close);
        //            m_currentProfit -= cost * i.Volume;
        //        }
        //    }
        //}
        public void CloseAll()
        {
            m_nowCost       = 0;
            m_currentProfit = 0;
            m_nowTp         = 0;
            m_nowFp         = 0;

            m_totalVolume = 0;
            m_totalDeal   = 0;

            foreach (var i in m_deals)
            {
                if (i.CloseTime.HasValue)
                {
                    if (i.CloseTime <= m_nowTime)
                    {
                        if (i.Cost < 0)
                        {
                            m_nowTp++;
                        }
                        else
                        {
                            m_nowFp++;
                        }

                        m_nowCost += i.Cost * i.Volume;
                    }
                    else
                    {
                        if (i.DealType == 'B')
                        {
                            float cost = (float)(m_nowPrice.close - i.OpenPrice - spread) * DealsInfo.GetPointInv(m_nowPrice.close);
                            m_nowCost -= cost * i.Volume;
                            if (cost < 0)
                            {
                                m_nowTp++;
                            }
                            else
                            {
                                m_nowFp++;
                            }
                        }
                        else if (i.DealType == 'S')
                        {
                            float cost = (float)(i.OpenPrice - m_nowPrice.close - spread) * DealsInfo.GetPointInv(m_nowPrice.close);
                            m_nowCost -= cost * i.Volume;
                            if (cost < 0)
                            {
                                m_nowTp++;
                            }
                            else
                            {
                                m_nowFp++;
                            }
                        }
                    }
                }
            }


            m_deals.Clear();
        }