Using EA_OBJPROP_CHART_ID in MetaTrader 5: A Trader's Guide

Mike 2011.06.14 21:41 15 0 0
Attachments

Are you looking to place chart objects, referred to as OBJ_CHART, onto your trading charts and use them like a regular chart? You're in luck because it's totally doable!

All you need is the handle for the OBJ_CHART object. With the Chart Operations, you can easily add or remove indicators using ChartIndicatorAdd() and ChartIndicatorDelete(), and set the chart's Period and Symbol, among other things.

EA_OBJPROP_CHART_ID

The EA_OBJPROP_CHART_ID Expert Advisor performs several key actions:

  • Adds a PriceChannel indicator, which is included in the standard package of the client terminal (found in terminal_data_folder\MQL5\Indicators\Examples);
  • Creates a subwindow using the Subwindow indicator (just copy Subwindow.mq5 to terminal_data_folder\MQL5\Indicators);
  • Generates an OBJ_CHART type object in the subwindow with the chart symbol, specifically for D1 and H4 timeframes;
  • For each OBJ_CHART object, it adds a Price_Channel indicator with default settings and changes the background color.

When you decide to remove it from the chart, it will delete all the indicators it created:

//+------------------------------------------------------------------+
//| Expert deinitialization function                                     |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//--- delete objects
//  ObjectDelete(0,D1);
//  ObjectDelete(0,H4);
//--- delete subwindow
   ChartIndicatorDelete(0,subwindow_ID,"Subwindow");
//--- delete PriceChannel indicator from the main window
//--- its short name with default parameters is "Price Channel(22)"
   ChartIndicatorDelete(0,0,"Price Channel(22)");
  }
List
Comments 0