C # How to Use NPlot to draw a futures stock K-line chart ?,

Source: Internet
Author: User

C # How to Use NPlot to draw a futures stock K-line chart ?,

[Introduction]

As a professional procedural trader, programming is the basic skill of a programmer. This article is a part of the K-line plot of the author in a futures CTP project. It is written in the chart design in MT4 of the trial class, I checked the related materials when writing the drawing. I still feel that the NPlot chart control is better. The features are: free, can be used in winform programs, and the speed is relatively fast, the chart data can be dynamically displayed in real time. The topic is displayed below.

[Content]

I. Introduction to NPlot controls:

Chart controls are always hard to find, especially free and powerful. NPlot is very rare. net platform chart controls, can do a variety of graphs, bar charts, pie charts, scatter charts, stock charts, and so on, and it is free and open source, it is also very consistent with the programmer's habits. The only drawback is that documents are hard to find and read. By reading its documents and analyzing the source code of the sample program, the basic concepts of NPlot are as follows:

 

NPlot namespaces include NPlot and NPlot. bitmap, NPlot. web, NPlot. web. design, NPlot. windows, etc. Among them, the core class that manages various charts belongs to the NPlot namespace, NPlot. bitmap manages Bitmap, NPlot. web, NPlot. web. design and NPlot. windows can be considered as a NPlot chart container on Web Form and Windows Form (PlotSurface2D ). These containers can be dragged to Form or in other containers.

 

To apply the NPlot control in an application, add the downloaded NPlot. dll to the. Net project. And add it to the Toolbox tray. Add method: Right-click the toolbox and select "select item". The "select toolbox item" dialog box appears. net Frameworks component, select Browse, and find NPlot. dll is added to the toolbox. The NPlot control appears in the toolbox. When designing the application interface, you can drag it into the application interface. The system automatically creates a PlotSurface2D object in the code.

 

The PlotSurface2D object is the container of the NPlot chart. All chart charts, coordinates, and titles (all inherit fromIDrawable Interface) And other information can be added to PlotSurface2D. PlotSurface2D has a very important method: Add. You can Add PlotSurface2D objects to various chart charts, coordinates, and titles by adding them.

The following is the basic code for drawing a candle chart:

1 / Various drawings ////////
 2 private void plot ()
 3 {
 4 this.myPlot.Clear ();
 7 //////// Grid ////////////
 8 Grid mygrid = new Grid ();
 9 mygrid.HorizontalGridType = Grid.GridType.Fine;
10 mygrid.VerticalGridType = Grid.GridType.Fine;
11 this.myPlot.Add (mygrid);
1213 /////// horizontal line ///////////
14 HorizontalLine line = new HorizontalLine (10);
15 line.LengthScale = 2.89f;
16 //line.OrdinateValue = 2;
17 this.myPlot.Add (line, 10);
18 /////// vertical line /////////////
19 VerticalLine line2 = new VerticalLine (10);
20 line2.LengthScale = 0.89f;
21 this.myPlot.Add (line2);
twenty two 
twenty three 
24 /////// candle chart /////////////
25 int [] opens = {1, 2, 1, 2, 1, 3};
26 double [] closes = {2, 2, 2, 1, 2, 1};
27 float [] lows = {1, 1, 1, 1, 1, 1};
28 System.Int64 [] highs = {3, 2, 3, 3, 3, 4};
29 int [] times = {0, 1, 2, 3, 4, 5};
30 CandlePlot cp = new CandlePlot ();
31 cp.CloseData = closes;
32 cp.OpenData = opens;
33 cp.LowData = lows;
34 cp.HighData = highs;
35 cp.AbscissaData = times;
36 this.myPlot.Add (cp);
37
            this.myPlot.Refresh ();
62} 


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.