I can't refresh my custom indicator automatically

 

Hello again, I hope your are doing well.

For a little context, my indicator uses data that is pulled from the web at candle open and written to a file. 

The problem is sometimes the line is not being updated accurately and I need to either manually switch timeframe and revert to the previous timeframe or manually right-click > refresh the chart to redraw the line correctly. 

I have tried waiting 30 seconds after bar open and runnning

 WindowRedraw();
ChartRedraw(ChartWindowFind());


...inside OnTimer()  with  EventSetTimer(30000); but as you guessed correctly: it doesn't work, otherwize I wouldn't be asking for help.


I am out of ideas. Could you help me find the solution?

 
  1. dc3463456: I have tried waiting 30 seconds after bar open and runnning

    Indicators can not sleep.

  2. dc3463456: For a little context, my indicator uses data that is pulled from the web at candle open and written to a file. 
    A WebRequest requires sleeping. Can't be done in an indicator.
 
William Roeder #:
  1. Indicators can not sleep.

  2. A WebRequest requires sleeping. Can't be done in an indicator.

2. Don't worry, the indicator only reads the file, the WebRequest is handled by an EA.

1. Oh right. Now I just leave the refresh code under OnCalculate(), yet the effect is not as good as when I manually refresh. Sometimes the refreshing doesn't happen and I swear it's not because the OnCalculate() function had not been triggered yet.


So why can I only be sure the chart is refreshed properly by doing it manually?

 
dc3463456:

Hello again, I hope your are doing well.

For a little context, my indicator uses data that is pulled from the web at candle open and written to a file. 

The problem is sometimes the line is not being updated accurately and I need to either manually switch timeframe and revert to the previous timeframe or manually right-click > refresh the chart to redraw the line correctly. 

I have tried waiting 30 seconds after bar open and runnning


...inside OnTimer()  with  EventSetTimer(30000); but as you guessed correctly: it doesn't work, otherwize I wouldn't be asking for help.


I am out of ideas. Could you help me find the solution?

That's not 30 seconds, but 30,000 seconds.

 WindowRedraw();
ChartRedraw(ChartWindowFind());

WindowRedraw() is Mql4 obsolete function. Not needed.

ChartRedraw() doesn't need a parameter to redraw the current chart, and if you provide one it's a chart ID, not a (sub)window number.

In general, you don't provide enough information about your issue.

 
Alain Verleyen #:

That's not 30 seconds, but 30,000 seconds.

WindowRedraw() is Mql4 obsolete function. Not needed.

ChartRedraw() doesn't need a parameter to redraw the current chart, and if you provide one it's a chart ID, not a (sub)window number.

In general, you don't provide enough information about your issue.

Oops, the Sleep function confused me because it uses milliseconds instead.

I'm trying to refresh a separate indicator window, hence the sub-window parameter. Are you saying the default chart includes that window?

 
dc3463456 #:

Oops, the Sleep function confused me because it uses milliseconds instead.

I'm trying to refresh a separate indicator window, hence the sub-window parameter. Are you saying the default chart includes that window?

Of course. A chart includes all (sub)windows.