Can this be coded without loop?


how do i do one loop? can you please give me an example or point me to one.


Are you saying you only want to execute your logic for the current DAY (not the current BAR)?


The problem is not how many loops you do, is how many bars you need to do for each loop. Do the loop of entire array, save results in static variables, next time you test if you have new bars/ticks and calculate only new ones


No. I am saying why Amibroker executes every bar for every new tick? Once the past bars are computed there is no need to compute them again, unless there is a backfill? I am asking if there is no way to create a system without loops, for the rules given by me, then is there a way to limit the loop execution such that only the current bar gets executed for the new tick and not the entire array.


I don’t think you know, what you are talking about.

AmiBroker is probably the fastest technical analysis software on the market - it runs smoothly even on a calculator and for this reason if you complain about your backtesting or chart performance, there must be something seriously wrong with your code. There are always many ways of improving performance. One of such “tricks” has been already recommended to you - calculating some values only once (or when needed) and saving the outcome to Static variable(s). Besides there are many ways of running some parts of your code conditionally. You can also execute part of your formula only when new bar is added:


Have you tried @awilson’s approach of using static variables? You can just save your work so that you don’t need to execute it all again. You will also need to save the number of the last bar that you fully processed, so you know where to start your loop each time the AFL is called. In this way, your “loop” will usually just execute on the most recent bar.


Might be I sound dumb, but as a newbie after reading this post in detail, I have a doubt as below:

As long as we get the desired output-----what is the difference is using array / loop.


Array is faster........


@santy, as said by @awilson mainly speed of execution.

But, IMHO, if loops help you to understand better the logic and the intermediate values (using the debugger and/or tracing) they could be the first approach to use in your own learning code.
Then, when you fully understand what is going on, you should try to achieve the same results using arrays.
For this step, I recommend to liberally use the explorations adding extra columns that will also display the intermediate calculations and the corresponding arrays results: I find it is a very beneficial way to learn while experimenting with array manipulating functions.

And a search here in the forum to find code examples to see how other users are employing them is another very handy way to speed up your learning curve!


Arrays are not just faster, but orders of magnitude faster (anywhere from 100x to 1000x faster).