Zorro's behavior can be set up through mode flags - that are "switches" that can be either set to on (active) or off (not active). Mode flags can be set, reset, or tested with the following functions:
set (int Flag)
Sets the given system flag or all flags of the given system flag combination.
Flags can be combined with the '+' or '|' operator. For instance, set(PARAMETERS+TICKS);
sets the PARAMETERS flag and the TICKS flag.
reset (int Flag)
Resets the given system flag or all flags of the given system flag combination.
mode (int Flag): int
Returns nonzero (or true) when the given system flag (or any flag of the given flag combination) is set, otherwise zero or false.
The following system flags are available for set,
reset, and mode:
Do not enter orders in the first, second, or third of every 3 weeks of the historical price data (the period can be set up with DataSkip). This can be used to separate out of sample price data from training data while still covering the same time period.
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
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.
Required capital and annual return are calculated not from maximum drawdown, but
from maximum adverse excursion (see performance report
for the difference). This normally produces slightly higher capital and lower
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. This flag is always set in [Train] mode.
Tick-precise intrabar simulation. If this flag 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; to be combined with TICKS. Ticks are then sorted by asset and by trade before executing them in a tick function or TMF. This can remarkably speed up backtests in TICKS mode, but implies some restrictions, as ticks can now arrive in a different order than their time stamps. In FAST mode TMFs must not use information from other trades or evaluate trade statistics, otherwise peeking bias can affect the result (for instance when a trade is closed by the TMF dependent on the win/loss situation of another trade). For the same reason, tick functions must not evaluate prices of other assets. Virtual hedging is simulated in FAST mode with restricted accuracy, so it's recommended to disable it in the simulation whe results strongly depend on tick order.
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 50%.
It must be set 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.
Use Zorro's historical price data, rather than loading price data from the broker's price server
or from external data sources. For filling the LookBack period at [Trade]
start, the data span between the end of the history and the current time is loaded from the
broker or data source. This flag is useful for reducing the trading 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; use the Download script for getting the most recent data. Setting this flag also suppresses the warning message in [Test] mode when the lookback period is too long for a normal trading session.
Don't synchronize multiple trading Zorro instances. Synchronization prevents simultaneous API access, but freezes all Zorros while a single Zorro waits for a response from the API. Set this flag for speeding up API access when the trading Zorros don't share the same
broker API, or when the broker API supports multiple simultaneous connections.
[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 causes trades to be entered - although less frequently - that would otherwise require a higher margin for ever being executed.
This flag has no effect in training mode.
Simulate binary options for training and testing. In this 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 place a "safety net" hard stop loss limit when sending the trade to the broker (this does not affect the Stop parameter that is handled by software). Do not close broker positions, 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 often 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 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 MT4 accounts are
often not NFA compliant even when broker and the account owner are located in
Compile the script to an executable in .x file format. Useful for a faster start, and for distributing strategies without revealing the source code. Zorro S required.
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.
Display the balance curve in the chart, and store balance rather than equity values in the exported profit/loss curve.
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().
Plot a chart immediately after testing, without clicking [Result]. Automatically set when the script plots a histogram with plotBar.
DataSkip, Status flags, setf,
► latest version online