The problem bug lies in the Print function; i replaced print with Alert and it is working as expected. By the way, global variables are static by themselves
Well, i was hurry on that one; Alert looks like it is working, but it does not actually
Yes, I have try and still hang
I looked at a little bit more, and here are some remarks. You can try the code
while (newbar<150)
{
Alert("Still Old candle"); Sleep(1000); newbar++;
}
Alert("Now new candle occurs");
If you right click and remove the script before it finishes the counting, we can see that the terminal disregards Sleep() and proceeds to complete the script as if Sleep was not there. So, in case we have while (newbar==Time[0] ) it goes in an infinite loop. Looks like a bug to me
Also, you should add RefresRates() inside while, or else Time[0] is not updated (so above code is wrong as well :) )
basicly, I want to loop the program until new candle occurs (do not go to the bigining start program for every tick until the current candle finish)
Do you have suggestion beside "While(still old candle)"
I can see your code is based presumably in the MQL book which is ok but somehow outdated. You can find more stuff in the reference manual and up to date of course.
Now, it looks like you are going to be happy with an indicator. In that case you can use OnTimer() with a period you want and put your code inside there instead of Start() ; you should not be worried if your program needs more time than the period you set, as MQL has a message queue
In any case, Start(), Init() are obsolete and you may use OnStart(), OnInit() etc. You can look at "MQL4 programs" in the reference manual, as a starting point for more info
Well, if you still want to use a script (presence of OnStart() implies a script), you have to enter the following line to protect your code
voidOnStart() /* i replaced int Start() with void OnStart(), so I removed return 0; from the body */
{
newbar = Time[0];
while (newbar == Time[0])
{
Alert("Still Old candle"); Sleep(1000); RefreshRates();
if (IsStopped() ) newbar=0; /* I added this line to handle the removal of the script */
}
Alert("Now new candle occurs");
}
hello,
The problem bug lies in the Print function; i replaced print with Alert and it is working as expected. By the way, global variables are static by themselves
(in MQL that is) so there is no need to do
static datetime newbar ;
best regards
I will Try
Thank you
Well, i was hurry on that one; Alert looks like it is working, but it does not actually
Yes, I have try and still hang
basicly, I want to loop the program until new candle occurs (do not go to the bigining start program for every tick until the current candle finish)
Do you have suggestion beside "While(still old candle)"
Thank you
Demos:
Yes, I have try and still hang
I looked at a little bit more, and here are some remarks. You can try the code
If you right click and remove the script before it finishes the counting, we can see that the terminal disregards Sleep() and proceeds to complete the script as if Sleep was not there. So, in case we have while (newbar==Time[0] ) it goes in an infinite loop. Looks like a bug to me
Also, you should add RefresRates() inside while, or else Time[0] is not updated (so above code is wrong as well :) )
basicly, I want to loop the program until new candle occurs (do not go to the bigining start program for every tick until the current candle finish)
Do you have suggestion beside "While(still old candle)"
I can see your code is based presumably in the MQL book which is ok but somehow outdated. You can find more stuff in the reference manual and up to date of course.I have add RefreshRates(), but the problem still exist
what do i don't understand why there isn't any "Still Old candle" printed in the expert tab, not even once
thank you
I think the structure of my program is wrong, because even I use this still the problem occurs
anyway thank you for to all of you for your effort to help me
best regards
I have add RefreshRates(), but the problem still exist
what do i don't understand why there isn't any "Still Old candle" printed in the expert tab, not even once
thank you
I put your code into a script and it worked as expected. Printed every second until a new bar.
Are you sure that you are looking in the Experts Tab and not the journal for the prints?
I put your code into a script and it worked as expected. Printed every second until a new bar.
Are you sure that you are looking in the Experts Tab and not the journal for the prints?