How To Synchronize clickable Object on All Open Chart

To add comments, please log in or register
rajtradingfx
37
rajtradingfx  

Hello All,

This code will help you to "Press" or "Un-Press"the objects button on all "openchart", I personally feel there is no much article on this topic. Hope you will like this.


//+------------------------------------------------------------------+
//|                                                         Test.mq5 |
//|                        Copyright 2018, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2018, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property indicator_chart_window


void OnChartEvent(const int id, // Event ID
                  const long& lparam, // Parameter of type long event
                  const double& dparam, // Parameter of type double event
                  const string& sparam) // Object button name
       
       
        { if(id==CHARTEVENT_OBJECT_CLICK && sparam=="Sychro"){ BroadcastEvent(lparam,dparam,"Sychro");} }   // BroadcastEvent function call here



//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//---
   
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+



//+------------------------------------------------------------------+
//| sends broadcast event to all open charts                         |
//+------------------------------------------------------------------+
void BroadcastEvent(long lparam, double  dparam, string sparam)              //BroadcastEvent function
  {
   int eventID =CHARTEVENT_OBJECT_CLICK;
   long currChart=ChartFirst();
   
   
   for( int i=0; i<100; i+=2)                 // We have certainly no more than CHARTS_MAX open charts
     {
      ChartSetInteger(currChart,CHART_BRING_TO_TOP,ChartWindowFind());
      EventChartCustom(currChart,eventID,lparam,dparam,sparam);
      ObjectSetInteger (currChart , sparam , OBJPROP_STATE , true );
      currChart=ChartNext(currChart); // We have received a new chart from the previous
      if(currChart==-1) break;        // Reached the end of the charts list
     }
     
   }
Discover new MetaTrader 5 opportunities with MQL5 community and services
Discover new MetaTrader 5 opportunities with MQL5 community and services
  • www.mql5.com
Ask questions on technical analysis, discuss trading systems and improve your MQL5 programming skills to develop your own trading strategies. Communicate and share your experience with traders from anywhere in the world, answer questions and help beginners — MQL5.community is developing along with you. "Hedging" in Forex trading -Why do it...
To add comments, please log in or register