示例#1
0
        private void movePlot(XYPlot plotToMove, XYPlot plotMoveTo)
        {
            int indexToMove = -1;
            int indexMoveTo = -1;

            for (int i = 0; i < TotalXYPlots; i++)
            {
                if (XYPlots[i] == plotToMove)
                {
                    indexToMove = i;
                }
                else if (XYPlots[i] == plotMoveTo)
                {
                    indexMoveTo = i;
                }
            }

            if (indexToMove >= 0 && indexMoveTo >= 0 && indexToMove != indexMoveTo)
            {
                XYPlots.RemoveAt(indexToMove);
                XYPlots.Insert(indexMoveTo, plotToMove);
                XYPlotViewStruct s = PlotViewSetting.PlotViewStructList[indexToMove];
                PlotViewSetting.PlotViewStructList.RemoveAt(indexToMove);
                PlotViewSetting.PlotViewStructList.Insert(indexMoveTo, s);
            }

            this.Invalidate();
        }
示例#2
0
        public static void Main(string[] args)
        {
            // Getting the time series
            TimeSeries series = CsvTradesLoader.loadBitstampSeries();
            // Building the trading strategy
            Strategy strategy = MovingMomentumStrategy.buildStrategy(series);

            /// <summary>
            /// Building chart datasets
            /// </summary>
            TimeSeriesCollection dataset = new TimeSeriesCollection();

            dataset.addSeries(buildChartTimeSeries(series, new ClosePriceIndicator(series), "Bitstamp Bitcoin (BTC)"));

            /// <summary>
            /// Creating the chart
            /// </summary>
            JFreeChart chart = ChartFactory.createTimeSeriesChart("Bitstamp BTC", "Date", "Price", dataset, true, true, false);             // generate URLs? -  generate tooltips? -  create legend? -  data -  y-axis label -  x-axis label -  title
            XYPlot     plot  = (XYPlot)chart.Plot;
            DateAxis   axis  = (DateAxis)plot.DomainAxis;

            axis.DateFormatOverride = new SimpleDateFormat("MM-dd HH:mm");

            /// <summary>
            /// Running the strategy and adding the buy and sell signals to plot
            /// </summary>
            addBuySellSignals(series, strategy, plot);

            /// <summary>
            /// Displaying the chart
            /// </summary>
            displayChart(chart);
        }
示例#3
0
        /// <summary>
        /// Create the chart using the data.
        /// </summary>
        private JFreeChart createChart(DefaultTableXYDataset dataset)
        {
            string xlabel = "Surface Area (ACRE)";

            if (__type.Equals("Seepage"))
            {
                xlabel = "Seepage (AF/M)";
            }
            JFreeChart chart = ChartFactory.createXYLineChart("Reservoir Content/" + __type + " Curve", xlabel, "Content (ACFT)", dataset, PlotOrientation.VERTICAL, false, true, false);

            chart.addSubtitle(new TextTitle(__res.getID() + " (" + __res.getName() + ")"));
            //TextTitle source = new TextTitle("Source: rgtTW.res");
            //source.setFont(new Font("SansSerif", Font.PLAIN, 10));
            //source.setPosition(RectangleEdge.BOTTOM);
            //source.setHorizontalAlignment(HorizontalAlignment.RIGHT);
            //chart.addSubtitle(source);

            chart.setBackgroundPaint(Color.WHITE);

            XYPlot plot = (XYPlot)chart.getPlot();

            plot.setBackgroundPaint(Color.white);
            plot.setRangeGridlinePaint(Color.lightGray);

            NumberAxis rangeAxis = (NumberAxis)plot.getRangeAxis();

            rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

            return(chart);
        }
示例#4
0
        private void deletePlotToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Point  location = this.PtMouseStart;
            XYPlot xyPlot   = GetXYPlot(location);

            if (xyPlot != null)
            {
                deletePlot(xyPlot);
            }
        }
