- Object types and features of specifying their coordinates
- Time and price bound objects
- Objects bound to screen coordinates
- Creating objects
- Deleting objects
- Finding objects
- Overview of object property access functions
- Main object properties
- Price and time coordinates
- Anchor window corner and screen coordinates
- Defining anchor point on the object
- Managing the object state
- Priority of objects (Z-Order)
- Object display settings: color, style, and frame
- Font settings
- Rotating text at an arbitrary angle
- Determining object width and height
- Visibility of objects in the context of timeframes
- Assigning a character code to a label
- Ray properties for objects with straight lines
- Managing object pressed state
- Adjusting images in bitmap objects
- Cropping (outputting part) of an image
- Input field properties: alignment and read-only
- Standard deviation channel width
- Setting levels in level objects
- Additional properties of Gann, Fibonacci, and Elliot objects
- Chart object
- Moving objects
- Getting time or price at the specified line points
Chart object
The chart object OBJ_CHART allows you to create thumbnails of other charts inside the chart for other instruments and timeframes. Chart objects are included in the general chart list, which we obtained programmatically using the ChartFirst and ChartNext functions. As mentioned in the section on Checking the main window status, the special chart property CHART_IS_OBJECT allows you to find out by identifier whether it is a full-fledged window or a chart object. In the latter case, calling ChartGetInteger(id, CHART_IS_OBJECT) will return true.
The chart object has a set of properties specific only to it.
Identifier |
Description |
Type |
---|---|---|
OBJPROP_CHART_ID |
Chart ID (r/o) |
long |
OBJPROP_PERIOD |
Chart Period |
ENUM_TIMEFRAMES |
OBJPROP_DATE_SCALE |
Show the time scale |
bool |
OBJPROP_PRICE_SCALE |
Show the price scale |
bool |
OBJPROP_CHART_SCALE |
Scale (value in the range 0 - 5) |
int |
OBJPROP_SYMBOL |
Symbol |
string |
The identifier obtained through the OBJPROP_CHART_ID property allows you to manage the object like a regular chart using the functions from the chapter Working with charts. However, there are some limitations:
- The object cannot be closed with ChartClose
- It is not possible to change the symbol/period in the object using the CartSetSymbolPeriod function
- Properties CHART_SCALE, CHART_BRING_TO_TOP,CHART_SHOW_DATE_SCALE and CHART_SHOW_PRICE_SCALE are not modified in the object.
By default, all properties (except OBJPROP_CHART_ID) are equal to the corresponding properties of the current window.
The demonstration of chart objects is implemented as a bufferless indicator ObjectChart.mq5. It creates a subwindow with two chart objects for the same symbol as the current chart but with adjacent timeframes above and below the current one.
Objects snap to the upper right corner of the subwindow and have the same predefined sizes:
#define SUBCHART_HEIGHT 150
|
Of course, the height of the subwindow must match the height of the objects, until we can respond adaptively to resize events.
#property indicator_separate_window
|
One mini-chart is configured in the SetupSubChart function, which takes the number of the object, its dimensions, and the required timeframe as inputs. The result of SetupSubChart is the identifier of the chart object, which we just output into the log for reference.
void OnInit()
|
Macros PeriodUp and PeriodDown use the helper function PeriodRelative.
#define PeriodUp(P) PeriodRelative(P, +1)
|
Here is the main working function SetupSubChart.
long SetupSubChart(const int n, const int dx, const int dy,
|
For a chart object, the anchor point is always fixed in the upper left corner of the object, so when anchoring to the right corner of the window, you need to add the width of the object (this is done by +1 in the expression(n+1)*dx for OBJPROP_XDISTANCE).
The following screenshot shows the result of the indicator on the XAUUSD,H1 chart.
Two chart objects in the indicator subwindow
As we can see, the mini-charts display the M30 and H2 timeframes.
It is important to note that you can add indicators to chart objects and apply tpl templates, including those with Expert Advisors. However, you cannot create objects inside chart objects.
When the chart object is hidden due to disabled visualization on the current timeframe or on all timeframes, the CHART_WINDOW_IS_VISIBLE property for the internal chart still returns true.