Way to limit tick update on my indicators in order to avoid freeze my computer?

 

Every time when the market get volatile my computer get freeze. I know, maybe I running more indicators than I need but as I'm learning I need them.

On my indicators I use basically this format to plot them. 

int K=0;
int Periodo =Period();
   
 switch(Periodo)
 
   { 
       case (1):   break; 
       case (5):   K=286;  break;
       case (15):  K=96;   break;
       case (30):  K=48;  break;
       case (60):  K=24;   break;
       case (240): K=15; break;  
       case (1440):  K=5; break;
       case (7200):  K=13;  break;
  
  }


   for (int i=0; i<Bars; i++)
   {

   
   
    Label6Buffer[i]= iMA(NULL,0,K/8,0,0,0,i);
       Label7Buffer[i]= iMA(NULL,0,K/4,0,0,0,i);
         Label8Buffer[i]= iMA(NULL,0,K/2,0,0,0,i);
            Label9Buffer[i]= iMA(NULL,0,K,0,0,0,i);   
             Label10Buffer[i]= iMA(NULL,0,5*K,0,0,0,i);   
   
   
   }
   

I believe my computer get freeze because it calculates on every tick, and on times of high volumes there is a lot of activity every tck.

If Am I right, is there a way to limit the number of interactions, lets say like limit to one or two every second?

O there is a way to code to avoid this?

Thank you


PD. Sorry, I think this belong to the indicators threads but couldn't find the way to move it.

The Fundamentals of Testing in MetaTrader 5
The Fundamentals of Testing in MetaTrader 5
  • www.mql5.com
What are the differences between the three modes of testing in MetaTrader 5, and what should be particularly looked for? How does the testing of an EA, trading simultaneously on multiple instruments, take place? When and how are the indicator values calculated during testing, and how are the events handled? How to synchronize the bars from different instruments during testing in an "open prices only" mode? This article aims to provide answers to these and many other questions.
 
The code you posted will calculate ALL values of ALL candles/periods on each tick.

You need to limit your for-loop to only calculate the most current period, after all periods ha e been calculated ONCE.

Read the docs on how to use OnCalculate and take a look at how the sample codes of indicators provided with MT5 do it.

You are doing it wrong at the moment.
 
Thank youDominik Egert #:
The code you posted will calculate ALL values of ALL candles/periods on each tick.

You need to limit your for-loop to only calculate the most current period, after all periods ha e been calculated ONCE.

Read the docs on how to use OnCalculate and take a look at how the sample codes of indicators provided with MT5 do it.

You are doing it wrong at the moment.
It makes sense. Will work on it. Thank you
 
   for (int i=0; i<Bars; i++)

Do your lookbacks correctly #9#14 & #19

.
 
William Roeder #:

Do your lookbacks correctly #9#14 & #19

.
Awesome! Thank you sir!
Reason: