Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 6. - page 1177

 
Rost17: Can you please advise how to set the indicator to work only on bar opening and not on every tick and how to make it not run every time (on every new bar) through the whole history?
Datetime t;
First, about the bars. When a new bar is formed, a new value is written to Time[0] - the time when the bar opens.
OnCalculate(...)
{
if(Time[0] == t) return(0); // If this bar is processed --> exit
t = Time[0];

Now for the whole history: it will slow
 
STARIJ:
datetime t;
First, about the bars. When we form a new bar, we write a new value into Time[0] - the time when the bar opens.
OnCalculate(...)
{
if(Time[0] == t) return(0); // if this bar is processed --> exit
t = Time[0];

Now for the whole story: it will slow down

Thanks for the quick reply. What I'm asking is how to make it NOT slow down and run through history when a new bar appears, but just process the new bar...

Now it's organized as follows: for(int i=limit-1; i>=0; i--) and as I understand it, it means that at every opening of a bar, all values on the entire history will be recalculated again, while you should work only with the last bar...

 
Rost17: I'm asking how to make it NOT slow down and not run through the whole history when a new bar appears, but just process the new bar...

This is how it calculates on the last bar:

//| Bears Power                                                      |
//+------------------------------------------------------------------+
int OnCalculate(.....)
  {
   int limit=rates_total-prev_calculated; // Количество баров, которые будем считать = ВсегоБаров - РанееПросчитано
   if(rates_total<=InpBearsPeriod) return(0);

   if(prev_calculated>0) limit++; // Если давно считаем, то захватим и предыдущий бар для точности
   for(int i=0; i<limit; i++)
     {
      ExtTempBuffer[i]=iMA(NULL,0,InpBearsPeriod,0,MODE_EMA,PRICE_CLOSE,i);
      ExtBearsBuffer[i]=low[i]-ExtTempBuffer[i];
     }
   return(rates_total);
  }
 
STARIJ:

Let's look at the line first

to make it clearer to me, I've rewritten it this way.

Aha!!! Now I'm starting to understand... In the loop, the variable a changes from 1 to 6. With values of this variable 1, 5 and 6 there is no action. Then just

Or in your style.

The result will be the same but it will run faster !

Now you need to get rid of the Statistic function, write its body three times in a row, replace the formal parameters in each of the three parts with actual parameters and remove duplicated variable declarations. The total code will be a bit longer but the execution will be faster. It makes sense to throw out print() - who exactly at this time will look through the message log? - Or replace it with Alert() to display it on the screen. Also, there is a variable namZz2 - does its value change?


I need to use stats() instead of stats(). Stupidly, I know I can rewrite three times, as you said, but the problem is that most likely the result of gathering statistics will have to add more arrays and I will sooner or later return to the original ones. That's why I offer you simple ways, which I already know, and they will unfortunately lead me to the beginning. That is why I look ahead, so that I do not have to return to it in the future!

for(int a=1;a<6;a++)
{
   if(a==2){Statistic(mZz2,namZz2);}
   if(a==3){Statistic(mZz3,namZz3);}
   if(a==4){Statistic(mZz4,namZz4);}
}

how to put this code into the statistician!? to be a single procedure you at the beginning as I stated the question please look at!

 
STARIJ:

Here's how it's calculated on the last bar:

Thank you very much! I have a very old indicator source. Could you fix it so it doesn't recalculate all the history every time, works only on bar close and puts the arrow only on the bar, after which the signal appeared? Well, and in the new style, with OnCalculate... I'm willing to compensate for the cost of your time... If you agree, what is the best way to do it? Can I send it to you in a private message or where?
 
Игорь:

Here is an extract from the working code ! How to collect it in one void Statistic without intermediate void Stat ! I would have to rework the whole code in order to gather all arrays into one and try to scratch it out from there !

The excerpt you cited from your working code is either wrong or your Statistic() function does nothing but print when called from Stat().

Anyway, it will stop right after return;.

Please give us the whole code to understand what you want.

 

For the record. Too many threads on the forum to help newbies on MQL4.

This thread is no longer supported and is closed.


Please direct all questions to any of the following active threads:

https://www.mql5.com/ru/forum/160683

https://www.mql5.com/ru/forum/160587

All further posts in this thread will be deleted.


 
help can an already bought order change its purchase price in 2 hours
Reason: