problem with ChartIndicatorAdd

 
//+------------------------------------------------------------------+
//|                                                       TEST11.mq5 |

#property version   "1.00"
#property indicator_chart_window
input bool doit = false;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
  
  if(doit)
  {
   for(int i = 0;i<SymbolsTotal(true);i++)
   {
      string ss = SymbolName(i,true);
      long cid = 0;
      cid = ChartOpen(ss,PERIOD_CURRENT);
      int indh = 0;
      indh = iCustom(ss,PERIOD_CURRENT,"TEST11");
      ChartIndicatorAdd(cid,0,indh);
   
   }
  }
//--- indicator buffers mapping
   
   ObjectCreate(ChartID(),"Obj_"+Symbol(),OBJ_VLINE,0,TimeCurrent(),0);
   
//---
   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);
  }


Hi every one. please help me with this surprising indicator.


this is a simple indicator with one input parameter.

if you add it to chart it draw a vertical line on last bar and set name equal to symbol name.




there is a Boolean parameter that when i set to true i want it open all symbols in market watch and by using iCustom() tries to add new example of itself as indicator to new opened chart.

it open all charts in market watch and even add indicator to them( you can see it in indicator list)  BUT   the problem is that new opened chart dont show any thing. there is noting in objectlist of new opened chart.


Now, lets talk about surprising point 

whisper magic words for 3 times.... boo0000000om

All objects draw on main chart





could any body explain how is this possible????

am i wrong or its a bug?

Iman Pakravan
Iman Pakravan
  • www.mql5.com
Published product To download MT5 version click here . One of the most popular tools for technical analyses is Fibonacci alternate time projection. This tools draws ATP using 3 points which is missed in MetaTrader. After downloading, you can find an indicator named "   Fibonacci Time Projection   " in the Indicators list in MetaTrader. Simply...
 

Solution way:

  • Create an indicator that draws a vertical line on the last bar
  • Put this indicator on the chart and save it as a chart template (for example, set the name 'VLine.tpl')
  • Create a chart in a loop (ChartOpen) and add a template (ChartApplyTemplate) to the chart

 

Or the second option - create a custom indicator 'Vertical Line Last Bar'  (it is located in my [data folder]\MQL5\Indicators\MyInd\OBJ_VLINE\Vertical Line Last Bar.mq5 folder). And in the indicator we very carefully create new charts: we MUST get and use the RECEIVED chart ID:

//+------------------------------------------------------------------+
//| 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[])
  {
//--- we work only at the time of the birth of new bar
   datetime time_0=time[rates_total-1];
   if(time_0==m_prev_bars)
      return(rates_total);
   m_prev_bars=time_0;
//---
   long chart_ID=ChartID();
   string charts_symbol=ChartSymbol(chart_ID);
   Print("ChartID: ",chart_ID,", ChartSymbol: ",charts_symbol);
   if(ObjectFind(chart_ID,InpName)<0)
      if(!VLineCreate(chart_ID,InpName))
        {
         m_prev_bars=0;
         return(rates_total);
        }
   VLineMove(chart_ID,InpName,time[rates_total-1]);
//--- return value of prev_calculated for next call
   return(rates_total);
  }
Step on New Rails: Custom Indicators in MQL5
Step on New Rails: Custom Indicators in MQL5
  • www.mql5.com
Finally we've got an opportunity to try the new trade terminal - MetaTrader 5 . No doubt, it is noteworthy and has many new features as compared to its predecessor. The important advantages of this platform among others are: Essentially modified language allowing now to use the object-oriented programming, still allowing to use the rich...
Files:
 
Vladimir Karputov:

Or the second option - create a custom indicator 'Vertical Line Last Bar'  (it is located in my [data folder]\MQL5\Indicators\MyInd\OBJ_VLINE\Vertical Line Last Bar.mq5 folder). And in the indicator we very carefully create new charts: we MUST get and use the RECEIVED chart ID:


thank you for help.

i used the 1st solution. create a template and add it to the chart. it worked . 

Reason: