{"id":1082,"date":"2015-02-03T17:35:59","date_gmt":"2015-02-03T22:35:59","guid":{"rendered":"http:\/\/www.amibroker.com\/kb\/?p=1082"},"modified":"2015-02-11T18:36:21","modified_gmt":"2015-02-11T23:36:21","slug":"when-and-how-often-afl-code-is-executed","status":"publish","type":"post","link":"https:\/\/www.amibroker.com\/wordpress\/kb\/2015\/02\/03\/when-and-how-often-afl-code-is-executed\/","title":{"rendered":"When and how often AFL code is executed?"},"content":{"rendered":"
All analysis in AmiBroker including charting, Analysis window or commentaries is based on underlying AFL code, which is being executed by the program to produce the required output. Therefore – any changes we see in the charts or analysis results (for example – chart updated with new ticks) mean that the program has received some input, then based on this information has recalculated the formula and presented the updated results.<\/p>
These refreshes \/ formula recalculations depend on several factors:<\/p>
It is worth noting that chart formulas are refreshed only when they are placed on the active chart sheets. Non-active sheets just ‘don’t exist’, they are only created when you click on a bottom tab (sheet tab) to make them visible and destroyed immediately when other sheet becomes active. This ensures that precious CPU resources are not wasted on invisible chart sheets.<\/p>
Additionally – by default charts in minimized chart windows or when multiple MDI windows are open and one is maximized, the windows in background that are completely obscured by others and\/or minimized windows are not redrawn\/refreshed during normal RT refresh. We can however call RequestTimedRefresh<\/strong> function with onlyvisible<\/strong> argument set to False<\/strong> and that will force regular refreshes in such windows as well.<\/p> With regards to Analysis<\/strong> window – in general the formula is executed when we run e.g. Scan, Exploration, Backtest etc. Analysis window executes the formulas in multiple threads running in parallel (this tutorial explains multi-threading aspects: http:\/\/www.amibroker.com\/guide\/h_multithreading.html<\/a>).<\/p> Repeated execution (to keep the code running over and over) in Analysis window can be also enabled with “Auto-repeat” option, the following Knowledge Base article explains it in details:<\/p>RequestTimedRefresh<\/span>( <\/span>1 <\/span>, <\/span>False <\/span>); <\/span>\/\/ force refresh for minimized MDI window or obscured MDI windo<\/code>