Exemple #1
0
        /// <summary>
        /// Processes the indicator.
        /// </summary>
        /// <param name="Name">The indicator name.</param>
        /// <returns></returns>
        private List <double> ProcessIndicator(string Name)
        {
            List <double> ret = new List <double>();
            //ctlChart chart = frmMain.GInstance.m_ActiveChart;
            CtlPainelChart chart = frmMain.GInstance.MActiveChart;

            if (chart == null)
            {
                return(ret);
            }

            int           count  = chart.StockChartX1.RecordCount;
            NeuralNetwork nn     = new NeuralNetwork();
            List <double> values = new List <double>(count);

            for (int n = 1; n < count + 1; ++n)
            {
                values.Add(chart.StockChartX1.GetValue(Name, n));
            }

            // TODO: Optionally you could allow the end user to set these parameters.
            int    periods      = 8;
            double learningRate = 1.5;
            int    epochs       = 5000;

            ret = nn.NeuralIndicator(values, periods, learningRate, epochs, 0.5);

            return(ret);
        }
Exemple #2
0
        public void AddChart(CtlPainelChart chart, DockWindow Window, XmlNode Propriedades, XmlNode node, string simbolo, Periodicity periodicity, int barSize, int mBars, string windowName)
        {
            chart.StockChartX1.Visible = false;

            chart.LoadCtlPainelChart(frmMain2.GInstance, frmMain2.GInstance._mCtlData, simbolo, periodicity, barSize,
                                     mBars, "Plena", true);


            chart.StateDummy       = true;
            chart.BlockUpdateStock = true;
            chart.m_StopLoadScroll = true;
            Window.Controls.Add(chart);
            chart.BlockUpdateStock = false;
            frmMain2.XmlChartPropriedades(chart, Propriedades);
            if (Window.DockState == DockState.Floating)
            {
                Window.FloatingParent.ShowInTaskbar   = true;
                Window.FloatingParent.MinimizeBox     = true;
                Window.FloatingParent.MaximizeBox     = true;
                Window.FloatingParent.FormBorderStyle = FormBorderStyle.Sizable;
                Window.FloatingParent.Activated      += new EventHandler(frmMain2.GInstance.Window_Activated);
                Window.FloatingParent.Closing        += new System.ComponentModel.CancelEventHandler(frmMain2.GInstance.Window_Closing);
                frmMain2.Window_Initialize(Window, chart);
            }

            if ((node["VISIBLE"] != null) && (node["VISIBLE"].InnerText.Equals("0")))
            {
                return;
            }
            chart.StateDummy = false;
            chart.InitRTChartAsync(b => chart._asyncOp.Post(() =>
            {
                if (b)
                {
                    chart.StockChartX1.FirstVisibleRecord = int.Parse(Propriedades["FIRST_VISIBLE_RECORD"].InnerText);
                    chart.StockChartX1.LastVisibleRecord  = int.Parse(Propriedades["LAST_VISIBLE_RECORD"].InnerText);
                    chart.BindContextMenuEvents();
                    chart.m_SchemeColor = Propriedades["COLOR"].InnerText;
                    Scheme.Instance().UpdateChartColors(chart.StockChartX1, chart.m_SchemeColor);
                    //chart.StockChartX1.Update();
                    //chart.StockChartX1.ForcePaint();
                    frmMain2.GInstance.MActiveChart = chart;
                    chart.LoadDataTemplate("-987654321.123456789");
                    chart.UpdateMenus();
                    chart.StockChartX1.Visible = true;
                    chart.StockChartX1.Width   = chart.Width - 4;
                    //frmMain2.GInstance.LoadColorScheme(chart);
                    if (File.Exists(windowName))
                    {
                        chart.StockChartX1.LoadGeneralTemplate(windowName);
                    }
                    chart.LoadScroll();
                    return;
                }
                return;
            }));
        }