示例#5
0
        private void XYPlotCtrl_MouseWheel(object sender, MouseEventArgs e)
        {
            int    delta  = e.Delta;
            Point  pt     = new Point(e.Location.X, e.Location.Y);
            XYPlot xyPlot = GetXYPlot(pt);

            if (xyPlot != null)
            {
                xyPlot.Zoom(delta);
                this.Invalidate();
            }
        }
示例#6
0
        public virtual XYPlot GetXYPlot(Point pt)
        {
            XYPlot xyPlot = null;

            Rectangle rect = new Rectangle(XYPlot1.Location, XYPlot1.Size);

            if (rect.Contains(pt))
            {
                xyPlot = XYPlot1;
            }

            return(xyPlot);
        }
示例#7
0
        public void SetPlotType(PlotType plotType)
        {
            switch (plotType)
            {
            case PlotType.XYPlotTimeDepth:
                XYPlot1 = new XYPlotTimeDepth(null, this, ClientRectangle);
                break;

            default:
                XYPlot1 = new XYPlot(null, this, ClientRectangle);
                break;
            }
        }
示例#8
0
        public static void Main(string[] args)
        {
            /// <summary>
            /// Getting time series
            /// </summary>
            TimeSeries series = CsvTradesLoader.loadBitstampSeries().subseries(0, Period.hours(6));

            /// <summary>
            /// Creating the OHLC dataset
            /// </summary>
            OHLCDataset ohlcDataset = createOHLCDataset(series);

            /// <summary>
            /// Creating the additional dataset
            /// </summary>
            TimeSeriesCollection xyDataset = createAdditionalDataset(series);

            /// <summary>
            /// Creating the chart
            /// </summary>
            JFreeChart chart = ChartFactory.createCandlestickChart("Bitstamp BTC price", "Time", "USD", ohlcDataset, true);
            // Candlestick rendering
            CandlestickRenderer renderer = new CandlestickRenderer();

            renderer.AutoWidthMethod = CandlestickRenderer.WIDTHMETHOD_SMALLEST;
            XYPlot plot = chart.XYPlot;

            plot.Renderer = renderer;
            // Additional dataset
            int index = 1;

            plot.setDataset(index, xyDataset);
            plot.mapDatasetToRangeAxis(index, 0);
            XYLineAndShapeRenderer renderer2 = new XYLineAndShapeRenderer(true, false);

            renderer2.setSeriesPaint(index, Color.blue);
            plot.setRenderer(index, renderer2);
            // Misc
            plot.RangeGridlinePaint = Color.lightGray;
            plot.BackgroundPaint    = Color.white;
            NumberAxis numberAxis = (NumberAxis)plot.RangeAxis;

            numberAxis.AutoRangeIncludesZero = false;
            plot.DatasetRenderingOrder       = DatasetRenderingOrder.FORWARD;

            /// <summary>
            /// Displaying the chart
            /// </summary>
            displayChart(chart);
        }
示例#9
0
        private void toolStripMenuItemPlotProperty_Click(object sender, EventArgs e)
        {
            Point  location = this.PtMouseStart;
            XYPlot xyPlot   = GetXYPlot(location);

            if (xyPlot != null)
            {
                xyPlot.SetPlotTitle();
                XYPlotSettingDlg dlg = new XYPlotSettingDlg(xyPlot.XYPlotSettings, xyPlot);
                dlg.InitialDialog();
                if (dlg.ShowDialog() == DialogResult.OK)
                {
                }
            }
        }
示例#10
0
        public virtual XYPlot GetXYPlot(Point pt)
        {
            XYPlot xyPlot = null;

            foreach (XYPlot plot in XYPlots)
            {
                //if (plot.Visible == true)
                {
                    Rectangle rect = new Rectangle(plot.Location, plot.Size);
                    if (rect.Contains(pt))
                    {
                        xyPlot = plot;
                    }
                }
            }

            return(xyPlot);
        }
