System Flags

Zorro's behavior can be set up through system flags - that are internal "switches" that can be either set (activated) or reset (deactivated). By default, they are normally off. Flags that affect the overall behavior must be set in the initial run at start of the script; otherwise they can be set or reset at any point. Some flags are status flags and can be read only. Flags are set, reset, or read with the following functions:

set (int Flag1, int Flag2..., int Flag10)

Sets or resets the given system flags (up to 10). A flags is reset by adding |OFF to the flag name. For instance, set(PARAMETERS,TICKS|OFF); sets the PARAMETERS flag and resets the TICKS flag.

is (int Flag): int

Returns nonzero (or true) when the given system flag is set, otherwise zero or false

The main system flags:

SKIP1

SKIP2

SKIP3

Do not enter trades in the first, second, or third of every 3 weeks of the historical price data (the period can be set up with DataSkip). These flags can be used for out-of-sample testing by separating test data from training data while still covering the same time period. These flags must be set in the INITRUN.
 

PEEK

Allow peeking in the future through negative price function offsets; [Test] and [Train] mode only. Sometimes required for advise functions and price difference analysis.

NOLOCK

Don't synchronize the API and file accesses of multiple trading Zorro instances, to prevent that they interfere with each other. Set this flag for speeding up API access when the trading Zorros don't share the broker API, or when the broker API allows simultaneous sccesses from multiple sources (MT4/MT5 does not). This flag must be set in the INITRUN.

NOWATCH

Ignore all watch statements. Can be set for trading a script that is full of watches.

NOSHIFT

Do not shift dynamic series and do not change their first element on series() calls. Useful for shifting series only under special conditions, f.i. for emulating special bars.

NOFACTORS

Don't calculate OptimalF factors in test and training. Useful when OptimalF calculation takes a long time due to a large number of trades. For training script-generated factors with a user-defined algorithm, set both FACTORS and NOFACTORS flags and set OptimalF, OptimalFLong, OptimalFShort to a script calculated value in the FACCYCLE training run (if(is(FACCYCLE)) ...).

 

COMMONSTART

Delay the simulation until price history of all assets is available. Otherwise the simulation starts either at the StartDate or at the history begin of the first asset, whichever is later, and missing price history of other assets produce an Error 055 message. This flag must be set in the INITRUN.

OPENEND

Do not close the remaining open trades at the end of a simulation cycle; leave them open and ignore their results. This has two purposes. In [Test] mode it eliminates the effect of prematurely closed trades on the performance report. In [Train] mode it prevents that rules are affected by the results of those trades.

ALLCYCLES

Do not reset the statistics values inside the STATUS structs when a new sample cycle is started. The Long/Short statistics and the portfolio analysis are then the result of all sample cycles so far. Print any sample cycle to the log; otherwise only the last cycle is logged. This flag is always set in [Train] mode. This flag must be set in the INITRUN.
 

TICKS

Tick-precise intrabar simulation. This flag must be set in the INITRUN. If it is set, not only the Open, Close, High, and Low, but also the price curve inside any bar is evaluated for triggering entry, stop, trail, or takeprofit limits. TMFs are run on every tick in the simulation, instead of only once per bar. This flag gives a more accurate simulation result, but also requires more time for a simulation cycle, and allocates more memory.
  If this flag is not set, an intra-bar approximation is used for simulating entry and exit. In this approximation, a stop loss is always triggered earlier than a profit target, resulting in a slightly pessimistic simulation. Trades closed by TMFs are sold at the open price of the next bar. This less accurate simulation is sufficient in most cases, but TICKS should be used when trades enter and exit at the same bar, when stop loss, or takeprofit distances are small, or when trading is strongly affected by tick functions or TMFs.

LEAN

Use compressed historical data. marketVal and marketVol are not available, .t1 data is stored without bid prices, and the open/close price of a bar is approximated by the center point of its first and last tick (except for EOD historical data). Set this flag to reduce memory requirement when market volume is not needed or when the historical data has a much higher resolution than one bar period, f.i. M1 data with 1-hour bars. This flag reduces the memory requirement for backtests by 30%. It must be set in the INITRUN before calling asset().

LEANER

Use only the Close from historical price data; disregard Open, High, Low, and Mean. Indicators that require full candles, such as ATR or TypPrice, can not be used. This flag is useful for strategies with hundreds or thousands of stocks, and reduces in combination with the LEAN flag the memory requirement by 50%. It must be set in the INITRUN before calling asset().

RECALCULATE

Run a full LookBack period at the begin of every WFO cycle in [Test] mode. Discard the content of all series at lookback start, and recalculate them from the parameters and rules of the new cycle. Without RECALCULATE the series keep their values from the previous test cycle. RECALCULATE increases the test time, but simulates more realistically the start behavior of a new trade session. This flag must be set in the INITRUN

PRELOAD

In [Trade] mode, use Zorro's historical price data for the LookBack period, rather than loading price data from the broker's price server or from external data sources. If historical data is not sufficient for filling the complete lookback period, the remaining data between the end of the history and the current time is still loaded from the broker or data source. This flag is useful for reducing the start time of a system, for overcoming history limitations of broker servers, or for very long lookback periods. Recent price history files from the current and the last year must be available in sufficient resolution and preferably from the same broker or data source. Use the Download script or the assetHistory function for getting the most recent data. This flag must be set in the INITRUN.
  In [Test] mode this flag suppresses the warning message when the lookback period is too long for a normal trading session. It also causes historical data to be reloaded again for any simulation cycle, which allows cycles with different bar periods or with shuffled or otherwise manipulated price data for generating reality check histograms.
 

PARAMETERS

[Train] mode: generate strategy parameters with optimize calls and store them in Data/*.par. This flag must be set before calling optimize. If this flag is not set, parameters are not generated in the training run, but still loaded from previously generated *.par files.
[Test] / [Trade] mode: load optimized parameters. If this flag is not set, the default parameters from the optimize calls are used.

FACTORS

[Train] mode: generate OptimalF capital allocation factors and store them in Data/*.fac. [Test] / [Trade] mode: load OptimalF factors for allocating capital. If this flag is not set, all OptimalF factors are 1.
OptimalF factors are normally generated from the whole backtest period. For generating them individually per WFO cycle, use the ALLCYCLES training mode.

RULES

[Train] mode: use the advise machine learning functions to generate trade rules or machine learning models, and store them in Data/*.c or Data/*.ml. This flag must be set before calling advise. Otherwise rules or models are not generated, but loaded from previously generated *.c or *.ml files.
[Test] / [Trade] mode: load trade rules or machine learnign models and use them in the advise functions. If this flag is not set, the advise functions always return the value 100.
  

MARGINLIMIT

Don't enter a trade when even the minimum amount of 1 Lot exceeds twice the used Margin value, or when the trade margin plus the trade risk exceeds the account balance. Trades skipped due to too-high risk or too-low balance are indicated in the log. This flag has no effect in training mode or for phantom trades that are always executed regardless of the margin.

RISKLIMIT

Don't enter a trade when even with the minimum amount of 1 Lot, the trade risk is still higher than twice the than the allowed Risk. Also don't enter a new trade in [Trade] mode when the total risk of all open trades exceeds the available margin left in the account. Setting this flag can reduce profit, as trades with a high stop loss distance are often profitable trades. Trades skipped due to too-high risk or too-low account are indicated in the log. This flag has no effect in training mode or for phantom trades that are always executed regardless of the risk.

ACCUMULATE

Accumulate the Margin of trades skipped by MARGINLIMIT or RISKLIMIT, until the accumulated margin is high enough to overcome the limits. The trade is then executed and the accumulated margin is reset. This allows trading - although less frequently - with very small capital that would result in trade sizes of less than one lot. This flag has no effect in training mode.
 

BINARY

Simulate binary options for training and testing. This flag must be set in the INITRUN. In binary mode the trade profit is not proportional to the price difference between entry and exit, but determined by the WinPayout or LossPayout of the selected asset. The stake can be set with the Margin variable for the backtest (live trading might require setting the stake with the Lots variable or with an order comment, dependent on the broker). Rollover and commission are ignored for binary trades. Spread is 0 by default in binary mode, but can be set to a nonzero value for simulating an additional disadvantage. The trade time can be set through ExitTime. Stop loss and profit targets are normally not set for binary trades, but can be used for betting on negative or positive excursions in special binary modes. Hedging should be enabled by Hedge = 2 for preventing the premature close of opposite trades.

NFA

Activate NFA Rule 2-43(b) compliant trading; required for most US based brokers, such as IB. Zorro handles NFA compliant trading in a transparent way, so the user and the script normally need not care about NFA complance. When this flag is set, the following NFA restrictions are observed:

The NFA flag must be set in the INITRUN. It is automatically set when the selected account has a nonzero NFA parameter in the account list. Do not set this flag for non-NFA compliant accounts. You can find out if your account is NFA compliant by manually opening a long and short position of the same asset in the broker platform. If two positions are then really open, your account is not NFA compliant and you must not set the NFA flag. If the short position cancels the long one, your account is NFA compliant and the NFA flag must be set. MT4 accounts are normally not NFA compliant even when the broker is located in the US; but they can be FIFO compliant and require exiting trades in the order of their entry.
 

EXE

Do not run the simulation, but compile the script to an executable in .x file format. Executable scripts start faster and can be used for distributing strategies without revealing the source code. If a .c and a .x script with the same name are found in the Strategy folder, the .c script has priority. Zorro S required. The EXE flag must be set in the INITRUN; it can also be set by command line or with the [Action] scrollbox.

STEPWISE

Do not run, but single step through the simulation in [Test] mode. A click on [Step] moves one bar forward. [Skip] moves to the next opening or closing a position. The current chart and trade status will be displayed on every step in a browser window. For details see debugging.
 

LOGFILE

Generate and export logs and statistics files in the Log and Data folders, dependent on [Test], [Train], or [Trade] mode. This flag affects the backtest speed.It is always set in [Trade] mode. When LogNumber is set, the number is appended to the filenames. This flag must be set in the INITRUN.

BALANCE

Use balance rather than equity for the profit curve in the chart, for the monthly profit table in the performance report, and for the values in the exported profit/loss curves. This flag must be set in the INITRUN.

PIPRETURN

Use volume-independent returns in pip units for the profit curve in the chart, for the monthly profit table in the performance report, and for the values in the exported profit/loss curve. This flag must be set in the INITRUN.

MAECAPITAL

Do not calculate the required capital, annual return, and the 'underwater profile' on the chart from maximum drawdown, but from maximum adverse excursion (see performance report for the difference). This is for comparing with results of other platforms and normally produces slightly higher required capital. This flag must be set in the INITRUN.
 

TESTNOW

Run a test immediately after training, without clicking [Test]. Only when multiple cores are not used and when test and training use similar mode flags. If the simulation is repeated multiple times (NumTotalCycles), TESTNOW causes the price curve to be generated anew at the begin of every cycle, which is useful for testing different bar offsets or detrend modes. Since the test run uses the settings from the previous training, its result can differ from a normal test. This flag must be set before calling asset(). This flag must be set in the INITRUN.

PLOTNOW

Plot a chart immediately after testing, without clicking [Result]. Automatically set when the script plots a histogram with plotBar. This flag must be set in the INITRUN.

 

Remarks

Example:

function run()
{
  if(is(TRAINMODE)) set(SKIP3);
  if(is(TESTMODE)) set(SKIP1,SKIP2,TICKS,FAST,LOGFILE); 
  ...
}

See also:

DataSkip, Status flags, setf, Zorro.ini

 

► latest version online