What is the terminal up to between OnInit and OnCalculate?

 

I've got an indicator that's very similar to other indicators I've written, all of them running super-simple algorithms (90% of the code or more is just about getting the data in) that calculate the slope of another indicator's values between two bars, a simple Y2 - Y1 for a user-selectable period.

I got the first one working and then just cloned it for each of the indicators I'm interested in. So, the buffer setup and most of the code is almost exactly the same in one as it is in the others. All that's really different is where the data comes from.

I've got some indicators with up to 20 output buffers, (not among this cloned set,) most of them for data readouts for the Data Window, but a few line plots, too. I mention that because I could understand the terminal taking extra time to set up a slew of plot or calculation buffers, but even then, I haven't had this problem before. 

I put a couple of print statements in so you can see.

2024.05.22 14:22:30.931 Slope of PlateauFinder MJM (USDJPY,M12) ChartID<133608793496763499>: [Slope of PlateauFinder MJM.mq5 [OnInit] LINE 182> MS: 742 - END OF ONINIT: 
2024.05.22 14:22:43.859 Slope of PlateauFinder MJM (USDJPY,M12) 
2024.05.22 14:22:43.859 Slope of PlateauFinder MJM (USDJPY,M12) ChartID<133608793496763499>: [Slope of PlateauFinder MJM.mq5 [OnCalculate] LINE 215> MS: 12928772 - TOP OF ONCALCULATE: 


Here's the code that prints that. I'm using this at the end of OnInit:

Print("\nChartID<",ChartID(),">: ["+__FILE__+" ["+__FUNCTION__+"] LINE "+(string)__LINE__,"> MS: "+(string)GetMicrosecondCount()," - END OF ONINIT: "
                );

   return(INIT_SUCCEEDED);   
}


And here's what's at the top of OnCalculate:

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[])
{
  
Print("\nChartID<",ChartID(),">: ["+__FILE__+" ["+__FUNCTION__+"] LINE "+(string)__LINE__,"> MS: "+(string)GetMicrosecondCount()," - TOP OF ONCALCULATE: "
                );

Even if it had to set up 100 buffers, this amount of time would still be unreasonable. Something else must be making my poor terminal spin in circles...

Does anyone have a clue what the terminal is doing for 12.93 seconds of no apparent activity? I'm afraid I can't debug whatever is happening in that particular black box...

I figured I should also share the code that sets up what few buffers there are in this case:

//--- indicator buffers mapping

ENUM_DRAW_TYPE eDrawSlpeLine                       = (Ib_Show_SlpeLine == true)        ? DRAW_LINE : DRAW_NONE;
ENUM_DRAW_TYPE eDrawSlpeOSlpeLine                  = (Ib_Show_SlpeOSlpeLine == true)   ? DRAW_LINE : DRAW_NONE;

   SetIndexBuffer          (0,dbSlpe,INDICATOR_DATA);
      PlotIndexSetInteger  (0,PLOT_DRAW_TYPE,eDrawSlpeLine);
      PlotIndexSetInteger  (0,PLOT_SHOW_DATA,true);
      PlotIndexSetInteger  (0,PLOT_LINE_COLOR,IiSlpeCLR);
      PlotIndexSetInteger  (0,PLOT_LINE_WIDTH,IiSlpeWdth);
      PlotIndexSetString   (0,PLOT_LABEL,sMyShrtName);
   
   SetIndexBuffer          (1,dbSlpeOSlpe,INDICATOR_DATA);
      PlotIndexSetInteger  (1,PLOT_DRAW_TYPE,eDrawSlpeOSlpeLine);
      PlotIndexSetInteger  (1,PLOT_SHOW_DATA,true);
      PlotIndexSetInteger  (1,PLOT_LINE_COLOR,IiSlpeOSlpeCLR);
      PlotIndexSetInteger  (1,PLOT_LINE_WIDTH,IiSlpeOSlpeWdth);
      PlotIndexSetString   (1,PLOT_LABEL,"Slope("+IntegerToString(IiSlpeOSlpePrd)+") of "+sMyShrtName);
   
   SetIndexBuffer          (2,dbIndy_BFR_1,INDICATOR_DATA);
      PlotIndexSetInteger  (2,PLOT_DRAW_TYPE,DRAW_NONE);
      PlotIndexSetInteger  (2,PLOT_SHOW_DATA,true);
      PlotIndexSetString   (2,PLOT_LABEL,sIndyShrtName+" HI/CLS data");
   
   SetIndexBuffer          (3,dbIndy_BFR_2,INDICATOR_DATA);
      PlotIndexSetInteger  (3,PLOT_DRAW_TYPE,DRAW_NONE);
      PlotIndexSetInteger  (3,PLOT_SHOW_DATA,true);
      PlotIndexSetString   (3,PLOT_LABEL,sIndyShrtName+" LO/OPN data");
   
   SetIndexBuffer          (4,dbDDT,INDICATOR_DATA);
      PlotIndexSetInteger  (4,PLOT_DRAW_TYPE,DRAW_NONE);
      PlotIndexSetInteger  (4,PLOT_SHOW_DATA,true);
      PlotIndexSetString   (4,PLOT_LABEL,"Date (YYYYMMDDHHMM)");
 

So weird.

So, here's where I'm at on this one. 

The indicator that's getting stuck calls a custom indicator to plot the slope of its results. That indicator works fine when run standalone. I'd made some changes to it recently, so I wondered if somehow they were messing things up and commented them out. They represented an enhancement but weren't crucial to the basic point of the indicator.

Sure enough, when I ran the slope indicator that was getting stuck, it now runs fine.

So, somehow, code that works fine in the custom indicator when run standalone is messing up the terminal somehow when called as an iCustom indicator.

I have no idea why that should be, but since that enhancement isn't crucial, I'll come back to this problem later.

 

It is just a guess and cannot be sure it applies to your conditions:

Sometimes loading data from another chart(in your case a custom indicator) takes long. Even when you open a new chart in your meta-trader it takes quite a few seconds to load.

 
Yashar Seyyedin #:

It is just a guess and cannot be sure it applies to your conditions:

Sometimes loading data from another chart(in your case a custom indicator) takes long. Even when you open a new chart in your meta-trader it takes quite a few seconds to load.

Yeah, that's what I thought, too. It's hard to know what to fix if you don't know what's going on. Something I did along the way fixed it, though, because it's not happening anymore. Life's little mysteries...