示例#11
0
        // private methods
        private XYPlot addPlot(String name)
        {
            XYPlot xyPlot1 = new XYPlot(null, this, ClientRectangle);

            xyPlot1.Name    = newPlotName(name);
            xyPlot1.Visible = true;
            xyPlot1.XYPlotSettings.PlotName = xyPlot1.Name;

            XYPlots.Add(xyPlot1);
            double           width = PlotViewSetting.AverageWidth;
            XYPlotViewStruct s     = new XYPlotViewStruct(xyPlot1.XYPlotSettings, width, xyPlot1.Visible);

            PlotViewSetting.PlotViewStructList.Add(s);
            SubscribePlotEvents(xyPlot1);

            this.Invalidate();

            return(xyPlot1);
        }
示例#12
0
        private void deletePlot(XYPlot xyPlot)
        {
            int index = -1;

            for (int i = 0; i < TotalXYPlots; i++)
            {
                if (XYPlots[i] == xyPlot)
                {
                    index = i;
                    break;
                }
            }

            if (index >= 0)
            {
                XYPlots.RemoveAt(index);
                PlotViewSetting.PlotViewStructList.RemoveAt(index);
            }

            this.Invalidate();
        }
示例#13
0
        protected void OnViewYChanged(object sender, XYPlotEventArgs e)
        {
            XYPlot plot = (XYPlot)sender;

            if (plot == null)
            {
                return;
            }

            double minView = plot.XYPlotSettings.YAxis.ViewMin;
            double maxView = plot.XYPlotSettings.YAxis.ViewMax;

            foreach (XYPlot xyplot in XYPlots)
            {
                if (xyplot.ZoomY == false)
                {
                    continue;
                }
                xyplot.XYPlotSettings.YAxis.ViewMin = minView;
                xyplot.XYPlotSettings.YAxis.ViewMax = maxView;
            }
        }
示例#14
0
        /// <summary>
        /// Runs a strategy over a time series and adds the value markers
        /// corresponding to buy/sell signals to the plot. </summary>
        /// <param name="series"> a time series </param>
        /// <param name="strategy"> a trading strategy </param>
        /// <param name="plot"> the plot </param>
        private static void addBuySellSignals(TimeSeries series, Strategy strategy, XYPlot plot)
        {
            // Running the strategy
            IList <Trade> trades = series.run(strategy).Trades;

            // Adding markers to plot
            foreach (Trade trade in trades)
            {
                // Buy signal
                double buySignalTickTime = (new Minute(series.getTick(trade.Entry.Index).EndTime.toDate())).FirstMillisecond;
                Marker buyMarker         = new ValueMarker(buySignalTickTime);
                buyMarker.Paint = Color.GREEN;
                buyMarker.Label = "B";
                plot.addDomainMarker(buyMarker);
                // Sell signal
                double sellSignalTickTime = (new Minute(series.getTick(trade.Exit.Index).EndTime.toDate())).FirstMillisecond;
                Marker sellMarker         = new ValueMarker(sellSignalTickTime);
                sellMarker.Paint = Color.RED;
                sellMarker.Label = "S";
                plot.addDomainMarker(sellMarker);
            }
        }
