AmiBroker executes code in various contexts indicated by “action” status…
As of version 6.10, the debugger runs the code with actionBacktest context.
Source: How to use AFL visual debugger
@Tomasz Can you clarify the order of Contexts (Status(“ActionEX”) in which AFL Executes while performing:
Backtest
Exploration
Interactive Chart (i.e. mouse clicking on a bar)
Other times AFL may execute
While in the AFL editor, or some other technique, is it possible to filter and view AFL code by the Execution Context in which it will run?
@SwingTradeMonkey The code below may help to understand the order of execution. Put this at the top of your afl and then try various actions. Watch the log window to see what happens.
function ActionExToStr(actionExNum)
{
switch (actionExNum)
{
case 1: result = "actionIndicator"; break;
case 2: result = "actionCommentary"; break;
case 3: result = "actionScan"; break;
case 4: result = "actionExplore"; break;
case 5: result = "actionBacktest"; break;
case 6: result = "actionPortfolio"; break;
case 7: result = "reserved7"; break;
case 8: result = "reserved8"; break;
case 9: result = "reserved9"; break;
case 10: result = "actionExAAShowArrows"; break;
case 11: result = "actionExAAParameters"; break;
case 12: result = "actionExEditVerifyFormula"; break;
case 13: result = "actionExOptimizeSetup"; break;
case 14: result = "actionExOptimizeBacktest"; break;
case 15: result = "actionExOptimizePortfolio"; break;
case 16: result = "actionExTooltip"; break;
case 17: result = "actionExInterpret"; break;
case 18: result = "actionExAAInit"; break;
}
return result;
}
stockNum = Status("stocknum");
actionEx = Status("ActionEx");
_Trace("" + stockNum + " " + Name() + " " + ActionExToStr(actionEx));
@Steve This is is a Great start and can show me the current context AFL is in during execution.
Now, I can only imagine how much easier debugging could be if there where a way in the AFL editor to “grey out” or hide code that does not execute in a particular context.
General advice is to avoid such conditional execution unless absolutely necessary (such as in case of actionPortfolio where code for CBT really needs to be separated).
It does not hurt to call Plot say in exploration, it will simply do nothing. Too many if-else just make formulas less readable.