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:




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.


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


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.


Ignore all watch statements. 


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.


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.


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.


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.


Fast simulation mode. This flag must be set in the INITRUN. Ticks are not sorted by their time stamps, but by asset and by trade. This can remarkably speed up backtests, but can generate a less accurate result and peeking bias. In FAST mode the script must take care that TMFs use no information from other trades or from global statistics, since that would be peeking into the future. FAST mode should not be used when it causes strongly different results or when stop, take profit, or entry limits, TMFs, tick() functions, or virtual hedging is used. Backtest a strategy first with and without FAST and compare the results. 


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 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().


Use only the Close from historical price data; disregard Open, High, Low, and Mean. 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% when candles are not needed. It must be set in the INITRUN before calling asset().


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


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 extremely long lookback periods. Recent price history files from the current and the last year must be available in sufficient resolution; use the Download script 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 price data to be reloaded at the begin of any simulation cycle, which allows test cycles with shuffling or otherwise manipulating the price data for generating reality check histograms or other statistics.


[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.


[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.


[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.


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 available margin left in the account. Trades skipped due to too-high risk or too-low account capital 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.


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 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.


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.


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

The NFA flag must be set in the INITRUN. It is automatically set when the selected account has a nonzero NFA parameter. 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. 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..


Do not run the simulation, but compile the script to an executable in .x file format. Compiled scripts start faster and can be used for distributing strategies without revealing the source code. Zorro S required. This flag must be set by command line or in the INITRUN


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.


Generate various log and statistics files in the Log folder, dependent on [Test], [Train], or [Trade] mode. This flag is always set in [Trade] mode. When LogNumber is set, the number is appended to the log filename. This flag must be set in the INITRUN.


Display the balance curve in the chart, and store balance rather than equity values in the exported profit/loss curve. This flag must be set in the INITRUN.


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.


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.


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.




function run()
  if(is(TRAINMODE)) set(SKIP3);

See also:

DataSkip, Status flags, setf, Zorro.ini


► latest version online