Exemple #3
0
        private void SavePrice()
        {
            PriceInfo priceInfo = (PriceInfo)pgrdPrice.SelectedObject;

            if (cbApplyAll.Checked)
            {
                //Apply in All charts
                foreach (DockWindow window in frmMain2.GInstance.radDock2.DockWindows)
                {
                    if (window.AccessibleName.Equals("CtlPainelChart"))
                    {
                        CtlPainelChart ctlPanel = (CtlPainelChart)window.Controls[0];

                        //Heikin Ashi Smooth params
                        ctlPanel.StockChartX1.SmoothHeikinType    = priceInfo.TipoMedia.GetHashCode();
                        ctlPanel.StockChartX1.SmoothHeikinPeriods = priceInfo.Period;
                        if (ctlPanel.m_PriceStyle == "Heikin Ashi Smooth")
                        {
                            ctlPanel.ChangePriceStyle("Heikin Ashi Smooth", true);
                        }

                        //_mCtlParent.StockChartX1.PriceLineMono = priceInfo.LineMono;
                        ctlPanel.StockChartX1.PriceLineThickness    = priceInfo.LineThickness;
                        ctlPanel.StockChartX1.PriceLineThicknessBar = priceInfo.BarLineThickness;

                        ctlPanel.StockChartX1.ForcePaint();
                    }
                }
            }

            //Apply only in current chart!!!

            //Heikin Ashi Smooth params
            _mCtlParent.StockChartX1.SmoothHeikinType    = priceInfo.TipoMedia.GetHashCode();
            _mCtlParent.StockChartX1.SmoothHeikinPeriods = priceInfo.Period;

            //_mCtlParent.StockChartX1.PriceLineMono = priceInfo.LineMono;
            _mCtlParent.StockChartX1.PriceLineThickness    = priceInfo.LineThickness;
            _mCtlParent.StockChartX1.PriceLineThicknessBar = priceInfo.BarLineThickness;


            if (_mCtlParent.m_PriceStyle == "Heikin Ashi Smooth")
            {
                _mCtlParent.ChangePriceStyle("Heikin Ashi Smooth", true);
            }
            else
            {
                _mCtlParent.StockChartX1.ForcePaint();
            }
        }
Exemple #4
0
        // Load available technical indicators
        private void frmNN_Load(object sender, EventArgs e)
        {
            //ctlChart chart = frmMain.GInstance.m_ActiveChart;
            CtlPainelChart chart = frmMain.GInstance.MActiveChart;

            if (chart == null)
            {
                return;
            }

            lstAvailable.Items.Clear();
            lstSelected.Items.Clear();

            List <string> series = chart.GetSeries();

            lstAvailable.Items.AddRange(series.ToArray());
        }
Exemple #5
0
        public FrmPriceSettings(CtlPainelChart parent)
        {
            _mCtlParent = parent;

            InitializeComponent();
            //LoadProxy();

            //LoadConfigProxy();

            TranslateForm();

            //tabChart.BackColor = Utils.GetDefaultBackColor();
            //tabProxy.BackColor = Utils.GetDefaultBackColor();
            //tabServer.BackColor = Utils.GetDefaultBackColor();
            //tabStudies.BackColor = Utils.GetDefaultBackColor();
            tabPrice.BackColor = Utils.GetDefaultBackColor();
        }
Exemple #6
0
 public void InsertCtlFromWindow(DockWindow window)
 {
     if (window.Controls.Count > 0 && window.Controls.ContainsKey("CtlPainelChart"))
     {
         CtlPainelChart chart = (CtlPainelChart)window.Controls[0];
         if (Members.Contains(chart))
         {
             chart.StateUsed = false;
         }
         else
         {
             Members.Add(chart);
         }
         window.Controls.Clear();
         chart.SuspendEvents();
     }
 }
Exemple #7
0
 public void InsertFromDockControls(RadDock dock)
 {
     foreach (DockWindow window in dock.DockWindows.Where(doc => doc.AccessibleName == "CtlPainelChart"))
     {
         CtlPainelChart chart = (CtlPainelChart)window.Controls[0];
         if (Members.Contains(chart))
         {
             chart.StateUsed = false;
         }
         else
         {
             Members.Add(chart);
         }
         window.Controls.Clear();
         chart.SuspendEvents();
     }
 }
