What I want to do is have an indicator update every X seconds and not wait for ticks at all.

 

What I want to do is have an indicator update every X seconds and not wait for ticks at all.


I have an indicator that writes to memory every time the price changes.


I want to have another indicator read memory every X seconds and display the value.




 
 
while(true)
{
 
elapsed = TimeLocal() - tTime ;
 
if( elapsed > myWaitTime )
{
 
DoGet( symbol, PERIOD_M1, 0) ;
 
 
Comment(
"tName= ", tName, "\n",
"tValue= ", DoubleToStr(tValue, Digits), "\n",
//"elapsed= ", elapsed, "\n",
"") ;
 
} // IF
 
 
 
tTime = TimeLocal() ;
 
WindowRedraw() ;
 
} // WHILE
 
 
//+------------------------------------------------------------------+
 
 
void DoGet(string sName, int sPeriod, int sShift )
{
 
tName = symbol + TimeFrameToString(sPeriod) + "Close" + sShift;
 
tValue=GlobalVariableGet(tName);
 
if(GetLastError()!=0) return(false);
 
}
 
//+------------------------------------------------------------------+




Loading the above causes MT4 to freeze.



Thanking you in advance for your assistance.

 

You can't put an endless loop -- your WHILE -- in an indicator.

As you found, it runs the CPU to 100%.

You can run a WHILE in a Script or EA, if you use Sleep() to give an escape from the loop for other tasks to execute.

Sleep() won't work in an indicator.

 
phy:

You can't put an endless loop -- your WHILE -- in an indicator.

As you found, it runs the CPU to 100%.

You can run a WHILE in a Script or EA, if you use Sleep() to give an escape from the loop for other tasks to execute.

Sleep() won't work in an indicator.



Thank you.



After I posted, I found your post about scripts and used your test script to build what I needed.



I appreciate you taking the time to reply.



Now, I need to learn more about the limitations of scripts.

 

Main limitation of scripts:

1. It is not an indicator, so can't manipulate indicator indexes.

2. It is not 'attached" to the chart like an indicator or EA, so you have to run it manually whenever it is stopped, chart time change, platform restart, etc.

Reason: