Trading a strategy

Click [Trade]. Zorro will connect to the broker and start spending your money. This happens in several steps:

While trading, Zorro will detect when the .par, .c, .fac or .ml files that contain the parameters, rules, capital allocation factors, or machine learning models are updated by a re-training process. In that case they are automatically reloaded at the begin of the next bar period. It is recommended to retrain strategy parameters and rules regularly (see WFO) for taking care of market changes. This is especially required for parameter-free strategies that have been walk-forward optimized.

The Status Window displays the broker server date and time shifted to UTC, and the current price of the asset selected with the [Asset] scrollbox if that asset is also used in the strategy (otherwise its price is not available). The tiny square at the right is green when connected to the server, and red when the connection was lost or no data was received within 100*TickTime. The update interval of the server window depends on TickTime and the server response time. Arriving price quotes are indicated with a blinking asterisk. If the price is unavailable - for instance because the selected Asset was not used in the strategy -  "XXXXX" is displayed instead. "Closed" indicates that trading is currently suspended due to the BarMode and market time settings of your script and asset list, or because the broker server is currently in market close state. "Out of sync" indicates a discrepancy of server time and PC time. Check if the displayed time is the correct UTC time. The broker server and your PC need not be in the same time zone, but their clocks need to be correctly set up to their local time.

The left segment of the Progress Bar in live trading indicates the closed profit of the strategy since starting it, the right segment indicates the total profit or loss of all open trades (including phantom trades). When the right segment is green, your trades are in the profit zone; when the left segment is green, your account is in the profit zone. Otherwise the segment is red.

The Result Window below displays information about the account and profit situation, in the following form:

 4567  +1412  +50  !/\\' 

4567 Current equity, the sum of balance and value of all open trades of the account.
+1412 Money earned (or lost) by the strategy since the start, in account currency units.
+50 Current open trade value of the strategy, in account currency units.
!/\\' Current trades. ! is a trade with locked profit, / a winning, \ a losing, and ' a pending trade.

The Trade Status Page (see below) gives the most detailed view into the current account and trade situation. Note that Zorro displays prices as ask prices and profits/losses including commission, rollover, and spread, so the live values on the Zorro panel might look slightly different than the values in your trading platform for the same trades.

When something happens during a trading sessing, like the start of a new bar or opening a trade, Zorro prints a message in the message window and records it in the .log file that can be opened with any text editor. Details about Zorro's log files can be found in the Log chapter. 

Some trading restrictions apply to the free Zorro version. If you see in the Result Window that your equity has grown above the allowed limit, withdraw the excess profits from your account.

Trade status, chart and trade log

While trading, a HTML page named after the script and asset (f.i. MySystem_EURUSD.htm) in the Log folder displays a list with the live status of all open trades, a chart with the equity curve, and the current performance statistics. This document is generated when prices are available. Prices and trades automatically update once per minute, the chart once per hour. It can be displayed with any web browser. The HTML style can be changed by editing Source\status.htm and Source\zorro.css. When trading on a VPS, the HTML document can be stored in the server's public web folder (see WebFolder) for observing the current trade status via Internet on your PC or mobile phone. An instruction for setting up a VPS to display your trade status on the Internet can be found under Brokers.

The top of the trade status page contains information about the session start, the last update, the last drawdown depth and CBI, and the last warning message that required a follow-up, such as suspicious asset parameters (054) or potentially orphaned trades (070).

In the list, phantom trades in {..} winged brackets and pending trades in (..) parentheses. ID is the identifier assigned by the broker API. Entry is the fill price, Price is the current price. Stop, Trail, and Target are the 'real' stop / trail / takeprofit limits set by the script (the 'safety net' Stop Loss in the broker platform has normally a different value and is not used for the stopping the trade). Pool trades have no 'real' stops, therefore nothing is shown in that column.  Risk is the maximum possible loss when negative, and the minimum possible profit of the trade when positive. Profit is the current profit or loss, retrieved from the broker API for real trades, or calculated (including spread, rollover, and commission) for phantom trades. Pips is the volume-neutral profit or loss in pips. Due to slippage or lack of liquidity, trades can always close with a worse result than projected under Risk and Profit. Dependent on the broker plugin and on SET_PATCH parameters, the displayed entry or exit prices are not the open and close prices of the trade, but the market prices at trade entry or exit, which can slightly differ. While Zorro always records ask prices in the log, the entry and exit prices in the spreadsheet follow the usual notation of ask or bid prices dependent on trade type.

The displayed phantom lots do not necessarily sum up to the pool lots. The list can also contain phantom trades for the purpose of equity curve trading that do not contribute to the pool trades.

Below the trade list, a chart with the current price and the equity or balance curve is displayed in the status page. The chart is updated on every bar or every hour, whichever is least frequent. The update interval and further properties of the chart, such as indicator lines, colors, scale etc. can be set up in the script. If a different chart in [Test] mode is required, different chart properties can be set up with the conditions if(Live) or if(Test).

When the [Result] button is clicked and no specific action was assigned to that button, a chart and a performance report is immediately created in the Log folder, and a list of all open trades with entry, current, and stop prices and current profit/loss is also printed in the message window. The message window content is stored in the log file, so any event is recorded for later evaluation.

All closed trades are separately recorded in a CSV spreadsheet (see Data Export) for further evaluation or statistics. The spreadsheet can be read back by Zorro for simulating a test with real trades generated by another platform; the Simulate script can be used for that.  !!  Take care not to keep the trade spreadsheet open in Excel while Zorro is trading. Excel prevents any other program from accessing that file.

Normally, all trades statistics are reset at the begin of a session. They can be continued from the previous session when they were saved with setf(SaveMode,SV_STATS).

Manually closing trades

Normally you should refrain from tampering with the strategy, as it is (hopefully) already optimized and any manual intervention will most likely reduce the performance. Still, in some situations you might want to close individual trades, or lock an individual profit by placing a stop loss. You can do this directly in the broker platform. If supported by the broker API, Zorro will detect when a trade is manually closed, and also close it internally.

For closing all open trades in case of an emergency, click [Stop]. You'll then be asked first if you want to close all trades or not, and afterwards if you want to stop trading or not. Click first [Yes] for closing all trades, then [No] for continuing trading. All trades opened by this strategy will be closed; other open trades are not affected. If trades cannot be closed for any reason (the market is not open or there is no connection to the broker), they stay open, and must then be manually closed.

NFA compliance

US based accounts are restricted by NFA Compliance Rule 2-43(b). The rule requires that trades are served in a first-in, first-out order. You can not hedge positions or have more than one position per asset, you can not place stop loss or profit targets, and you can not close trades. Instead of closing a position, a new position must be opened in opposite direction. You're also not allowed to open more than 4 trades per week, dependent on your account deposit. All those restrictions are well-meant and intended to prevent US citizens from losing their money and suing their brokers (of course they do nevertheless).

Zorro can step around NFA restrictions - except for low leverage, unsupported assets, and limited trades - when the NFA flag is set. It must normally be set for US based accounts, except when trading through MT4. It must not be set for all other accounts. If it is set wrongly, you'll get error messages like "!Can't close trade" on US accounts, and you'll get a massive number of open trades on non-US accounts as no trade is ever closed. So make sure that you know whether you live in the US or not.

Stopping and resuming a live trading system

While trading, Zorro stores the currently open trades, the status of the sliders, and component specific variables (AlgoVar) in a .trd file in the Data folder. This way trading can be stopped and resumed without losing track of open trades. The name of the file is composed from the script name plus the selected asset plus a "_d" in case of a demo account. If a trade can not be resumed - for instance when it was externally closed - an error message will be printed at restarting the trading session, and Zorro will resume the other trades. Because any new trade overwrites the .trd file, its previous content is stored in a .bak file at session start. Trades are not resumed when the session has no lookback period and opens trades already in the first run.

The content of any .trd file can be loaded with loadStatus. For looking into its open trades, you can use a short script like this:

function run()
  if(Bar >= 1) {

After a test run of this script, the open trades are printed in the HTML status page.

For migrating a live trading system to a different PC or VPS, stop trading without closing the open trades, then copy the whole Zorro folder over to the new PC. Open Zorro and start trading on the new PC. Slider settings and open trades will be resumed.

 !!  The .trd file can be simply copied over to the Data folder of a different Zorro installation for continuing the session from there. When stopping a trade session and starting a new session with the same script on a different broker or account, make sure to delete the .trd file so that open trades from the last session are not resumed with the new account or broker. This is especially important with an NFA account, since there is no way to automatically determine if trades were opened or closed on such an account.

Updating to a new software version

If strategy and .trd file format are unchanged in the new version:

If according to What's New the strategy or file format were changed:

If you want to run the old and new version a while in parallel:

Please read the What's New page for checking if the strategy or .trd format have changed, or if further actions are required for resuming sessions.

Trading without a broker

It is sometimes desired to run a Zorro script in [Trade] mode with no broker connection, for instance when prices are received from online price sources and when trades are not directly sent. For this the Offline plugin can be used. Alternatively, a live broker connection can be simulated with the Simulation plugin that's available in the Source folder. 


While trading, Zorro S can re-train the system in regular intervals for adapting it to the current market situation. For comparing live with backtest results, it can also automatically run a backtest over the previous live trading period. For details see Retraining and Retesting.

Multiple accounts, multiple instances

The free Zorro version can only trade with a single Zorro instance. Zorro S is licensed to trade with multiple Zorro instances, brokers, and accounts simultaneously, either on the same PC or on several PCs or servers. Zorros trading on the same PC are automatically synchronized. That means that any instance waits until the other instance has finished its current task, such as sending an order or retrieving a price quote. This synchronization allows to trade even with a broker API that does not support many simultaneous connections, but it can also lead to long response times of the user interface, especially when lenghty operations - for instance, downloading large price histories - are performed on the same PC on which other Zorros are live trading. For preventing synchronization, set (on your own risk) the NOLOCK flag in the script.

When trading the same script on several Zorro instances, make sure to either copy the script to different names, or run it from different Zorro installations. Otherwise the Zorro instances would write into the same status, .log, or .trd files, which can cause undesired behavior such as garbled log files or 'deadlock' situations.

For trading with the same Zorro instance on multiple accounts of the same broker, make a copy of the broker plugin under a different name, and use it to define different assets for the different accounts. The procedure is described under Broker Arbitrage.

If you have several accounts with different brokers, you can use the ZStatus script for displaying the status of all accounts on a single panel (Zorro S required). Put your accounts in an account list, then enter the names as they appear in the scrollbox to the BROKERS definition at the begin of the script. Set NUM_BROKERS to the number of accounts you want to observe. If the accounts are in different currencies, you can set up conversion factors in the Convert array. Start the script in [Trade] mode. It will connect to your accounts in 1-minute intervals and display the profit since start, the profit of the last 2 days, the account value, the balance, the open trade value, and the total margin on a panel. Profits are displayed in green when positive, red when negative.

Note that with some brokers, such as IB, you'll need to add a dedicated user to your real money account for observing the account status, since you cannot run multiple sessions with the same user.

Switching or updating strategies

Zorro updates come out every couple of months, normally with improved versions of the Z strategies. When developing your own strategies, you'll also often get new ideas and improve the script so that is generates a few pips more than the previous version. For the transition of a live trading system from the old version to a new Zorro and/or strategy version, you have several options:

Errors and crash recovery

Zorro is designed to trade without human intervention. However, for keeping a program running for months and years, some special precautions are necessary. Obviously you should not switch off the active trading PC - not even in the interest of energy saving. Set the PC energy settings accordingly. Disable automatic Windows updates, as they normally reboot the PC. Look here for how to automatically restart a session if a reboot still happens. Screen savers won't harm.

Zorro will display an error message when the broker can not open or close a certain trade. There can be many reasons for this, such as an interruption of the connection to the broker, a server failure, lack of liquidity, or a closed market. If a trade was not opened, it is up to the script to cancel the trade or retry. If a trade can not be closed, Zorro will automatically close it again in regular intervals until the market opens or liquidity is available. If the close command repeatedly fails because the trade is unknown to the broker, Zorro will assume that it was already closed, stop the close attempts, and remove it from its internal trade list.

If you trip over the power cable, or if the broker's server goes offline, Zorro gets temporarily disconnected from the trade session. This can regularly happen on Saturdays due to broker server maintenance. It is normally no reason to worry: the session will continue automatically when the connection is established again. While disconnected, no prices are received, no bars are created, and Zorro cannot react on the market. If the situation persists, the colored square next to the server window will change from green to red, and the time in the server window will switch from server time to PC time. Zorro will then start reconnection attempts in increasing intervals, until the connection is established again. Any reconnection attempt prints a dot to the message window. Since there is no price data during the interruption, prices can suddenly jump to their current value at reconnecting. This might affect indicators. Trade strategies should consider disconnections when they are programmed to react on price jumps.

If the connection to the broker server cannot automatically be reestablished for some reason, click [Stop], then click [No] for not closing open trades and [No] for continuing trading. Zorro will then log out, close and re-open the broker API library, then log in again. This solves problems with a 'hung' broker interface or API.

If Zorro terminates due to a PC breakdown or software crash, start it again and click [Trade]. Zorro will then read its last trade state from the .trd file (see above) and continue trading at the point where it was shut down. The continued trades are displayed in the message window (f.i. [AUD/USD:CY:S4400] continuing...]. If you see an error message instead, a particular trade could not be continued. It might have hit a stop loss and been closed by the broker inbetween. For checking, open the broker's trade platform and compare the ID numbers of the open trades to the trades continued by Zorro.

If the PC is malfunctioning and you have to continue trading on a different PC, install Zorro there and then copy the *.trd file from the old to the new Zorro installation. Zorro will then resume the open trades on the new PC.

If a connected broker API or program, such as MT4, crashed due to a serious software or PC fault, it can become unresponsive and Zorro can appear 'frozen'. The safest way to resolve that is closing MT4, closing Zorro, rebooting the PC, then starting MT4 and Zorro again. If possible, find out the reason of the crash and fix it,

See also:

Bars, mode, log, testing, training, TradeMode ► latest version online