protected override void OnStateChange()
        {
            base.OnStateChange();

            if (State == State.SetDefaults)
            {
                Description = @"Enter the description for your new custom Strategy here.";
                Name        = "MySpreadTrader";
                IncludeTradeHistoryInBacktest = true;
                TraceOrders = false;
            }

            else if (State == State.DataLoaded)
            {
                Zweistein.FractionString f = new Zweistein.FractionString(QuantityRatio, ':');
                int lots1 = (int)f.Nominator * Units;
                int lots2 = (int)f.Denominator * Units;
                // spreadprices = Spread(Closes[0],PriceString, lots1, strLeg2Instrument,lots2, Leg1PriceDisplayMultiplier, Leg2PriceDisplayMultiplier);
                // we need this to avoid this NinjaTrader error: as we use Spread later on
                //"A hosted indicator tried to load additional data. All data must first be loaded by the hosting NinjaScript in its configure state"
            }
        }
        private void Itm1_Click(object sender, RoutedEventArgs e)
        {
            Zweistein.FractionString f = new Zweistein.FractionString(ptr2members.QuantityRatio, ':');
            int    A = (int)f.Nominator;
            int    B = (int)f.Denominator;
            string currenttemplate = "";

            try {
                currenttemplate = TemplateExtensions.SpreadChartTemplate(_strategy.InstrumentOrInstrumentList, ptr2members.strLeg2Instrument,
                                                                         A, B, ptr2members.Leg1PriceDisplayMultiplier, ptr2members.Leg2PriceDisplayMultiplier,
                                                                         ptr2members.PriceString, _strategy.BarsPeriods[0]);
            }
            catch (Exception ex) {
                _strategy.Print(ex.Message);
                return;
            }
            NinjaTrader.Gui.ControlCenter cc = Zweistein.NinjaTraderExtension.ControlCenter();


            NinjaTrader.Gui.Chart.BarsDialog BD = new  NinjaTrader.Gui.Chart.BarsDialog();
            if (BD != null)
            {
                MethodInfo mi4 = BD.GetType().GetMethod("SaveLastBarsPeriod", BindingFlags.Instance | BindingFlags.NonPublic);
                mi4.Invoke(BD, new object[] { _strategy.BarsPeriods[0] });
                //_strategy.Print("BD not null");
                BD = null;
            }
            MethodInfo mi = cc.GetType().GetMethod("OnChart", BindingFlags.Instance | BindingFlags.NonPublic);

            mi.Invoke(cc, new object[] { this, null });

            NinjaTrader.Core.Globals.RandomDispatcher.InvokeAsync(() =>
            {
                NinjaTrader.Gui.Chart.BarsDialog bdlg = null;
                for (int i = 0; i < 5; i++)
                {
                    System.Threading.Thread.Sleep(500);
                    bdlg = Zweistein.NinjaTraderExtension.BarsDialog();
                    if (bdlg != null)
                    {
                        MethodInfo mi3 = bdlg.GetType().GetMethod("SaveLastBarsPeriod", BindingFlags.Instance | BindingFlags.NonPublic);
                        mi3.Invoke(bdlg, new object[] { _strategy.BarsPeriods[0] });
                        break;
                    }
                }
                if (bdlg != null)
                {
                    bdlg.Dispatcher.Invoke(new Action(() =>
                    {
                        MethodInfo mi2 = bdlg.GetType().GetMethod("AddDataSeries", BindingFlags.Instance | BindingFlags.NonPublic);
                        mi2.Invoke(bdlg, new object[] { _strategy.Instruments[0] });

                        FieldInfo fi2   = bdlg.GetType().GetField("propertyGrid", BindingFlags.Instance | BindingFlags.NonPublic);
                        PropertyGrid pg = fi2.GetValue(bdlg) as PropertyGrid;

                        mi2.Invoke(bdlg, new object[] { _strategy.Instruments[1] });



                        FieldInfo fi3         = bdlg.GetType().GetField("cbxTemplates", BindingFlags.Instance | BindingFlags.NonPublic);
                        ComboBox cbxTemplates = fi3.GetValue(bdlg) as ComboBox;

                        int selectedindex = -1;
                        int i             = -1;
                        foreach (object o in  cbxTemplates.ItemsSource)
                        {
                            i++;
                            NinjaTrader.Gui.Chart.ChartTemplateWrapper w = o as NinjaTrader.Gui.Chart.ChartTemplateWrapper;
                            if (w == null)
                            {
                                continue;
                            }
                            if (w.DisplayName == currenttemplate)
                            {
                                selectedindex = i; break;
                            }
                        }
                        if (selectedindex >= 0)
                        {
                            cbxTemplates.Dispatcher.Invoke(() => {
                                cbxTemplates.SelectedIndex = selectedindex;
                            });
                        }

                        //private readonly BarsProperties preSelected;
                        //internal PropertyGrid propertyGrid;
                        FieldInfo fi   = bdlg.GetType().GetField("btnOk", BindingFlags.Instance | BindingFlags.NonPublic);
                        Button b       = fi.GetValue(bdlg) as Button;
                        MethodInfo mi3 = bdlg.GetType().GetMethod("OnOk", BindingFlags.Instance | BindingFlags.NonPublic);

                        if (b != null)
                        {
                            bdlg.Dispatcher.InvokeAsync(() =>
                            {
                                mi3.Invoke(bdlg, new object[] { b, null });
                            });
                        }
                    }
                                                      ));
                }
            });
        }