|
Post by bobpit on Mar 13, 2016 18:56:02 GMT
What if my formula takes several seconds to execute and in the meantime a new bar forms (in a live system)? Then the barcount will be increased by one. All array variables that I have in memory will have one less cell.
Will the formula brake? How do you deal with this issue?
|
|
Milosz
Rookie
Posts: 38
Received Likes: 12
|
Post by Milosz on Mar 13, 2016 20:05:41 GMT
What makes your formula so slow? Maybe there is a way to significantly improve its performance?
|
|
|
Post by bobpit on Mar 13, 2016 22:17:33 GMT
Hi Milosz, thank you for answering.
I am not facing any issue right now, I made a theoretical question. I always strive for efficiency, but I am righting a formula that is going to grow a lot.
|
|
|
Post by bobpit on Mar 14, 2016 0:46:43 GMT
AB takes care of this problem. I run the following code. It artificially delays about 5sec from begin to end of formula execution. I had bar replay (1 bar per second). So from beginning to end of formula I had 5 bars. The script takes a snapshot of the database at the beginning of the executions and correctly reports the same number of bars at the end of the execution. Next time the script runs, it takes another snapshot, but this time the database has 5 more bars (since 5sec had elapsed).
procedure delay_execution(d) {local i, k;
GetPerformanceCounter(true); // reset the timer
do {
// just a dummy loop to spend some time for( i = 0; i < 1000; i++ ) { k = 0; }
} // see if enough time has elapsed while (d > GetPerformanceCounter(false)) ;
}
SetBarsRequired(-2,-2); printf("barcount1 = %g \n",BarCount); delay_execution(5000); printf("GetPerformanceCounter(false); = %g \n", GetPerformanceCounter(false)); printf("barcount2 = %g \n",BarCount);
sample output: barcount1 = 11491 GetPerformanceCounter(false); = 5000.06 barcount2 = 11491
|
|