Exemple #8
0
 public ndtChartTools(CtlPainelChart ctlPainelChartParent, frmMain2 frmMain2)
 {
     frmMain      = frmMain2;
     MActiveChart = ctlPainelChartParent;
     InitializeComponent();
     cmdDeltaCursor.ToggleStateChanging -= cmdDeltaCursor_ToggleStateChanging;
     cmdSelect.ToggleStateChanging      -= cmdSelect_ToggleStateChanging;
     cmdCrosshair.ToggleStateChanging   -= cmdCrosshair_ToggleStateChanging;
     cmdMagnetic.ToggleStateChanging    -= cmdMagnetic_ToggleStateChanging;
     cmdDeltaCursor.ToggleState          = frmMain2.cmdDeltaCursor.ToggleState;
     cmdSelect.ToggleState               = frmMain2.cmdSelect.ToggleState;
     cmdCrosshair.ToggleState            = frmMain2.cmdCrosshair.ToggleState;
     cmdMagnetic.ToggleState             = frmMain2.cmdMagnetic.ToggleState;
     cmdDeltaCursor.ToggleStateChanging += cmdDeltaCursor_ToggleStateChanging;
     cmdSelect.ToggleStateChanging      += cmdSelect_ToggleStateChanging;
     cmdCrosshair.ToggleStateChanging   += cmdCrosshair_ToggleStateChanging;
     cmdMagnetic.ToggleStateChanging    += cmdMagnetic_ToggleStateChanging;
     MActiveChart.popout           = true;
     MActiveChart.ChartToolsPopOut = this;
     SetupButtons();
 }
Exemple #9
0
        private void cmdLineColor_Click(object sender, EventArgs e)
        {
            RadColorDialogForm colorBox = new RadColorDialogForm();

            frmMain.configStudies  = ListConfigStudies.Instance().LoadListConfigStudies();
            colorBox.SelectedColor = frmMain.configStudies.Color;
            if (colorBox.ShowDialog() == DialogResult.OK)
            {
                frmMain.configStudies.Color = colorBox.SelectedColor;
            }
            ListConfigStudies.Instance().Update(frmMain.configStudies);
            //Change all charts status:
            foreach (DockWindow window in frmMain.radDock2.DockWindows)
            {
                if (window.AccessibleName.Equals("CtlPainelChart"))
                {
                    CtlPainelChart ctlPanel = (CtlPainelChart)window.Controls[0];
                    ctlPanel.StockChartX1.LineColor = frmMain.configStudies.Color;
                }
            }
        }
Exemple #10
0
        /// <summary>
        /// Runs the neural network.
        /// </summary>
        public void DoWork(List <string> seriesNames)
        {
            ResultCount = seriesNames.Count + 1;
            bool cancel = false;

            List <double> ret = new List <double>();
            //ctlChart chart = frmMain.GInstance.m_ActiveChart;
            CtlPainelChart chart = frmMain.GInstance.MActiveChart;

            if (chart == null)
            {
                return;
            }

            int count = chart.StockChartX1.RecordCount;

            double[] sum = new double[count];

            // Run the neural network
            int current = 0;

            foreach (string item in seriesNames)
            {
                current++;
                if (ProgressCallback != null)
                {
                    ProgressCallback(this, ResultCount, current, ref cancel);
                }

                if (cancel)
                {
                    return;
                }
                List <double> values = ProcessIndicator(item);
                for (int n = 0; n < count; ++n)
                {
                    sum[n] += values[n];
                }
            }

            for (int n = 0; n < sum.Length; ++n)
            {
                sum[n] /= seriesNames.Count;
                sum[n]  = sum[n] * 1000;
            }

            if (ProgressCallback != null)
            {
                ProgressCallback(this, ResultCount, current + 1, ref cancel);
            }

            // Display the results in StockChartX
            chart.StockChartX1.RemoveSeries("Neural Network");
            int panel = chart.StockChartX1.AddChartPanel();

            chart.StockChartX1.AddSeries("Neural Network", STOCKCHARTXLib.SeriesType.stLineChart, panel);

            chart.StockChartX1.Freeze(true);
            for (int n = 0; n < count; ++n)
            {
                if (cancel)
                {
                    return;
                }
                double jdate = chart.StockChartX1.GetJDate(chart.StockChartX1.Symbol + ".close", n + 1);
                double value = sum[n];
                if (value == 0)
                {
                    value = (double)STOCKCHARTXLib.DataType.dtNullValue;
                }
                chart.StockChartX1.AppendValue("Neural Network", jdate, value);
            }
            chart.StockChartX1.Freeze(false);
            chart.StockChartX1.Update();
        }
