Hi,
The Sleep() function isn't allowed for a custom indicator. Is there any workaround ?
I wrote the following code but it doesnt work fine when I change timeframes of charts.
But when I did the same thing with Expert Adviser program, it works fine by using the Sleep() function.
How can I do that with Custom Indicator ?
or
Thank you =)
It's probably not a good idea to put this code in OnInit(), your examples don't make a lot of sense.
In OnTick(), for example :
void OnTick() { static bool firstCall=true; if(firstCall) { //-- Your code ... firstCall=false; } ...
In OnTick(), for example :
Thank you so much!
I'll try that :)
Hi,
It almost works fine in the way that you told me. Thanks (=^・^=)
But when I change timeframe of chart, 'Wating For Update' pending sometimes occurs for seconds.
In that case, the function still returns false.
int OnCalculate(const int rates_total, const int prev_calculated, const int begin, const double &price[] ) { static bool firstCall=true; if(firstCall) { if(ChartNavigate(0,CHART_CURRENT_POS,100)==false) Print("ChartNavigate Error!!!"); firstCall=false; } }
I know it would work well when the next tick is received, by writing as blow.
if(ChartNavigate(0,CHART_CURRENT_POS,100)==false) Print("ChartNavigate Error"); else firstCall=false;
But it doesnt work on weekend, when markets are closed.
Do you have any recommendations to do well any day ?
Hi,
It almost works fine in the way that you told me. Thanks (=^・^=)
But when I change timeframe of chart, 'Wating For Update' pending sometimes occurs for seconds.
In that case, the function still returns false.
I know it would work well when the next tick is received, by writing as blow.
But it doesnt work on weekend, when markets are closed.
Do you have any recommendations to do well any day ?
Sorry but I don't understand well your issue, what "doesn't work on weekend" ?
Sorry about my bad English :'(
if(ChartNavigate(0,CHART_CURRENT_POS,100)==false) Print("ChartNavigate Error"); else firstCall=false;
Even though the ChartNavigate function fails in firstCall, it is called by every tick before becoming successful on weekdays.
But on weekend, it doesnt work fine because the ChartNavigate function is called only once,
the second never be called.
So I'm strugging to make it work any day.
I wanted to do like below with Custom Indicators.
for(int i=0;i<100;i++) { if(ChartNavigate(0,CHART_CURRENT_POS,100)==false) Sleep(50); else { firstCall=false; break; } }
Sorry about my bad English :'(
Even though the ChartNavigate function fails in firstCall, it is called by every tick before becoming successful on weekdays.
But on weekend, it doesnt work fine because the ChartNavigate function is called only once,
the second never be called.
So I'm strugging to make it work any day.
I wanted to do like below with Custom Indicators.
Your English is just as good as mine
Ok, I got it now. On week-end OnCalculate() is only call once as there is no tick. Isn't your last posted code working ? Maybe you can try a while() loop.
Your English is just as good as mine
Ok, I got it now. On week-end OnCalculate() is only call once as there is no tick. Isn't your last posted code working ? Maybe you can try a while() loop.
I feel some relief about my English :-)
The last posted code works fine only as an Expert Adviser program that allows the Sleep() function.
But it doesnt as a Custom Indicator that doesnt allow the Sleep() function sadly.
So I appreciate if you could tell me any idea or any workaround !
Thanks for your time (^_^)

- www.mql5.com

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi,
The Sleep() function isn't allowed for a custom indicator. Is there any workaround ?
I wrote the following code but it doesnt work fine when I change timeframes of charts.
But when I did the same thing with Expert Adviser program, it works fine by using the Sleep() function.
How can I do that with Custom Indicator ?
or
Thank you =)