private void GenerateSimulation()
        {
            // Manage selected Stock and portofolio
            // Get selected portofolio
            StockPortofolio portofolio = this.stockPortofolioList.Get(this.portofolioComboBox.SelectedItem.ToString());
            portofolio.OrderList.Clear();

            // Get selected Stock
            StockSerie stockSerie = this.stockDictionary[this.SelectedStockName];
            if (!stockSerie.Initialise()) { return; }

            StockFilteredStrategyBase filteredStrategy = new StockFilteredStrategyBase(filterEvents, triggerEvents,
                buyTriggerComboBox.Text, shortTriggerComboBox.Text,
                buyFilterComboBox.Text, shortFilterComboBox.Text);

            StockAnalyzerForm.MainFrame.SetThemeFromStrategy(filteredStrategy);

            StockOrder lastOrder = stockSerie.GenerateSimulation(filteredStrategy,
                simulationParameterControl.StartDate, simulationParameterControl.EndDate.AddHours(18),
                simulationParameterControl.amount, simulationParameterControl.reinvest,
                simulationParameterControl.amendOrders, simulationParameterControl.supportShortSelling,
                this.simulationParameterControl.takeProfit, this.simulationParameterControl.profitRate,
                this.simulationParameterControl.stopLoss, this.simulationParameterControl.stopLossRate,
                simulationParameterControl.fixedFee, simulationParameterControl.taxRate, portofolio);

            // Do a bit of cleanup
            if (lastOrder != null && this.simulationParameterControl.removePendingOrders)
            {
                if (lastOrder.IsBuyOrder())
                {
                    lastOrder = null;
                }
                else
                {
                    if (lastOrder.State != StockOrder.OrderStatus.Executed)
                    {
                        portofolio.OrderList.Remove(portofolio.OrderList.Last());
                        lastOrder = null;
                    }
                }
            }

            if (this.simulationParameterControl.displayPendingOrders && lastOrder != null && lastOrder.State == StockOrder.OrderStatus.Pending)
            {
                OrderEditionDlg orderEditionDlg = new OrderEditionDlg(lastOrder);
                orderEditionDlg.StartPosition = FormStartPosition.Manual;
                orderEditionDlg.Location = new Point(0, 0);
                orderEditionDlg.ShowDialog();
            }
        }
        private void saveButton_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(this.strategyNameTextBox.Text))
            {
                MessageBox.Show("Provide a strategy name");
                return;
            }

            if (filterIndicatorTextBox.Text == string.Empty || string.IsNullOrEmpty(buyFilterComboBox.SelectedItem.ToString()) ||
                string.IsNullOrEmpty(shortFilterComboBox.SelectedItem.ToString()))
            {
                MessageBox.Show("Invalid filter: " + filterIndicatorTextBox.Text);
                return;
            }

            if (triggerIndicatorTextBox.Text == string.Empty ||
                string.IsNullOrEmpty(buyFilterComboBox.SelectedItem.ToString()) ||
                string.IsNullOrEmpty(shortFilterComboBox.SelectedItem.ToString()))
            {
                MessageBox.Show("Invalid trigger: " + triggerIndicatorTextBox.Text);
                return;
            }

            StockFilteredStrategyBase filteredStrategy = new StockFilteredStrategyBase(filterEvents, triggerEvents,
               buyTriggerComboBox.Text, shortTriggerComboBox.Text,
               buyFilterComboBox.Text, shortFilterComboBox.Text);

            filteredStrategy.Name = this.strategyNameTextBox.Text;

            filteredStrategy.Save(Settings.Default.RootFolder);
            this.simulationParameterControl.LoadStrategies(filteredStrategy.Name);

            StrategyManager.ResetStrategyList();
        }
 public void SetThemeFromStrategy(StockFilteredStrategyBase strategy)
 {
     using (MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(strategy.ToTheme())))
     {
         using (StreamReader sr = new StreamReader(ms))
         {
             this.LoadThemeStream(WORK_THEME, sr);
         }
     }
     if (this.themeComboBox.SelectedItem.ToString() == WORK_THEME)
     {
         this.ApplyTheme();
     }
     else
     {
         this.themeComboBox.SelectedItem = WORK_THEME;
     }
 }