System Flags

Zorro's behavior can be set up through flags - that are internal "switches" that can be either set (activated) or reset (deactivated). By default, they are off. Flags must normally be set in the initial run at start of the script since they affect the overall behavior, but some can be set or reset at any point. 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 following system flags are available:




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.


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 any open trades at the end of a simulation cycle; 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 results of prematurely closed trades.


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.


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. For filling the lookback period at session start, the data span 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.


Don't synchronize multiple trading Zorro instances. Synchronization prevents simultaneous API access by putting API calls from all Zorros in a queue. Set this flag for speeding up API access when the trading Zorros don't share the same broker API. This flag must be set in the INITRUN.


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


[Train] mode: generate OptimalF capital allocation factors and store them in Data/*.fac. If this flag is not set, all OptimalF factors are 1.
[Test] / [Trade] mode: load OptimalF factors for allocating capital. If this flag is not set, all OptimalF factors are 1.
OptimalF factors can alternatively be copied from the performance report. For this, leave Margin and Risk at default settings and set Lots to 1, then do a [Test] run. Save the portfolio part of the performance report under the name of a .fac file.


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


Only when Margin is used for determining the trade volume: Don't enter a trade when even the minimum amount of 1 Lot exceeds twice the given Margin value. Also don't enter a new trade in [Trade] mode 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. 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.


Apply a technical workaround for NFA Compliance Rule 2-43(b); often required for US based accounts or US based brokers such as IB. Do not attempt to send close orders to the broker, open a new position in opposite direction instead; do not hedge broker positions, use virtual hedging instead if required. Although the compliance rule is intended mainly for Forex brokers, NFA compliance is not limited to it. NFA compliant brokers do normally not store individual trades, but only positions. Zorro will handle NFA compliant trading in a transparent way so that the user and the script does not need to care about the NFA rule.
This flag must be set in the INITRUN. It is automatically set in [Trade] mode when the selected account has a nonzero NFA parameter. Do not set this flag for non-NFA compliant accounts, as positions then could not be closed. 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. If the short position cancels the long one, your account is NFA compliant. Note that MTR4 accounts are often not NFA compliant even when broker and the account owner are located in the US.


Do not run a 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.


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.


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