OnRender()
<< Click to Display Table of Contents >> OnRender() |
Used to render custom drawing to a chart from various chart objects, such as an Indicator, DrawingTool or Strategy.
Notes: 1.This method uses the 3rd party SharpDX library to render custom Direct2D Text and Shapes. For a walk through for using the SharpDX, please see the educational resource Using SharpDX for Custom Chart Rendering 2.The OnRender() method frequently runs once the State has reached State.Realtime in response to market data updates or a user interacting with the chart (e.g., clicking, resizing, rescaling, etc.) 3.For performance optimizations, the timing of the calls to OnRender() are buffered to at least 250ms, and re-renders once internal logic determines that values may be out-of-date. See also ForceRefresh() for more details 4.When using the Strategy Analyzer, OnRender() does NOT call until you switch to the "Chart" display and renders from State.Terminated. As a result, this method should NOT be relied on for historical Strategy backtesting logic and should ONLY be used for rendering purposes 5.Unlike market data events and strategy order related events, there is NO guarantee that the barsAgo indexer used for Series<T> objects are in sync with the current bars in progress. As a result, you should favor using an absolute index method to look up values (e.g., <series>.GetValueAt(), Bars.GetOpen(), etc) 6.While OnRender() is an excellent means for customizing and enhancing indicators and strategies, its application can easily be abused, resulting in unforeseen performance issues which you may not catch until the right conditions (e.g., in the hands of your users during an FOMC event) 7.Please limit any calculations or algorithms you may be tempted run in OnRender() simply to rendering. You should always favor precomputed values and store them for rendering later as the preferred approach to working with the OnRender() method (e.g., reusing brushes, passing values from OnBarUpdate(), etc.). See also OnRenderTargetChanged() method for more information on reusing Brushes 8.If you are using this method as an opportunity to "hook" onto a user related event, such as when a user selects a 3rd party control, you should alternatively consider using the events of that control independent of official NinjaScript events. See also TriggerCustomEvent() |
This method does not return a value
protected override void OnRender(ChartControl chartControl, ChartScale chartScale)
{
}
Warning: Each DirectX render target requires its own brushes. You must create a brushes directly in OnRender() or using OnRenderTargetChanged(). If you do not you will receive an error at run time similar to:
Please see OnRenderTargetChanged() for examples of a brush that needs to be recalculated, or the example below of recreating a static brush. |
chartControl |
A ChartControl object (the chart's bar-related properties and x-axis) |
chartScale |
A ChartScale object (the chart's y-axis) |
Tips: •Please see the help guide topic on Working with Brushes for general information on using brushes and advanced brush concepts •If you are using standard Plots along with custom rendering from an indicator or strategy, you will need to ensure to call the base.OnRender() method for those plots to display. |
Using a static SharpDX Brush to render a rectangle on the chart panel |
---|
protected override void OnRender(ChartControl chartControl, ChartScale chartScale) |
Calling the base.OnRender() method to ensure Plots are rendered along with custom render logic |
---|
protected override void OnRender(ChartControl chartControl, ChartScale chartScale) |
Using multiple SharpDX objects to override the default plot appearance |
---|
protected override void OnRender(ChartControl chartControl, ChartScale chartScale) |