SetOption
- sets options in automatic analysis settings

Trading system toolbox
(AmiBroker 4.30)


SYNTAX SetOption( field, value )
RETURNS NOTHING
FUNCTION Sets various options in automatic analysis settings. Affects also Equity() function results.

field - is a string that defines the option to change. There are following options available:

  • "NoDefaultColumns" - if set to True - exploration does not have default Ticker and Date/Time columns
  • "InitialEquity"
  • "AllowSameBarExit"
  • "ActivateStopsImmediately"
  • "AllowPositionShrinking"
  • "FuturesMode"
  • "InterestRate"
  • "MaxOpenPositions" - maximum number of simlutaneously open positions (trades) in portfolio backtest/optimization
  • "WorstRankHeld" - the worst rank of symbol to be held in rotational trading mode (see EnableRotationalTrading for more details)
  • "MinShares" - the minimum number of shares required to open the position in the backtester/optimizer. If you don't have enough funds to purchase that many, trade will NOT be entered
  • "MinPosValue" - (4.70.3 and above) the minimum dollar amount required to open the position in the backtester/optimizer. If you don't have enough funds trade will NOT be entered
  • "PriceBoundChecking" - if set to False - disables checking and adjusting buyprice/sellprice/coverprice/shortprice arrays to current symbol High-Low range.
  • CommissionMode -
    0 - use portfolio manager commission table
    1 - percent of trade
    2 - $ per trade
    3 - $ per share/contract
  • CommissionAmount - amount of commission in modes 1..3
  • AccountMargin (in old versios it was 'MarginRequirement') - account margin requirement (as in settings), 100 = no margin
  • ReverseSignalForcesExit - reverse entry signal forces exit of existing trade (default = True )
  • UsePrevBarEquityForPosSizing - Affects how percent of current equity position sizing is performed.
    False (default value) means: use current (intraday) equity to perform position sizing,
    True means: use previous bar closing equity to perform position sizing
  • PortfolioReportMode - sets backtester report mode:
    0 - trade list
    1 - detailed log
    2 - summary
    3 - no output (custom only)
  • UseCustomBacktestProc - True/False - allows to turn on/off custom backtest procedure
  • EveryBarNullCheck - allows to turn on checking for Nulls in arithmetic operations on every bar in the array(by default it is OFF - i.e. AmiBroker checks for nulls that appear in the beginning of the arrayand in the end of the array and once non-null value is detected it assumes no further holes (nulls) in the middle). Turning "EveryBarNullCheck" to True allows to extend these checks to each and every barwhich is the way 4.74.x and earlier versions worked.
    Note however that turning it on gives huge performance penalty (arithmetic operations are performed even 4x slower when this option is ON, so don't use it unless you really have to).
  • HoldMinBars - Number - if set to value > 0 - it disables exit during user-specified number of bars even if signals/stops are generated during that period
  • EarlyExitBars - Number if set to value > 0 - causes that special early exit (redemption) fee is charged if trade is exited during this period
  • EarlyExitFee - defines the % (percent) value of early exit fee
  • HoldMinDays - Number - if set to value > 0 - it disables exit during user-specified number of CALENDAR DAYS (not bars) even if signals/stops are generated during that period
  • EarlyExitDays - Number if set to value > 0 - causes that special early exit (redemption) fee is charged if trade is exited during the period specified in calendar days (not bars).
  • DisableRuinStop - it set to TRUE built-in ruin stop is disabled
  • Generate report - allows to suppress/force generation of backtest report. Allowable values: 0, 1, or 2
    By default backtest reports are generated ONLY for portfolio backtests and for individual backtests if individual reporting is turned on in the settings. Reports are disabled for optimization.
    Now with the SetOption() function you can either supress report generation for backtests or enable report generation during certain optimization steps, all from code level.
    SetOption("GenerateReport", 0 ); // suppress generation of report
    SetOption("GenerateReport", 1 ); // force generation of full report
    SetOption("GenerateReport", 2 ); // only one-line report is generated (in results.rlst file) viewable as single line in Report Explorer
  • SeparateLongShortRank - True/False
    When separate long/short ranking is enabled, the backtester maintains TWO separate "top-ranked" signal lists, one for long signals and one for short signals. This ensures that long and short candidates are independently even if position score is not symetrical (for example when long candidates have very high positive scores while short candidates have only fractional negative scores). That contrasts with the default mode where only absolute value of position score matters, therefore one side (long/short) may completely dominate ranking if score values are asymetrical.
    When SeparateLongShortRank is enabled, in the second phase of backtest, two separate ranking lists are interleaved to form final signal list by first taking top ranked long, then top ranked short, then 2nd top ranked long, then 2nd top ranked short, then 3rd top ranked long and 3rd top ranked short, and so on... (as long as signals exist in BOTH long/short lists, if there is no more signals of given kind, then remaining signals from either long or short lists are appended)
    For example: Entry signals(score):ESRX=Buy(60.93), GILD=Short(-47.56), CELG=Buy(57.68), MRVL=Short(-10.75), ADBE=Buy(34.75), VRTX=Buy(15.55), SIRI=Buy(2.79),
    As you can see Short signals get interleaved between Long signals even though their absolute values of scores are smaller than corresponding scores of long signals. Also there were only 2 short signals for that particular bar so, the rest of the list shows long signals in order of position score
    Although this feature can be used independently, it is intended to be used in combination with MaxOpenLong and MaxOpenShort options.
  • MaxOpenLong - limits the number of LONG positions that can be open simultaneously
  • MaxOpenShort - limits the number of SHORT positions that can be open simultaneously
    The value of ZERO (default) means NO LIMIT. If both MaxOpenLong and MaxOpenShort are set to zero ( or not defined at all) the backtester works old way - there is only global limit active (MaxOpenPositions) regardless of type of trade.
    Note that these limits are independent from global limit (MaxOpenPositions). This means that MaxOpenLong + MaxOpenShort may or may not be equal to MaxOpenPositions.
    If MaxOpenLong + MaxOpenShort is greater than MaxOpenPositions then total number of positions allowed will not exceed MaxOpenPositions, and individual long/short limits will apply too. For example if your system MaxOpenLong is set to 7 and maxOpenShort is set to 7 and MaxOpenPositions is set to 10 and your system generated 20 signals: 9 long (highest ranked) and 11 short, it will open 7 long and 3 shorts.
    If MaxOpenLong + MaxOpenShort is smaller than MaxOpenPositions (but greater than zero), the system won't be able to open more than (MaxOpenLong+MaxOpenShort).
    Please also note that MaxOpenLong and MaxOpenShort only cap the number of open positions of given type (long/short). They do NOT affect the way ranking is made. I.e. by default ranking is performed using ABSOLUTE value of positionscore.
    If your position score is NOT symetrical, this may mean that you are not getting desired top-ranked signals from one side. Therefore, to fully utilise MaxOpenLong and MaxOpenShort in rotational balanced ("market neutral") long/short systems it is desired to perform SEPARATE ranking for long signals and short signals.
    To enable separate long/short ranking use:
    SetOption("SeparateLongShortRank", True );
  • RefreshWhenCompleted - when set to TRUE, it will perform View->Refresh All after Automatic-Analysis operation (scan/exploration/backtest/optimize) is completed.
  • RequireDeclarations - when set to TRUE the AFL engine will always require variable declarations (using local/global) on formula-by-formula basis
  • ExtraColumnsLocation - allows the user to change the location of custom columns added during backtest/optimization.
    "extra" columns mean:
    a) any custom metrics added using custom backtester
    b) any optimization parameters defined using Optimize() function

    If both custom metrics and optimization parameters are present then custom metrics appear first then optimization parameters

    This function is provided to allow the user to change the default "at the end" location of custom columns/optimization parameters.
    For example:

    SetOption("ExtraColumnsLocation", 1 );

    will cause that custom metrics and opt params will be subsequently added starting from column 1 (as opposed to last column default)

    Note that this setting changes "visual" order of columns, not really in-memory order or export order, so exported data files or copy/paste format do not change.

  • SettlementDelay - this option describes the number of days (not bars) it takes for sale proceeds to settle and be available for opening new positions.

    SetOption("SettlementDelay", 3 ); // this will cause that proceeds from sale are only available for trading on 3rd day after sale

    For detailed tracking " Detailed log" report option now shows available and unsettled funds for T+1, T+2 and so on

    Note: when using this option it is recommended to use backtestRegularRaw instead of backtestRegular, otherwise some trades may not be entered because funds are not settled immediately and you need to be able to enter not on first but subsequent buy signals and that is exactly what backtestRegularRaw offers.

    Note2: old backtester (Equity() function) ignores settlement delay

  • StaticVarAutoSave - allow periodical auto-saving of persistent static variables (in addition to saving on exit, which is always done).

    The interval is given in seconds.
    For example:
    SetOption("StaticVarAutoSave", 60 ); // auto-save persistent variables every 60 seconds (1-minute)
    It is important to understand that persistent variables are saved ON EXIT automatically, without any user intervention so it should be enough for most cases. If you for some reason want auto-saves when AmiBroker is running, then you can use this function. Please note that writing many static variables into physical disk file takes time and it blocks all static variable access so you should AVOID specifying too small auto-save intervals. Saving every second is bad idea - it will cause overload. Saving every 60 seconds should be fine. Calling function with interval set to zero disables auto-save.
    SetOption("StaticVarAutoSave", 0 );
  • MCEnable - controls Monte Carlo simulation: 0 - disabled, 1 - enabled in backtests, 2 - enabled in backtests and optimizations
  • MCRuns - number of Monte Carlo simulation runs (realizations) default 1000
  • MCPosSizeMethod - Monte Carlo position size method: 0 - don't change, 1 - fixed size, 2 - constant amount, 3 - percent of equity
  • MCPosSizeShares - number of shares per trade in MC simulation
  • MCPosSizeValue - dollar value per trade in MC simulation
  • MCPosSizePctEquity - percent of current equity per trade in MC simulation
  • MCChartEquityCurves - true/false (1/0) - enables Monte Carlo equity chart
  • MCStrawBroomLines - defines number of equity lines drawn in Monte Carlo straw broom chart
  • WarningLevel - allows to change warning level. Level 1 is default for all AFL executions with exception of AFL editor and commentary where warning level is set to 4
    Warning Level
    1 - report only level 1 warnings (502- too much plots)
    2 - report level 1 and 2 warnings (above plus assignment within conditional, division by zero, threadsleep period too long)
    3 - report level 1, 2 and 3 warnings (above plus createobject/createstaticobject )
    4- report all warnings (default for the AFL editor)

WARNING: If you change the option on *per-symbol* basis the composite results (%profit for example) will be DISTORTED since calculations assume that OPTIONS are constant for all symbols in one backtest run. 'HoldMinBars', 'EarlyExit..." options are exception from this rule (i.e. can be safely set on per-symbol basis)

EXAMPLE SetOption("InitialEquity", 5000 );
SetOption("AllowPositionShrinking", True );
SetOption("MaxOpenPositions", 5 );
PositionSize = -100/5;
SEE ALSO EnableRotationalTrading() function , EQUITY() function

References:

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

More information:

See updated/extended version on-line.