×

Sign up and get MultiCharts free

Use its powerful simulation mode with data included out of the box. Just fill out the form and start honing your trading skills with a few clicks.

Changes - MultiCharts

Changes

Jump to navigation Jump to search

4.7.1 Chart Custom Draw

4,458 bytes added, 15:26, 3 May 2013
Created page with "Every study can plot a custom drawing in a chart window. This is possible using the '''IChartCustomDrawRegistrator''' interface that is available through the '''ChartCustomDra..."
Every study can plot a custom drawing in a chart window. This is possible using the '''IChartCustomDrawRegistrator''' interface that is available through the '''ChartCustomDraw''' property.


This interface contains methods for registering/unregistering a custom drawer, the initiation of the drawing of the entire chart window and a property for accessing the data that is required during the drawing. It is possible to register/unregister the custom drawer from any thread. Re-plotting initiation is also available from any thread and will be started asynchronously in the main thread, i.e. not as soon the method is called.


Custom drawer is an object that implements the '''IChartCustomDrawer''' interface with the only one '''void Draw(DrawContext context, EDrawPhases phase)''' method. This method will be called several times within one process of chart window plotting, once per each phase of plotting. The plotting process is performed on a phased basis:

# background is filled,
# grid is plotted,
# background figures are plotted (rectangles, ellipses, etc)
# bar series is plotted, the chart for an instrument itself
# foreground figures are plotted (trend lines, Fibonacci levels, etc)


The current phase of plotting can be checked in the ''{{color|blue|phase}}'' argument. It allows plotting at the required moment, for example, either above or below the bar series, at the background, or in front of all the objects of the chart.


The first argument of the '''IChartCustomDrawer.Draw()''' method context is a wrapper class that contains all the necessary data and means for the plotting, they are:

* {{color|blue|public readonly Color BackGround;}} - chart background color.

* {{color|blue|public RectangleF DirtyRect;}} - Custom drawer can require to re-plot a bigger space than is currently being plotted and can notify the caller about that by setting the required space in this property. If on exiting from the '''IChartCustomDrawer.Draw()''' method this space is bigger than the one set in {{color|blue|DrawRect}}, then the caller will initiate the plotting procedure on all phases one more time. This double plotting allows the receipt all the required information about the objects that need to be plotted in a bigger space, thus it is being re-plotted without any visual artifacts (flashing).

* {{color|blue|public readonly RectangleF DrawRect;}} - contains the space that is required to be re-plotted. To speed up the plotting process, the whole chart window does not need to be re-plotted, only the space where the indicated objects were changed. For example, the last bar has been updated in real time, so in this case only a little space containing this bar should be re-plotted and the '''DrawRect''' property will contain this space.

* {{color|blue|public readonly IDrawDataEnviroment Environment;}} - this interface gives access to the data on the charts bars and status line. Also it contains the methods for conversion of the coordinates from one type to another. For example:
# from bar number/index to screen coordinate X
# from the point, date-time, price to screen coordinate point

* {{color|blue|public readonly bool FinalDraw;}} - returns TRUE when the '''IChartCustomDrawer.Draw()''' method will not be called within the current plotting and phase, regardless of the values of the {{color|blue|DirtyRect}} and {{color|blue|ReDraw}} fields. If nothing is currently being plotted the custom drawing will not be indicated on the chart (at least for 1 fps).

* {{color|blue|public readonly RectangleF FullRect;}} - contains the whole chart space where the plotting is possible. Basically, this is the whole internal space of a chart window.

* {{color|blue|public readonly Graphics graphics;}} -plotting is performed by means of GDI/GDI+ with {{color|blue|System.Drawing.Graphics. graphics}} class, this is a reference to the object of this type. All the plots are created by calling methods of this class. More information about methods and properties of System.Drawing.Graphics class can be found on [http://msdn.microsoft.com/en-gb/library/system.drawing.graphics%28v=vs.90%29.aspx msdn].

* {{color|blue|public bool ReDraw;}} -should be set as TRUE if the whole chart window should be re-plotted.



<div style="background-color: #E3FBE5;">NOTE: A pre-built indicator '''_Market_Depth_on_Chart_2_''' uses custom drawings and can be used as an example.</div>


[[Category:.NET Programming Giude]]

Navigation menu