示例#15
0
        private void XYPlotCtrl_MouseMove(object sender, MouseEventArgs e)
        {
            Point ptCurrent = e.Location;

            if (ptCurrent == PtMouseStart)
            {
                return;
            }
            //if (Math.Abs(ptCurrent.X - PtMouseStart.X) <= 2 &&
            //    Math.Abs(ptCurrent.Y - PtMouseStart.Y) <= 2) return;

            PlotViewMouseMode mouseMode = MouseMode;

            if (Control.ModifierKeys == Keys.Shift)
            {
                mouseMode = PlotViewMouseMode.Zoom;
            }
            else if (Control.ModifierKeys == Keys.Control)
            {
                mouseMode = PlotViewMouseMode.Pan;
            }

            // Check if the left mouse button is pressed.
            if (e.Button == MouseButtons.Left)
            {
                switch (mouseMode)
                {
                case PlotViewMouseMode.Zoom:
                    // erase previous rectangle
                    DrawReversibleRectangle(PtMouseStart, PtMouseEnd);

                    // draw new rectangle
                    DrawReversibleRectangle(PtMouseStart, ptCurrent);
                    break;

                case PlotViewMouseMode.Pan:
                    // erase previous rectangle
                    //DrawReversibleRectangle(PtMouseStart, PtMouseEnd);
                    DrawReversibleLine(PtMouseStart, PtMouseEnd);

                    // draw new rectangle
                    //DrawReversibleRectangle(PtMouseStart, ptCurrent);
                    DrawReversibleLine(PtMouseStart, ptCurrent);
                    break;

                case PlotViewMouseMode.Select:
                    // erase previous rectangle
                    DrawReversibleRectangle(PtMouseStart, PtMouseEnd);

                    // draw new rectangle
                    DrawReversibleRectangle(PtMouseStart, ptCurrent);
                    break;

                case PlotViewMouseMode.None:
                    XYPlot xyPlot = GetXYPlot(PtMouseStart);
                    if (xyPlot != null)
                    {
                        // erase previous cross lines
                        DrawReversibleCrossLines(PtMouseEnd);

                        // draw new cross lines
                        DrawReversibleCrossLines(ptCurrent);
                    }
                    break;

                default:
                    break;
                }
            }

            PtMouseEnd = ptCurrent;
        }
示例#16
0
        public XYPlotCtrl()
        {
            InitializeComponent();

            XYPlot1 = new XYPlot(null, this, ClientRectangle);
        }
示例#17
0
 // context menu
 private void toolStripMenuItemAddPlot_Click(object sender, EventArgs e)
 {
     XYPlot xyPlot = addPlot("Test");
 }
示例#18
0
        private void XYPlotCtrl_MouseUp(object sender, MouseEventArgs e)
        {
            //using (new WaitCursor())
            {
                PlotViewMouseMode mouseMode = MouseMode;
                if (Control.ModifierKeys == Keys.Shift)
                {
                    mouseMode = PlotViewMouseMode.Zoom;
                }
                else if (Control.ModifierKeys == Keys.Control)
                {
                    mouseMode = PlotViewMouseMode.Pan;
                }

                if (e.Button == MouseButtons.Left)
                {
                    PtMouseEnd = e.Location;

                    XYPlot xyPlot = GetXYPlot(PtMouseStart);
                    if (xyPlot != null)
                    {
                        switch (mouseMode)
                        {
                        case PlotViewMouseMode.Zoom:
                            if (PtMouseStart != Point.Empty)
                            {
                                xyPlot.Zoom(PtMouseStart, PtMouseEnd);
                                DrawReversibleRectangle(PtMouseStart, PtMouseEnd);
                                this.Invalidate();
                            }
                            break;

                        case PlotViewMouseMode.Pan:
                            if (PtMouseStart != Point.Empty)
                            {
                                xyPlot.Pan(PtMouseStart, PtMouseEnd);
                                //DrawReversibleRectangle(PtMouseStart, PtMouseEnd);
                                DrawReversibleLine(PtMouseStart, PtMouseEnd);
                                this.Invalidate();
                            }
                            break;

                        //case PlotViewMouseMode.Select:
                        //    Select(xyPlot, PtMouseStart, PtMouseEnd);
                        //    DrawReversibleRectangle(PtMouseStart, PtMouseEnd);
                        //    this.Invalidate();
                        //    break;

                        case PlotViewMouseMode.None:
                            DrawReversibleCrossLines(PtMouseEnd);
                            break;

                        default:
                            break;
                        }
                    }
                    PtMouseStart = Point.Empty;
                    PtMouseEnd   = Point.Empty;
                }
            }
        }
示例#19
0
 // plot related events, used to change view limits together
 protected void SubscribePlotEvents(XYPlot plot)
 {
     plot.ViewXChanged += new XYPlotEvent(OnViewXChanged);
     plot.ViewYChanged += new XYPlotEvent(OnViewYChanged);
 }