Debugging Strategy

From FxCodeBaseWiki
Jump to: navigation, search

Start Debugging Session

To start debugging your strategy, in the Integrated Lua EditorDebugger dialog box on the "File menu", point to "Open", and then click "File". The Open dialog box appears listing all available indicator and strategy files. Select the strategy you wish to debug and click "Open". Note that to debug a standard strategy, you need to move it to the folder of user strategies. After you have started the debugging session, the Init() function of the strategy starts being executed step-by-step. You can run this function, only do not forget to place a break point in your Prepare() or Update() function to break the execution of the strategy while entering its parameters.

Strategy Parameters

Once the execution of the Init() function is completed, the Parameters dialog box appears.

Luadebugging6-123.png

The first two groups of parameters are used for configuring the debugging session. All other groups are used for configuring strategies.

Simulation Parameters

Parameters Dialog

The simulation parameters allow configuring the market to be simulated during the debugging session.

Luadebugging6-0.png
Instruments

The parameters allow configuring the market to be simulated during the debugging session (see the picture below). The first three parameters of the group, First Instrument Price Source, Second Instrument Price Source, and Third Instrument Price Source, allow to add up to three instruments to simulate tick prices. They are added by specifying a price source of either of the three parameters. To specify a price source, point to an instrument's value field and click the ellipsis button (...).

The Choose Price Source dialog box appears:

Luadebugging6-1.png

Click Quotes Manager, and from the drop-down list that appears, select the instrument of your choice. In the From and To windows, specify the data range, and then click OK. Note that you can avoid using the quotes manager by clicking Don't use the price source. The following rules apply to price sources:

  • Every instrument must use its own data range.
  • All data ranges must begin at more or less same time.

The quotes manager uses the server to download the quote data of the selected instrument and data range. The data is downloaded fast enough. Loading of a whole year of one-minute data (approx 300K candles) usually takes less than 30 seconds. Wait while the data is being loaded.

Luadebugging6-3.PNG

After the data is loaded, to add one more instrument, repeat the procedure with another parameter if necessary. We know that strategies can trade on any number of instruments but are activated (the Update() function is called) only for one instrument. Thus, if more than one instruments are specified, you have to choose which of them is to be used to activate the strategy. The Update() function of the strategy is called only when a tick of this instrument is simulated. The function is NOT called by the ticks of other instruments. The other parameters of the group, Chart Price Type, Open Price Mode, and Show Volume, are self-explanatory.

Trading Parameters

The parameters allow configuring the account and trading rules to be simulated during the debugging session (see the picture below).

Luadebugging6-31.PNG

The Account Currency parameter allows to specify the currency of the simulated account. If the account currency is not specified and its value field is empty, the base currency of the first instrument is automatically used as the account currency. If the account currency is specified, it affects the way the instruments are added:

If the account currency is specified, it may affect the order of adding the instruments:

  • The base currency or the counter currency of the first instrument that you add must be the same as the account currency.
  • The base currency or the counter currencyof the second and third instruments that you add must be the same as the account currency or as any currencies of the first instrument.
Example 1
The first instrument is EUR/USD.
If the account currency is not specified, USD will be used by default. The account currency may be either EUR or USD.
Example 2
You want to have an account in USD but run the strategy on GBP/JPY.
Select the first instrument as USD/JPY and then add GBP/JPY. Then run the strategy on the second instrument.
Example 3
You want to have an account in USD and simulate trading on GBP/JPY, EUR/USD, and GBP/USD.

The first instrument must be GBP/USD because either of its currencies is the account currency, or currency included in the other two instruments. The selection order of these two instruments is irrelevant.

The Are closing orders allowed? parameter specifies whether the close, stop, and limit orders can be used or not, and the Is hedging allowed? parameter ̶ whether opposite positions (buy and sell) can be opened simultaneously for one and the same instrument or not. If the parameter's value is False, a new market order first closes existing opposite positions (beginning with the oldest one) and then opens a new position only if the remaining amount is sufficient.

The trading systems located in different countries and run under different regulations may have different permissions for certain operations. By using these two parameters you can match almost all existing markets.

The trading systems located in different countries and run under different regulations may have different permissions for certain operations. By using these two parameters you can match almost all existing markets.

  • UK, with hedging ̶ hedging is allowed, closing orders are allowed.
  • UK, without hedging ̶ hedging is not allowed, closing orders are allowed.
  • US (or FIFO, NFA-regulated) ̶ hedging is not allowed, closing orders are not allowed

The Non-slippage mode parameter allows to specify whether the non-slippage mode is used or not.

The Initial Amount parameter allows to specify the amount funds in the account currency initially allocated to the simulated account.

The MMR parameter allows to specify the amount in the account currency to be allocated as used margin per one lot of a contract. In the Trading Station, the value is provided in the MMR column of the Simple Dealing Rates table.

