Show progress of indicator

 

Hi!

I need a way to give the user the chance to cancel the indicator when necessary. E.g. if the amount of selected bars is to big so it would take minutes until the indicator finished calculating, there should pop up a window to warn the user and give him the chance to reselect the input. MessageBox seems not to work with indicators and even an Alert is carried out after the indicator has done its whole calculation. What can I do?


Thx in advance :)

 
APeng: I need a way to give the user the chance to cancel the indicator when necessary. E.g. if the amount of selected bars is to big so it would take minutes until the indicator finished calculating, there should pop up a window to warn the user and give him the chance to reselect the input. MessageBox seems not to work with indicators and even an Alert is carried out after the indicator has done its whole calculation. What can I do?
Why not give the users the options they need with extern/input while the indicator is being attached?
 
ubzen:
Why not give the users the options they need with extern/input while the indicator is being attached?


The indicator looks for breakouts above / below swings. Input is swingsize and the date to where the indicator shall go back in the chart. Depending on swingsize and timeframe the number of swings can result in a very high value. For that case I was thinking about a messge box telling the user that the calculation will take long and he has to wait or to cancel an change settings like a date that is not so far in past.
 
APeng:

The indicator looks for breakouts above / below swings. Input is swingsize and the date to where the indicator shall go back in the chart. Depending on swingsize and timeframe the number of swings can result in a very high value. For that case I was thinking about a messge box telling the user that the calculation will take long and he has to wait or to cancel an change settings like a date that is not so far in past.
You can use the new feature of mql4.com to add a button on your chart, and use OnChartEvent() event handler to process user input. See mql4 reference by pressing F1 in MetaEditor (or you can use this mql5 online reference).
 
angevoyageur:
You can use the new feature of mql4.com to add a button on your chart, and use OnChartEvent() event handler to process user input. See mql4 reference by pressing F1 in MetaEditor (or you can use this mql5 online reference).


thanks, I give it a try!
 
APeng: I need a way to give the user the chance to cancel the indicator when necessary.
The new OnCalculate() gives you all you need.
Standard way (all bars)
int OnCalculate(const int rates_total,
                const int prev_calculated, ...){
   #define LOOKBACK 1 // iMA(... iBar+1)
   int indicator_counted = prev_calculated;
   if(indicator_counted < LOOKBACK) indicator_counted = LOOKBACK;
   for(int iBar = rates_total - 1 - indicator_counted; i>=0 i--){
      Buffer[iBar] = ...;
   }
   return(rates_total - 1); // Recalculate bar zero next tick.
I know what the new docs say. If you do it their way you'll have to test prev_calculated for non-zero and adjust rates_total - prev_calculated down one. That is going back to decrement indicator_counted confusion.
You just need to do the bars in groups
int OnCalculate(const int rates_total,
                const int prev_calculated, ...){
   #define LOOKBACK 1 // iMA(... iBar+1)
   #define MAXCHUNK 100
   int indicator_counted = prev_calculated;
   if(indicator_counted < LOOKBACK) indicator_counted = LOOKBACK;
   int iBar = rates_total - 1 - indicator_counted,
       iEnd = iBar - MAXCHUNK; if(iEnd < 0) iEnd = 0;
   for(; iBar >= iEnd iBar--){
      Buffer[iBar] = ...;
   }
   return(rates_total - 1); // Recalculate bar zero next tick.
}
 
angevoyageur: See mql4 reference by pressing F1 in MetaEditor (or you can use this mql5 online reference).
Use the updated MQL4 Documentation
 
WHRoeder:
Use the updated MQL4 Documentation

Ah ok, great. Thank you.
 

There are a couple of issues to check with this, when a chart is diconnected from the server for a period of several bars, on reconnect the missing bars are all added at once, IndicatorCounted would return zero on such an event causing the whole chart to be redrawn. Is it safe to assume a Rates_Total - Rates_Previous loop would just cause the missing bars to be filled in ? The other issue is when chart history is added to the back end of the chart.

 
WHRoeder:

The new OnCalculate() gives you all you need.

int OnCalculate(const int rates_total,
                const int prev_calculated, ...){
   #define LOOKBACK 1 // iMA(... iBar+1)
   #define MAXCHUNK 100
   int indicator_counted = prev_calculated;
   if(indicator_counted < LOOKBACK) indicator_counted = LOOKBACK;
   int iBar = rates_total - 1 - indicator_counted,
       iEnd = iBar - MAXCHUNK; if(iEnd < 0) iEnd = 0;
   for(; iBar >= iEnd iBar--){
      Buffer[iBar] = ...;
   }
   return(rates_total - 1); // Recalculate bar zero next tick.
}

I read and reread your code, and I don't see what it is supposed to address.

Suppose a chart with 1000 bars :

first call, rates_total=1000, prev_calculated=0 => indicator_counted=1, iBar=998, iEnd=898, Buffer is calculated for bar 998 to bar 898

second call, rates_total=1000, prev_calculated=999 => indicator_counted=999, iBar=0, iEnd=0, Buffer is calculated only for bar 0

third call, a new bar arrives, rates_total=1001, prev_calculated=999 => indicator_counted=999, iBar=1, iEnd=0, Buffer is calculated for bar 1 and 0.

The bars from 897 to 2 are never calculated. I don't see how this is an answer to the OP.

 
SDC: There are a couple of issues to check with this, when a chart is diconnected from the server for a period of several bars, on reconnect the missing bars are all added at once, IndicatorCounted would return zero on such an event causing the whole chart to be redrawn. Is it safe to assume a Rates_Total - Rates_Previous loop would just cause the missing bars to be filled in ? The other issue is when chart history is added to the back end of the chart.

False. On a disconnect/reconnect, only Bars changes, the old IndicatorCounted() doesn't, so it only processes the new bars. Only on older history download would IndicatorCounted return zero. Same for the new prev_calculated: "if since the last call of OnCalculate() price data has changed (a deeper history downloaded or history blanks filled), the value of the input parameter prev_calculated will be set to zero by the terminal."

Reason: