@AlgoEnthusiast, if nested loops are the only way to do it, to achieve a much faster execution time, you should convert your AFL code to a DLL function using the free Amibroker Development Kit (ADK)
(It requires the knowledge to code and compile a DLL using Microsoft C++.)
See this kb article and/or search the forum for additional topics about its usage.