The Lot Size parameter allows to specify the size of one lot of a simulated instrument. The amount of all positions and orders must be multiple of the lot size. The lot size is always expressed in the base currency of an instrument. For example, if the instrument is USD/JPY, the parameter's value is expressed in USD, if the instrument is EUR/USD, the parameter's value is expressed in EUR, and so on.

The Lot Size and MMR values must be balanced with each other. For example, the MMR value of 5,000 and the Lot Size value of 100 correspond to the 1:50 leverage approximately.

Chart Parameters

The parameters are used for configuring the appearance of the chart that displays the debugging session results (see the picture below).

Luadebugging6-32.PNG

The Chart Timeframe parameter allows to select the size of the chart's timeframe. The chart is always drawn with the help of bars, therefore, the timeframe has to be specified. The data for a chart is collected from the tick log of the strategy and its timeframe may differ from those of the price source and strategy. Thus, select the Chart Timeframe value in accordance with the timeframe of the price source and strategy. The common rules are:

  • The chart timeframe must be same as that of the price source.
  • The chart timeframe must never be smaller than that of the strategy.

The timeframe values may vary. On data ranges of similar sizes, greater timeframes result in a faster execution of the simulation session (fewer ticks need to be simulated and the Update() function is called less frequently), whereas smaller timeframes produce more precise market simulation.

The Equity Line Color and Balance Line Color parameters are self-explanatory.

The Show Equity/Balance Area parameter allows to specify whether Equity/Balance Area should be displayed or not.

The Equity/Balance High/Low Channel Transparency parameter is self-explanatory.

The Buy Sign Color, Sell Sign Color, and Font Size of Buy/Sell Signs (in points) parameters allow to specify the color and font size of the arrows that appear over the bars when a sell or buy order is executed during the simulation.

Debugging Strategy

When a strategy is initialized, the debugger starts simulating ticks for one or more instruments in accordance with the values specified in the Parameters dialog box. When the tick of the selected instrument is simulated, the Update() function of the strategy is called.

In addition to the debugging output and watches (see Lua Debugging), the following information is provided:

  • The strategy tick log (the Streams tab).
  • The strategy results displayed on a chart (the Chart tab).
  • The strategy statistics ( the Statistics tab).
  • The content of all trading tables (the Stack, Offers, Accounts, Orders, Trades, Closed Trades and Summary tabs).

This information is updated every time the debugger is stopped by a break point or a step-by-step execution mode.

Strategy Tick Log

The log is shown on the Streams tab. It contains all simulated ticks . The entry of every tick provides the following data:

  • Offer
  • The date and time of the tick
  • The bid and ask price
  • All events of the strategy (order creation, alerts, trades)
  • The equity and balance on the tick

If you need to find quickly the rows that contain certain events, use the following commands: Debug->Find Previous Action in Tick Log or Debug->Find Next Action in Tick Log


Luadebugging8.png

Strategy Statistics

The strategy statistics is shown on the Statistics tab and reflects the overall performance of the strategy (see the picture below).

Luadebugging9.png

Chart

The chart is shown on the Chart tab of the debugger and displays the strategy results in a graphic form.

On the chart, the strategy's instrument prices , are presented with the help of bar of certain timeframes. The red arrows indicate that at least one Sell order has been executed. The arrows point to the average weighted price of all Sell orders executed during this bar. The green arrows indicate that at least one Buy order has been executed. The arrows point to the average weighted price of all Buy orders executed during this bar.

Below the price chart, the equity and balance chart is provided. The lines indicate the equity and balance values at the bar's closing. On the chart, there is also a semi-transparent cloud or channel of the same color as the equity line. The channel edges indicates the maximum and minimum equities of the bar.

To see detailed information about a bar, simply right-click the bar of your choice. You can also zoom in or out and shift the chart by the mouse or with the help of respective commands in the Chart menu.


Luadebugging10.png


GetHistory Simulation

When a strategy is applied on a chart, it usually calls the Get History command of the host application. In this case, the dialog requesting additional price data appears.

You need to select the instrument's price source and required data range. Please note that of all the prices of the data range, only those prior to the simulated beginning date/time are used. All following bars are built on the basis of the simulated ticks. You can also select Empty History. In this case, no history is provided and all bars are built only on the basis of the tick data.

However, if the timeframe of a strategy is big (hours or days), it may cause a long delay before the strategy actually starts trading. For example, if the strategy requests days and then applied MACD with the default parameters, the strategy can be able to start trading only on the 26th day of the simulated market.

Please note that only simulated instruments are processed properly.

See Also

Integrated Lua EditorDebugger, Lua Debugging, Backtesting Strategy

This Article in Other Languages

Language: English  • español • français • русский • 中文 • 中文(繁體)‎