Exemplo n.º 1
0
        static decimal _crossrate(NinjaTrader.Cbi.Currency A, NinjaTrader.Cbi.Currency B)
        {
            if (ConversionRate.Count == 0)
            {
                FillConversionRate();
            }
            double d = 1.0;

            ConversionRate.TryGetValue(CurrencyConversion.ISO(A) + CurrencyConversion.ISO(B), out d);
            return((decimal)d);
        }
Exemplo n.º 2
0
        public MoneyString(string input)
        {
            try
            {
                if (string.IsNullOrEmpty(input))
                {
                    return;
                }
                // string is number currency
                string scur       = "";
                string numberpart = "";
                foreach (char c in input)
                {
                    if (char.IsSymbol(c))
                    {
                        scur += c;
                    }
                    else if (char.IsLetter(c))
                    {
                        scur += c;
                    }
                    else
                    {
                        numberpart += c;
                    }
                }


                foreach (NinjaTrader.Cbi.Currency cur in Enum.GetValues(typeof(NinjaTrader.Cbi.Currency)))
                {
                    string tmp = CurrencyConversion.ISO(cur);

                    if (scur.ToUpper().Contains(tmp.ToUpper()))
                    {
                        currency = cur;
                        break;
                    }
                    if (scur.Contains(Symbol(cur)))
                    {
                        currency = cur;
                        break;
                    }
                }
                amount = Convert.ToDouble(numberpart, CultureInfo.CurrentCulture);
            }
            catch { }
        }
Exemplo n.º 3
0
        public static bool IsPrefix(NinjaTrader.Cbi.Currency currency)
        {
            if (currency == NinjaTrader.Cbi.Currency.BritishPound)
            {
                return(true);
            }
            if (currency == NinjaTrader.Cbi.Currency.CanadianDollar)
            {
                return(true);
            }
            if (currency == NinjaTrader.Cbi.Currency.SwissFranc)
            {
                return(true);
            }
            if (currency == NinjaTrader.Cbi.Currency.UsDollar)
            {
                return(true);
            }
            if (currency == NinjaTrader.Cbi.Currency.JapaneseYen)
            {
                return(true);
            }
            if (currency == NinjaTrader.Cbi.Currency.IsraeliShekel)
            {
                return(true);
            }
            if (currency == NinjaTrader.Cbi.Currency.MalaysiaRinggit)
            {
                return(true);
            }
            if (currency == NinjaTrader.Cbi.Currency.ChinaYuan)
            {
                return(true);
            }
            if (currency == NinjaTrader.Cbi.Currency.SouthAfricanRand)
            {
                return(true);
            }
            if (currency == NinjaTrader.Cbi.Currency.HongKongDollar)
            {
                return(true);
            }

            return(false);
        }
Exemplo n.º 4
0
        public void SetBaseCurrency(NinjaTrader.Cbi.Currency currency)
        {
            Zweistein.NinjaTraderLog.Process("SetBaseCurrency:", "old:" + basecurrency.ToString() + " new:" + currency.ToString(), LogLevel.Information, LogCategories.Strategy);
            basecurrency = currency;
            decimal oldconvfactor0 = convfactor0;
            decimal oldconvfactor1 = convfactor1;

            convfactor0 = Zweistein.CurrencyConversion.Cube.Convert((decimal)1.0,
                                                                    Zweistein.CurrencyConversion.ISO(strategybase.Instruments[0].MasterInstrument.Currency),
                                                                    Zweistein.CurrencyConversion.ISO(basecurrency));


            convfactor1 = Zweistein.CurrencyConversion.Cube.Convert((decimal)1.0,
                                                                    Zweistein.CurrencyConversion.ISO(strategybase.Instruments[1].MasterInstrument.Currency),
                                                                    Zweistein.CurrencyConversion.ISO(basecurrency));

            totalprice0 *= (double)(convfactor0 / oldconvfactor0);
            totalprice1 *= (double)(convfactor1 / oldconvfactor1);
        }
 public void setCurrency(NinjaTrader.Cbi.Currency currency)
 {
     basecurrency     = currency;
     currencySymbol   = Zweistein.MoneyString.Symbol(basecurrency);
     currencyIsPrefix = Zweistein.MoneyString.IsPrefix(basecurrency);
 }
Exemplo n.º 6
0
        public static string Symbol(NinjaTrader.Cbi.Currency currency)
        {
            string cur = CurrencyConversion.ISO(currency);

            if (cur == "EUR")
            {
                return("€");                      // "EUR";
            }
            if (cur == "USD")
            {
                return("$");                        //prefix
            }
            // CHF  prefix
            if (cur == "GBP")
            {
                return("£");                        //prefix
            }
            if (cur == "JPY")
            {
                return("¥");                       // prefix  "YEN";
            }
            if (cur == "RUB")
            {
                return("₽");
            }
            if (cur == "ILS")
            {
                return("₪");              // prefix
            }
            if (cur == "CZK")
            {
                return("Kč");
            }
            if (cur == "DKK")
            {
                return("kr.");
            }
            if (cur == "BRL")
            {
                return("R$");
            }
            if (cur == "TWD")
            {
                return("NT$");
            }
            if (cur == "ZAR")
            {
                return("R");              //prefix
            }
            if (cur == "TRY")
            {
                return("₺");             //prefix
            }
            if (cur == "PLN")
            {
                return("zł");
            }
            //if (cur == "CNY") return  "¥"; //prefix same as JPY
            if (cur == "MYR")
            {
                return("RM");              //prefix
            }
            if (cur == "NOK")
            {
                return("kr");
            }
            if (cur == "INR")
            {
                return("₹");
            }
            if (cur == "HUF")
            {
                return("Ft");
            }
            return(cur);
        }
Exemplo n.º 7
0
 public Money(decimal amount, Currency currency)
 {
     this.currency = currency;
     this.amount   = amount;
 }
Exemplo n.º 8
0
 public void setCurrency(NinjaTrader.Cbi.Currency currency)
 {
     _currency = currency;
 }
Exemplo n.º 9
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);
                }
            }
        }