Beispiel #1
0
        public override void CopyTo(NinjaScript ninjaScript)
        {
            base.CopyTo(ninjaScript);

            Type newInstType = ninjaScript.GetType();

            System.Reflection.PropertyInfo gannAnglePropertyInfo = newInstType.GetProperty("GannAngles");
            if (gannAnglePropertyInfo == null)
            {
                return;
            }

            IList newInstGannAngles = gannAnglePropertyInfo.GetValue(ninjaScript) as IList;

            if (newInstGannAngles == null)
            {
                return;
            }

            // Since new instance could be past set defaults, clear any existing
            newInstGannAngles.Clear();
            foreach (GannAngle oldGannAngle in GannAngles)
            {
                try
                {
                    // Clone from the new assembly here to prevent losing existing GannAngles on compile
                    object newInstance = oldGannAngle.AssemblyClone(Core.Globals.AssemblyRegistry.GetType(typeof(GannAngle).FullName));

                    if (newInstance == null)
                    {
                        continue;
                    }

                    newInstGannAngles.Add(newInstance);
                }
                catch (ArgumentException)
                {
                    // In compiled assembly case, Add call will fail for different assemblies so do normal clone instead
                    object newInstance = oldGannAngle.Clone();

                    if (newInstance == null)
                    {
                        continue;
                    }

                    // Make sure to update our stroke to a new instance so we dont try to use the old one
                    IStrokeProvider strokeProvider = newInstance as IStrokeProvider;
                    if (strokeProvider != null)
                    {
                        Stroke oldStroke = strokeProvider.Stroke;
                        strokeProvider.Stroke = new Stroke();
                        oldStroke.CopyTo(strokeProvider.Stroke);
                    }

                    newInstGannAngles.Add(newInstance);
                }
                catch { }
            }
        }
Beispiel #2
0
        public override void CopyTo(NinjaScript ninjaScript)
        {
            base.CopyTo(ninjaScript);

            /* Handle price levels updating.
             * We can't use a cast here, because the incoming NS could be from a newer assembly,
             * so the cast would always fail. Dig it up using reflection. For the same reason,
             * we need to cast as something without specific type, List<PriceLevel> could fail, because
             * it could try to resovle PriceLevel to current assembly, when its holding a list of PriceLevels
             * from newer assembly as well. For this reason we cast to IList */
            Type         newInstType            = ninjaScript.GetType();
            PropertyInfo priceLevelPropertyInfo = newInstType.GetProperty("PriceLevels");

            if (priceLevelPropertyInfo == null)
            {
                return;
            }

            IList newInstPriceLevels = priceLevelPropertyInfo.GetValue(ninjaScript) as IList;

            if (newInstPriceLevels == null)
            {
                return;
            }

            // Since new instance could be past set defaults, clear any existing
            newInstPriceLevels.Clear();
            foreach (PriceLevel oldPriceLevel in PriceLevels)
            {
                try
                {
                    object newInstance = oldPriceLevel.AssemblyClone(Core.Globals.AssemblyRegistry.GetType(typeof(PriceLevel).FullName));
                    if (newInstance == null)
                    {
                        continue;
                    }

                    // Make sure to update our stroke to a new instance so we dont try to use the old one
                    IStrokeProvider strokeProvider = newInstance as IStrokeProvider;
                    if (strokeProvider != null)
                    {
                        Stroke oldStroke = strokeProvider.Stroke;
                        strokeProvider.Stroke = new Stroke();
                        oldStroke.CopyTo(strokeProvider.Stroke);
                    }
                    newInstPriceLevels.Add(newInstance);
                }
                catch { }
            }
        }
Beispiel #3
0
        public override void CopyTo(NinjaScript ninjaScript)
        {
            base.CopyTo(ninjaScript);

            Type newInstType = ninjaScript.GetType();

            System.Reflection.PropertyInfo gannAnglePropertyInfo = newInstType.GetProperty("GannAngles");
            if (gannAnglePropertyInfo == null)
            {
                return;
            }

            IList newInstGannAngles = gannAnglePropertyInfo.GetValue(ninjaScript) as IList;

            if (newInstGannAngles == null)
            {
                return;
            }

            // Since new instance could be past set defaults, clear any existing
            newInstGannAngles.Clear();
            foreach (GannAngle oldGannAngle in GannAngles)
            {
                try
                {
                    object newInstance = oldGannAngle.AssemblyClone(Core.Globals.AssemblyRegistry.GetType(typeof(GannAngle).FullName));
                    if (newInstance == null)
                    {
                        continue;
                    }

                    // Make sure to update our stroke to a new instance so we dont try to use the old one
                    IStrokeProvider strokeProvider = newInstance as IStrokeProvider;
                    if (strokeProvider != null)
                    {
                        Stroke oldStroke = strokeProvider.Stroke;
                        strokeProvider.Stroke = new Stroke();
                        oldStroke.CopyTo(strokeProvider.Stroke);
                    }
                    newInstGannAngles.Add(newInstance);
                }
                catch (Exception e) { NinjaTrader.Code.Output.Process(e.ToString(), PrintTo.OutputTab1); }
            }
        }