Exemple #11
0
        //Runs the backtest and displays the chart with buy/sell/exit icons.
        private string RunBacktest()
        {
            string ret = string.Empty;

            try
            {
                oScript.ClearRecords();
                oBacktest.ClearRecords();

                if (!VerifyForm())
                {
                    return(string.Empty);
                }
                if (!TestScripts())
                {
                    return(string.Empty);
                }
                if (m_ctlData == null)
                {
                    return(string.Empty);
                }

                cmdBacktest.Text = "&Stop Backtest";
                EnableControls(false);

                Periodicity periodicity;
                switch (cboPeriodicity.Text)
                {
                case "Minute":
                    periodicity = Periodicity.Minutely;
                    break;

                case "Hour":
                    periodicity = Periodicity.Hourly;
                    break;

                case "Day":
                    periodicity = Periodicity.Daily;
                    break;

                case "Week":
                    periodicity = Periodicity.Weekly;
                    break;

                default:
                    periodicity = Periodicity.Minutely;
                    break;
                }

                cmdBacktest.Enabled = false;


                Telerik.WinControls.UI.Docking.DockWindow activeDoc = frmMain2.GInstance.radDock2.DocumentManager.ActiveDocument;


                //Get the data selection
                M4Core.Entities.ChartSelection selection = new M4Core.Entities.ChartSelection
                {
                    Periodicity = (M4Core.Entities.Periodicity)periodicity,
                    Symbol      = txtSymbol.Text,
                    Interval    = Convert.ToInt32(txtInterval.Text),
                    Bars        = Convert.ToInt32(txtBars.Text)
                };

                m_ctlData.LoadRealTimeCtlPainelChartAsync2(selection, new Action <CtlPainelChart>(chart =>
                {
                    m_chart = chart;
                    if (m_chart == null)
                    {
                        goto Quit;
                    }

                    DataManager.BarData[] bars = m_chart.GetDataFromChart();
                    if (bars.Length < 1)
                    {
                        goto Quit;
                    }

                    m_chart.Subscribers    += 1;
                    m_chart.RealTimeUpdates = false;

                    //Get historic data
                    cmdBacktest.Enabled = true;
                    if (bars.Length < 3)
                    {
                        goto Quit;                  //Bad request
                    }
                    //Insert the data into all four instances of TradeScript
                    oScript.ClearRecords();
                    oBacktest.ClearRecords();

                    DateTime td;
                    double jdate;
                    for (int n = 1; n < bars.Length - 1; n++)
                    {
                        td    = bars[n].TradeDate;
                        jdate = oScript.ToJulianDate(td.Year, td.Month, td.Day, td.Hour, td.Minute, td.Second, 0);
                        oScript.AppendRecord(jdate, bars[n].OpenPrice, bars[n].HighPrice,
                                             bars[n].LowPrice, bars[n].ClosePrice, (int)bars[n].Volume);
                        oBacktest.AppendRecord(jdate, bars[n].OpenPrice, bars[n].HighPrice,
                                               bars[n].LowPrice, bars[n].ClosePrice, (int)bars[n].Volume);
                    }

                    //TODO
                    ret = oBacktest.Backtest(txtBuyScript, txtSellScript, txtExitLongScript, txtExitShortScript, 0.001);
                    if (string.IsNullOrEmpty(ret))
                    {
                        goto Quit;
                    }

                    string output =
                        oScript.GetScriptOutput(txtBuyScript + " AND \r\n" + txtSellScript + " AND \r\n" + txtExitLongScript +
                                                " AND \r\n" + txtExitShortScript);
                    if (string.IsNullOrEmpty(output))
                    {
                        goto Quit;
                    }

                    int row;
                    string[] cols;
                    int col;
                    string[] rows   = output.Split(new[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
                    string[] Header = SplitHeader(rows[0]);


                    //StockChartX
                    AxSTOCKCHARTXLib.AxStockChartX StockChartX1 = m_chart.StockChartX1;
                    StockChartX1.RemoveAllSeries();

                    string symbol = selection.Symbol;

                    StockChartX1.Symbol = symbol;


                    StockChartX1.AddChartPanel();
                    StockChartX1.AddSeries(symbol + ".open", STOCKCHARTXLib.SeriesType.stCandleChart, 0);
                    StockChartX1.AddSeries(symbol + ".high", STOCKCHARTXLib.SeriesType.stCandleChart, 0);
                    StockChartX1.AddSeries(symbol + ".low", STOCKCHARTXLib.SeriesType.stCandleChart, 0);
                    StockChartX1.AddSeries(symbol + ".close", STOCKCHARTXLib.SeriesType.stCandleChart, 0);
                    StockChartX1.set_SeriesColor(symbol + ".close", ColorTranslator.ToOle(Color.Black));



                    //OLD BEHAVIOR: Add generic serie

                    /*
                     * for (col = 6; col < Header.Length; col++)
                     * {
                     *  int panel = 0;
                     *  panel = StockChartX1.AddChartPanel();
                     *
                     *  StockChartX1.AddSeries(Header[col], STOCKCHARTXLib.SeriesType.stLineChart, panel);
                     *
                     *  System.Drawing.Color color;
                     *  switch (col)
                     *  {
                     *      case 6:
                     *          color = System.Drawing.Color.Blue;
                     *          break;
                     *      case 7:
                     *          color = System.Drawing.Color.Red;
                     *          break;
                     *      case 8:
                     *          color = System.Drawing.Color.Green;
                     *          break;
                     *      case 9:
                     *          color = System.Drawing.Color.Orange;
                     *          break;
                     *      case 10:
                     *          color = System.Drawing.Color.Purple;
                     *          break;
                     *      default:
                     *          color = System.Drawing.Color.Blue;
                     *          break;
                     *  }
                     *  StockChartX1.set_SeriesColor(Header[col], System.Drawing.ColorTranslator.ToOle(color));
                     *
                     * }*/

                    for (row = 1; row < rows.Length; row++)
                    {
                        cols  = rows[row].Split(',');
                        jdate = GetJDate(cols[0]);
                        StockChartX1.AppendValue(symbol + ".open", jdate, Convert.ToDouble(cols[1], ciEnUs));
                        StockChartX1.AppendValue(symbol + ".high", jdate, Convert.ToDouble(cols[2], ciEnUs));
                        StockChartX1.AppendValue(symbol + ".low", jdate, Convert.ToDouble(cols[3], ciEnUs));
                        StockChartX1.AppendValue(symbol + ".close", jdate, Convert.ToDouble(cols[4], ciEnUs));

                        //OLD BEHAVIOR: Add generic serie

                        /*
                         *  for (col = 6; col < cols.Length; col++)
                         *  {
                         *      double value = Convert.ToDouble(cols[col], ciEnUs);
                         *      if (value == 0 && row < rows.Length * 0.2)
                         *      {
                         *          value = (double)STOCKCHARTXLib.DataType.dtNullValue;
                         *      }
                         *
                         *      StockChartX1.AppendValue(Header[col], jdate, value);
                         *  }
                         */
                    }

                    //NEW BEHAVIOR: Add known indicators (it doesnt work with others indicators!)
                    for (col = 6; col < Header.Length; col++)
                    {
                        //Try to add until available key isnt found:
                        bool errorKey    = true;
                        int indicatorKey = 1;
                        while (errorKey)
                        {
                            try
                            {
                                System.Drawing.Color color;
                                switch (col)
                                {
                                case 6:
                                    color = System.Drawing.Color.Blue;
                                    break;

                                case 7:
                                    color = System.Drawing.Color.Red;
                                    break;

                                case 8:
                                    color = System.Drawing.Color.Green;
                                    break;

                                case 9:
                                    color = System.Drawing.Color.Orange;
                                    break;

                                case 10:
                                    color = System.Drawing.Color.Purple;
                                    break;

                                default:
                                    color = System.Drawing.Color.Blue;
                                    break;
                                }
                                //param[0  1   2   3]
                                //   MM(1,14,CLOSE,0)
                                if (Header[col].Contains("MM("))
                                {
                                    string indScript = Header[col].Replace("MM(", "");
                                    indScript        = indScript.Replace(")", "");
                                    string[] param   = indScript.Split(new char[] { ',' });
                                    string source    = symbol + ".Close";
                                    switch (param[2])
                                    {
                                    case "OPEN":
                                        source = symbol + ".Open";
                                        break;

                                    case "HIGH":
                                        source = symbol + ".High";
                                        break;

                                    case "LOW":
                                        source = symbol + ".Low";
                                        break;

                                    default:
                                        source = symbol + ".Close";
                                        break;
                                    }
                                    StockChartX1.AddIndicatorGenericMovingAverage("MA" + indicatorKey, 0, source,
                                                                                  int.Parse(param[1]), int.Parse(param[3]), int.Parse(param[0]), 0, color.R,
                                                                                  color.G,
                                                                                  color.B, 0, 1);
                                }
                                errorKey = false;
                            }
                            catch (Exception ex)
                            {
                                if (ex.Message == "Key not unique")
                                {
                                    errorKey = true;
                                    indicatorKey++;
                                }
                                else
                                {
                                    Telerik.WinControls.RadMessageBox.Show(ex.Message);
                                }
                            }
                        }
                    }
                    StockChartX1.Update();

                    Quit:

                    if (m_chart != null)
                    {
                        m_chart.Show();
                    }

                    cmdBacktest.Text = "&Back Test";
                    EnableControls(true);

                    if (m_chart != null)
                    {
                        m_chart.Subscribers -= 1;
                    }
                })); //Ensure the chart is new

                while (ret == string.Empty)
                {
                    Application.DoEvents();
                }
            }
            catch (Exception ex) { }
            return(ret);
        }
Exemple #12
0
        //Runs the backtest and displays the chart with buy/sell/exit icons.
        private string RunBacktest()
        {
            string ret = string.Empty;

            _oScript.ClearRecords();
            _oBacktest.ClearRecords();

            if (!VerifyForm())
            {
                return(string.Empty);
            }
            if (!TestScripts())
            {
                return(string.Empty);
            }
            if (_mCtlData == null)
            {
                return(string.Empty);
            }

            cmdBacktest.Text             = "&Stop Backtest";
            cmdBacktest.Border.BaseColor = Color.Red;
            EnableControls(false);
            cmdBacktest.Border.Update();

            Periodicity periodicity;

            switch (cboPeriodicity.Text)
            {
            case "Day":
                periodicity = Periodicity.Daily;
                break;

            case "Hour":
                periodicity = Periodicity.Hourly;
                break;

            case "Minute":
                periodicity = Periodicity.Minutely;
                break;

            case "Week":
                periodicity = Periodicity.Weekly;
                break;

            case "Month":
                periodicity = Periodicity.Month;
                break;

            case "Year":
                periodicity = Periodicity.Year;
                break;

            default:
                periodicity = Periodicity.Minutely;
                break;
            }

            cmdBacktest.Enabled = false;

            //Get the data selection
            ChartSelection selection = new ChartSelection
            {
                Periodicity = periodicity,
                Symbol      = txtSymbol.Text,
                Interval    = Convert.ToInt32(txtInterval.Text),
                Bars        = Convert.ToInt32(txtBars.Text),
                Source      = "PLENA"
            };

            _ctlPainelChart = _mCtlData.GetCtlPainelChart(selection, true); //Ensure the chart is new

            if (_ctlPainelChart == null)
            {
                goto Quit;
            }

            DataManager.BarData[] bars = _ctlPainelChart.GetDataFromChart();

            if (bars.Length < 1)
            {
                goto Quit;
            }

            _ctlPainelChart.Subscribers    += 1;
            _ctlPainelChart.RealTimeUpdates = false;

            //Get historic data
            cmdBacktest.Enabled = true;

            if (bars.Length < 3)
            {
                goto Quit; //Bad request
            }
            //Insert the data into all four instances of TradeScript
            _oScript.ClearRecords();
            _oBacktest.ClearRecords();

            DateTime td;
            double   jdate;

            for (int n = 1; n < bars.Length - 1; n++)
            {
                td    = bars[n].TradeDate;
                jdate = _oScript.ToJulianDate(td.Year, td.Month, td.Day, td.Hour, td.Minute, td.Second, 0);
                _oScript.AppendRecord(jdate, bars[n].OpenPrice, bars[n].HighPrice,
                                      bars[n].LowPrice, bars[n].ClosePrice, (int)bars[n].Volume);
                _oBacktest.AppendRecord(jdate, bars[n].OpenPrice, bars[n].HighPrice,
                                        bars[n].LowPrice, bars[n].ClosePrice, (int)bars[n].Volume);
            }

            //TODO
            ret = _oBacktest.Backtest(txtBuyScript.Text, txtSellScript.Text, txtExitLongScript.Text, txtExitShortScript.Text, 0.001);

            if (string.IsNullOrEmpty(ret))
            {
                goto Quit;
            }

            string output =
                _oScript.GetScriptOutput(txtBuyScript.Text + " AND \r\n" + txtSellScript.Text + " AND \r\n" + txtExitLongScript.Text +
                                         " AND \r\n" + txtExitShortScript.Text);

            if (string.IsNullOrEmpty(output))
            {
                goto Quit;
            }

            int row;

            string[] cols;
            int      col;

            string[] rows   = output.Split(new[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
            string[] header = SplitHeader(rows[0]);

            //StockChartX
            AxSTOCKCHARTXLib.AxStockChartX StockChartX1 = _ctlPainelChart.StockChartX1;
            StockChartX1.RemoveAllSeries();

            string symbol = selection.Symbol;

            StockChartX1.Symbol = symbol;


            StockChartX1.AddChartPanel();
            StockChartX1.AddSeries(symbol + ".open", STOCKCHARTXLib.SeriesType.stCandleChart, 0);
            StockChartX1.AddSeries(symbol + ".high", STOCKCHARTXLib.SeriesType.stCandleChart, 0);
            StockChartX1.AddSeries(symbol + ".low", STOCKCHARTXLib.SeriesType.stCandleChart, 0);
            StockChartX1.AddSeries(symbol + ".close", STOCKCHARTXLib.SeriesType.stCandleChart, 0);
            StockChartX1.set_SeriesColor(symbol + ".close", ColorTranslator.ToOle(Color.Black));

            bool hasVolume = bars[0].Volume != -987654321;

            if (hasVolume)
            {
                StockChartX1.AddChartPanel();
                StockChartX1.AddSeries(symbol + ".volume", STOCKCHARTXLib.SeriesType.stVolumeChart, 1);
                StockChartX1.set_SeriesColor(symbol + ".volume", ColorTranslator.ToOle(Color.Blue));
                StockChartX1.set_SeriesWeight(symbol + ".volume", 3);
                StockChartX1.VolumePostfixLetter = "M"; //Google trades in millions
            }

            for (col = 6; col < header.Length; col++)
            {
                int panel = StockChartX1.AddChartPanel();
                StockChartX1.AddSeries(header[col], STOCKCHARTXLib.SeriesType.stLineChart, panel);
                Color color;

                switch (col)
                {
                case 6:
                    color = Color.Blue;
                    break;

                case 7:
                    color = Color.Red;
                    break;

                case 8:
                    color = Color.Green;
                    break;

                case 9:
                    color = Color.Orange;
                    break;

                case 10:
                    color = Color.Purple;
                    break;

                default:
                    color = Color.Blue;
                    break;
                }

                StockChartX1.set_SeriesColor(header[col], ColorTranslator.ToOle(color));
            }

            for (row = 1; row < rows.Length; row++)
            {
                cols  = rows[row].Split(',');
                jdate = GetJDate(cols[0]);
                StockChartX1.AppendValue(symbol + ".open", jdate, Convert.ToDouble(cols[1], _ciEnUs));
                StockChartX1.AppendValue(symbol + ".high", jdate, Convert.ToDouble(cols[2], _ciEnUs));
                StockChartX1.AppendValue(symbol + ".low", jdate, Convert.ToDouble(cols[3], _ciEnUs));
                StockChartX1.AppendValue(symbol + ".close", jdate, Convert.ToDouble(cols[4], _ciEnUs));

                if (hasVolume)
                {
                    StockChartX1.AppendValue(symbol + ".volume", jdate, Convert.ToDouble(cols[5], _ciEnUs) / 1000000);
                }

                for (col = 6; col < cols.Length; col++)
                {
                    double value = Convert.ToDouble(cols[col], _ciEnUs);
                    if (value == 0 && row < rows.Length * 0.2)
                    {
                        value = (double)STOCKCHARTXLib.DataType.dtNullValue;
                    }

                    StockChartX1.AppendValue(header[col], jdate, value);
                }
            }

            StockChartX1.Update();

Quit:

            if (_ctlPainelChart != null)
            {
                _ctlPainelChart.Show();
            }

            cmdBacktest.Text             = "&Back Test";
            cmdBacktest.Border.BaseColor = Color.Lime;
            EnableControls(true);
            cmdBacktest.Border.Update();

            if (_ctlPainelChart != null)
            {
                _ctlPainelChart.Subscribers -= 1;
            }

            return(ret);
        }
Exemple #13
0
 public void InsertToList(CtlPainelChart chart)
 {
     Members.Add(chart);
 }
Exemple #14
0
        //Starts alerts
        public bool StartAlerts()
        {
            Periodicity periodicity;

            M4Core.Entities.ChartSelection selection = new M4Core.Entities.ChartSelection();
            if (!VerifyForm())
            {
                return(false);
            }
            if (!TestScripts())
            {
                return(false);
            }
            if (m_ctlData == null)
            {
                return(false);
            }

            cmdEnable.Text = "&Disable Alerts";
            EnableControls(false);

            switch (cboPeriodicity.Text)
            {
            case "Minute":
                periodicity = Periodicity.Minutely;
                break;

            case "Hour":
                periodicity = Periodicity.Hourly;
                break;

            case "Day":
                periodicity = Periodicity.Daily;
                break;

            case "Week":
                periodicity = Periodicity.Weekly;
                break;

            default:
                periodicity = Periodicity.Minutely;
                break;
            }
            cmdEnable.Enabled     = false;
            selection.Periodicity = (M4Core.Entities.Periodicity)periodicity;
            selection.Symbol      = txtSymbol.Text;
            try
            {
                selection.Interval = (int)Math.Round(Convert.ToDouble(txtInterval.Text));
            }
            catch { }
            try{
                selection.Bars = (int)Math.Round(Convert.ToDouble(txtBars.Text));
            }
            catch { }

            m_ctlData.LoadRealTimeCtlPainelChartAsync2(selection, new Action <CtlPainelChart>(chart => { m_chart = chart; }));
            if (m_chart == null)
            {
                return(false);           //Failed to get the chart
            }
            DataManager.BarData[] bars = m_chart.GetDataFromChart();
            if (bars.Length < 1)
            {
                return(false);
            }

            m_chart.Subscribers++; //Increment (deincremented in frmMain UI unload)

            cmdEnable.Enabled = true;

            //Get historic data and subscribe to realtime updates
            if (bars.Length < 3)
            {
                return(false);           //Bad request
            }
            //Insert the data into all four instances of TradeScript
            oBuyAlert.AlertScript       = "";
            oSellAlert.AlertScript      = "";
            oExitLongAlert.AlertScript  = "";
            oExitShortAlert.AlertScript = "";
            oBuyAlert.ClearRecords();
            oSellAlert.ClearRecords();
            oExitLongAlert.ClearRecords();
            oExitShortAlert.ClearRecords();
            for (int n = 0; n <= bars.Length - 1; n++)
            {
                DateTime td    = bars[n].TradeDate;
                double   jdate = oBuyAlert.ToJulianDate(td.Year, td.Month, td.Day, td.Hour, td.Minute, td.Second, 0);
                oBuyAlert.AppendHistoryRecord(jdate, bars[n].OpenPrice, bars[n].HighPrice, bars[n].LowPrice, bars[n].ClosePrice,
                                              (int)Math.Round(bars[n].Volume));
                oSellAlert.AppendHistoryRecord(jdate, bars[n].OpenPrice, bars[n].HighPrice, bars[n].LowPrice, bars[n].ClosePrice,
                                               (int)Math.Round(bars[n].Volume));
                oExitLongAlert.AppendHistoryRecord(jdate, bars[n].OpenPrice, bars[n].HighPrice, bars[n].LowPrice,
                                                   bars[n].ClosePrice, (int)Math.Round(bars[n].Volume));
                oExitShortAlert.AppendHistoryRecord(jdate, bars[n].OpenPrice, bars[n].HighPrice, bars[n].LowPrice,
                                                    bars[n].ClosePrice, (int)Math.Round(bars[n].Volume));
            }

            //Now that the history has been added, turn the scripts on
            oBuyAlert.AlertName         = "Buy Script";
            oBuyAlert.AlertScript       = txtBuyScript.Text;
            oSellAlert.AlertName        = "Sell Script";
            oSellAlert.AlertScript      = txtSellScript.Text;
            oExitLongAlert.AlertName    = "Exit Long Script";
            oExitLongAlert.AlertScript  = txtExitLongScript.Text;
            oExitShortAlert.AlertName   = "Exit Short Script";
            oExitShortAlert.AlertScript = txtExitShortScript.Text;

            //Start the data poll timer
            tmrUpdate.Enabled = true;

            return(true);
        }