Ejemplo n.º 1
0
        public object Clone()
        {
            SingleSpread s = new SingleSpread();

            s.Lots1          = this.Lots1;
            s.Lots2          = this.Lots2;
            s.MarketPosition = this.MarketPosition;
            s.NUnits         = this.NUnits;
            s.Leg1Tokens     = this.Leg1Tokens;
            s.Leg2Tokens     = this.Leg2Tokens;
            s.IEHData        = this.iehdata;
            s.ConvFactor0    = this.ConvFactor0;
            s.ConvFactor1    = this.ConvFactor1;
            s.Guid           = this.Guid;
            s.BaseCurrency   = this.BaseCurrency;
            s.Totalprice0    = this.Totalprice0;
            s.Totalprice1    = this.Totalprice1;
            return(s);                 // call clone method
        }
Ejemplo n.º 2
0
        public SingleSpread(ref Queue <SingleSpread> transferfrom, NinjaTrader.Cbi.Currency currency)
        {
            int tmpunits = 0;

            Zweistein.FractionString f = null;

            SetBaseCurrency(currency);

            List <SingleSpread> toremove = new List <SingleSpread>();

            foreach (SingleSpread s in transferfrom)
            {
                if (s.exit[0].Order != null || s.exit[1].Order != null)
                {
                    continue;
                }
                if (s.mleg1 == NinjaTrader.Cbi.MarketPosition.Long)
                {
                    if (s.positionX != s.lots1)
                    {
                        continue;
                    }
                    if (-1 * s.positionY != s.lots2)
                    {
                        continue;
                    }
                }
                if (s.mleg1 == NinjaTrader.Cbi.MarketPosition.Short)
                {
                    if (-1 * s.positionX != s.lots1)
                    {
                        continue;
                    }
                    if (s.positionY != s.lots2)
                    {
                        continue;
                    }
                }
                if (s.mleg1 == NinjaTrader.Cbi.MarketPosition.Flat)
                {
                    continue;
                }
                if (s.MarketPosition == NinjaTrader.Cbi.MarketPosition.Long)
                {
                    tmpunits += s.NUnits;
                }
                if (s.MarketPosition == NinjaTrader.Cbi.MarketPosition.Short)
                {
                    tmpunits -= s.NUnits;
                }
                totalprice0 += (double)Zweistein.CurrencyConversion.Cube.Convert((decimal)s.totalprice0, Zweistein.CurrencyConversion.ISO(s.BaseCurrency), Zweistein.CurrencyConversion.ISO(basecurrency));
                totalprice1 += (double)Zweistein.CurrencyConversion.Cube.Convert((decimal)s.totalprice1, Zweistein.CurrencyConversion.ISO(s.BaseCurrency), Zweistein.CurrencyConversion.ISO(basecurrency));

                positionX += s.positionX;
                positionY += s.positionY;
                if (s.units > 0)
                {
                    int k1 = s.lots1 / s.units;
                    int k2 = s.lots2 / s.units;
                    if (f == null)
                    {
                        f            = new Zweistein.FractionString(k1.ToString() + ":" + k2.ToString(), ':');
                        strategybase = s.strategybase;
                    }
                }
                toremove.Add(s);
            }



            if (f == null)
            {
                throw new ArgumentNullException("SingleSpread(ref Queue<SingleSpread> spreads) , spreads is empty collection");
            }
            if (tmpunits > 0)
            {
                this.mleg1 = NinjaTrader.Cbi.MarketPosition.Long;
            }
            else
            {
                if (tmpunits < 0)
                {
                    this.mleg1 = NinjaTrader.Cbi.MarketPosition.Short;
                }
            }

            if (tmpunits == 0)
            {
                throw new ArgumentNullException("SingleSpread(ref Queue<SingleSpread> spreads) , tmpunits == 0");
            }
            units = Math.Abs(tmpunits);
            lots1 = (int)f.Nominator * units;
            lots2 = (int)f.Denominator * units;
            if (lots1 == 0 || lots2 == 0)
            {
                throw new ArgumentNullException("SingleSpread , incomplete spread defintion: lots1 or lots2 == 0");
            }

            foreach (SingleSpread r in toremove)
            {
                for (int i = 0; i < transferfrom.Count; i++)
                {
                    SingleSpread q = transferfrom.Dequeue();
                    if (q == r)
                    {
                        break;
                    }
                    transferfrom.Enqueue(q);
                }
            }
        }