- get run-time AFL status information

Miscellaneous functions
(AFL 1.65)

SYNTAX status( ''statuscode'' )
FUNCTION Returns run-time status of the analysis engine. Supported status codes:
  • "stocknum" - gives you the ordinal number of currently analysed symbol
  • "action" - gives information in what context given formula is run: 1 - actionIndicator (INDICATOR), 2 - actionCommentary (COMMENTARY), 3 - actionScan (SCAN), 4 - actionExplore (EXPLORATION), 5 - actionBacktest (BACKTEST / OPTIMIZE), 6 - actionPortfolio (portfolio backtest). The value of actionBacktest (5) (backtest) is used also in some other contexts (like code check and profile). Therefore you can use ActionEx to get more detailed/precise information
  • "ActionEx" (new in 5.20) - more detailed information about action that triggered AFL execution. Note that 5 first codes are the same as Status("action") but scope is limited to 'core' meaning (see notes below).
    Possible values
    1. actionIndicator - when indicator is being repainted (NOTE: 5.32 - indicator can also give actionExInterpret when updating both chart and interpretation)
    2. actionCommentary (NOTE: commentary only, not interpretaion nor tooltip)
    3. actionScan - when AA Scan is performed
    4. actionExplore - when AA exploration is performed
    5. actionBacktest (NOTE backtest only, no optimization)
    6. actionPortfolio (2nd phase of portfolio backtest (custom backtest)
    7. reserved for future use
    8. reserved for future use
    9. reserved for future use
    10. - actionExAAShowArrows - when AA "Show arrows" command is used
    11. actionExAAParameters - when AA "Parameters" dialog is displayed/updated
    12. actionExEditVerifyFormula - when AFL editor verifies syntax
    13. actionExOptimizeSetup - when Optimize() parameters are read (to setup optimization engine)
    14. actionExOptimizeBacktest - when Backtest is performed as a part of optimization process
    15. actionExOptimizePortfolio - when portfolio-backtest phase (CUSTOM backtester) is performed as a part of optimization process
    16. actionExTooltip - when tooltip for given chart is being displayed/updated
    17. actionExInterpret - when the Interpretation window is being updated (can also mean indicator + interpretation in 5.32 above, see note below)
    18. (not used, reserved for future) actionExAAInit - when AA needs to initialize QuickAFL bars required information and/or formula contains functions changing general AA options

    NOTE: for backward compatiblity with all formulas you have written already, the codes for Status("action") did NOT change.

    NOTE ABOUT 5.32.x CHANGE: Since introduction of multi-threading, there is only ONE pass/execution that updates both indicator and interpretation when current chart pane has focus. Status("action") will always return actionIndicator and Status("actionex") will either return actionExInterpret (when chart pane has focus and intepretation window is visible) or actionIndicator otherwise (when pane does not have focus or interpretation is NOT visible). Be careful NOT to disable Plot() depending on Status("actionex") code. If you really think you need to execute Plot() conditionally you should only check for Status("action")==actionIndicator.
  • "rangefromdate", "rangetodate" - return current auto-analysis From-To range as DateNums
  • "rangefromtime", "rangetotime" - return current auto-analysis From-To range as DateNums
  • "barinrange" - returns 1 when current bar is within current auto-analysis From-To range
  • "barvisible" - (custom indicators only) returns 1 when current bar is visible in current view
  • "firstbarinrange" and "lastbarinrange". They return 1 (or True) on the first/last bar of analysis range.
  • "buydelay", "selldelay", "shortdelay", "coverdelay" - return delays set in the Settings window
  • "firstbarintest" and "lastbarintest" - similar to "firstbarinrange" and "lastbarinrange" but they return the settings of last BACKTEST/OPTIMIZATION and intermediate scans/explorations do not affect them
  • "firstvisiblebar", "lastvisiblebar", "firstvisiblebarindex", "lastvisiblebarindex" - return bar number or bar index of first/last visible bar. Available in indicator mode only. Visible bar may potentially include "blank" future bars (past the last bar in the array) as defined in preferences
  • "redrawaction" - returns 0 (zero) for regular refreshes, and 1 for refreshes triggered via RequestTimedRefresh().
  • "pxwidth" - returns pixel width of chart window pane (indicators only, low-level gfx) (AmiBroker 4.94 or higher)
  • "pxheight" - returns pixel height of chart window pane (indicators only, low-level gfx) (AmiBroker 4.94 or higher)
  • "axisminy" - retrieves the minimum (bottom) value of Y axis (indicators only, low-level gfx)
  • "axismaxy" - retrieves the maximum (top) value of Y axis (indicators only, low-level gfx)
  • "pxchartleft" - returns x-coordinate of top-left corner of chart area
  • "pxcharttop" - returns y-coordinate of top-left corner of chart area
  • "pxchartright" - returns x-coordinate of bottom-right corner of chart area
  • "pxchartbottom" - returns y-coordinate of bottom-right corner of chart area
  • "pxchartwidth" - returns width chart area (right-left)
  • "pxchartheight" - returns width chart area (bottom-top)
  • "quickaflfirstdatabar", "quickafllastdatabar" - This feature is for internal use only. These are bar indexes of actual underlying compressed quotation array that make up AFL's array[ 0 ] and array[ BarCount - 1]
  • "timeshift" - returns database timeshift expressed in seconds (v5.60)
  • "lastbarend" - returns DateTime of the end of last bar. For example 5 -minute bar at 9:00 will have end time of 9:04:59 (works for time-based bars only) (v5.60)
  • "lastbartimeleft" - returns number of seconds to the completion of current last bar. Works for time-based bars only. Note that for proper operation this requires database timeshift to be set properly (so dates displayed on chart match your local computer time zone). (v5.60)
  • "lastbartimeleftrt" - it works like "lastbartimeleft" but uses the most recent RT stream update time instead of Now(). Also added Status("lastrtupdate") - time of last RT stream update Depends on RT plugin to deliver correct DateUpdate / TimeUpdate data. If plugin or date source sends incorrect datetimestamps or does not send DateUpdate/TimeUpdate correctly this function will not operate properly. Note that most data sources send weird (not current) datetime stamps on weekends. Also IQFeed plugin sends DateUpdate/TimeUpdate only inside regular trading hours. (v5.60)
  • "lastrtupdate" - returns date time of last update sent by RT plugin (see remarks above) (v5.60)
  • "ThreadID" - returns current thread ID under which formula is executed.
EXAMPLE Example 1:

if( Status("redrawaction") ==1 )

Example 2 (low-level graphic overlay + pixel co-ordinate conversion):


function GetVisibleBarCount()
 lvb =
 fvb =

 return Min( Lvb - fvb, BarCount - fvb );

function GfxConvertBarToPixelX( bar )
 lvb =
 fvb =
 pxchartleft =
 pxchartwidth =

 return pxchartleft + bar  * pxchartwidth / ( Lvb - fvb + 1 );

function GfxConvertValueToPixelY( Value )
 local Miny, Maxy, pxchartbottom, pxchartheight;

 Miny =
 Maxy =

 pxchartbottom =
 pxchartheight =

 return pxchartbottom - floor( 0.5 + ( Value - Miny ) * pxchartheight/ ( Maxy - Miny ) );

Plot(C, "Price", colorBlack, styleHistogram );

GfxSelectSolidBrush( colorRed );
GfxSelectPen( colorRed );

AllVisibleBars = GetVisibleBarCount();
fvb =

for( i = 0; i < AllVisibleBars ; i++ )
   x = GfxConvertBarToPixelX( i );
   y = GfxConvertValueToPixelY(
C[ i + fvb ] );

GfxRectangle( x-1, y-1, x + 2, y+1 );

//SetChartBkGradientFill( ColorRGB(200,200,200), ColorRGB( 255,255,255) );

SEE ALSO RequestTimedRefresh() function


The Status function is used in the following formulas in AFL on-line library:

More information:

Updated on-line reference