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:
Sets the given flag resp. all flags of the given flag combination.
Flags can be combined with the '+' or '|' operator. For instance, set(PARAMETERS+TICKS); activates the PARAMETERS flag and the TICKS flag.
Resets the given flag resp. all flags of the given flag combination.
mode(int flag) : int
Returns nonzero resp. true when the given flag (or any flag of the given flag combination) is set, otherwise zero resp. false.
The following mode flags are available:
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.
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 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 simulation. Not only the Open, Close, High, and Low of a bar, but also the real price curve inside a bar is used for calculating entry, exit, and profit of trades. 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 before a profit or trail target, and trades closed by trade functions are sold at the open price of the next bar. This causes a less accurate simulation, which is however sufficient in most cases. TICKS should be used for better precision when many trades enter and exit within the same bar, when stop loss or takeprofit distances are small, or when tick functions or TMFs are used.
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, 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. This increases the test time, but produces a slightly more realistic test by simulating the start of a new trade session at every WFO cycle.
Use Zorro's historical price data for the LookBack period at [Trade] start, rather than loading all price data from the broker's price server. Only the data span between the end of the history and the current time is loaded from the server. 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. Alternatively, data can be downloaded at trading start from different sources such as Yahoo or Quandl. Setting this flag also suppresses the warning message in [Test] mode when the lookback period is too long for a normal trading session, and causes prices to be loaded from the broker even outside market hours.
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 API.
Single step through a session 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.
[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 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 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.
Observe 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. Zorro will handle NFA compliant trades 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 normally not NFA compliant even when the account owner is US citizen.
Compile the script to an executable in .x file format. Useful for distributing strategies without revealing the source code. Zorro S required.
Generate the following files in the Log folder, dependent on [Test], [Train], or [Trade] mode: a *.log file containing all trade events and messages; a *.dbl file containing a var array of the daily balance or equity values from the backtest; a *.csv file containing a record of all closed trades for further evaluation or the tax declaration; a *.htm file containing the last trade status; and a *.htm file with parameter charts from the training process. The file names are composed from the script and asset name. This flag is always set in [Trade] mode.
Display the balance curve in the chart, and store balance rather than equity values in the *.dbl array resp. in the Curves file.
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, PlotMode, Zorro.ini
► latest version online