Debugging Indicator

From FxCodeBaseWiki
Jump to: navigation, search

Start Debugging Session

To start debugging your indicator, 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/strategy files. Select the indicator you wish to debug and click Open. Standard indicators can be used by other indicators stored in the folder of user indicators but cannot be debugged. To debug a standard indicator, you need to move it to the folder of user indicators.

After you have started the debugging session, the Init() function of the indicator 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 indicator for entering its parameters.

Configuring Parameters

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

Luadebugging3.png

The first group of parameters is used for configuring the debugging session.

Luadebugging3-1.png

Simulation parameters

Note: this set of parameters is available only for tick indicators, and it is not available for bar indicators.


The first three parameters, 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 a parameter's value field and click the ellipsis (...) button. The Choose Price Source dialog box appears.

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 for the selected instrument and data range. The data is downloaded fast enough. Loading of a whole year of the one-minute data for an instrument (approx 300K candles) usually takes less than 30 seconds. Wait while the data is being loaded.

Luadebugging15.png

After the data is loaded, to add one more instrument, repeat the procedure with another parameter if necessary. The Source Price parameter allows to select one of the four (Open, High, Low, and Close) prices to be used to calculate the indicator's values. By default, the Close price is used (as in Marketscope 2.0).

The Price Type parameter allows to select between the Bid and Ask prices.

The Pre-deliver Prices parameter allows to select the mode of the history simulation. If the parameter's value is False, nine ticks are simulated for every bar of the selected price data range, . Accordingly, the indicator is called for updating nine times for every bar, and every time the bar is slightly changed. This mode allows to perform simulation by applying the indicator to the live price data. If the parameter's value is True, the history is passed to the indicator "as is", and the indicator is called for every bar only once, and the bar is always in its final state. This mode allows to perform simulation by applying the indicator to the historical price data.See also Indicators on Live Market Data.

The Show In New Area parameter allows to display an indicator in an additional area of the chart (as it is done with oscillators). This is useful for testing the indicator with candle or from/to bar output, so that you can see both, source prices and the indicator output that may overlap otherwise.

The Open Price Mode parameter is self-explanatory.

The Show Volume parameter allows to specify whether the volume is displayed on the chart or not. It is useful for volume indicator. For other indicators, the volume data is irrelevant.

Trading Parameters

The parameters allow configuring the account and trading rules to be simulated during the debugging session.

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:

  • The base or counter currency of the first instrument you add must be same as the account currency.
  • The base or counter currency of the second and third instruments you add must be same as the account currency or any of the first instrument's currencies.

Example 1 The first instrument is EUR/USD.

If the account currency is not specified, it is USD by default. Though, the account currency may be not only USD, but EUR as well.

Example 2

You want to have an account in USD but run the strategy on GBP/JPY.

For the first instrument, select USD/JPY, and for the second instrument, select 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.

  • 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.

Indicator Parameters

The second and third groups list all indicator parameters. The parameters are similar to indicator parameters of Marketscope 2.0. For your debugging session, configure indicators parameters as you may need, and. Click OK. An instance of the indicator is created and the debugging session continues. If the debugger is in the step-by-step mode, it stops on the first code line of the Prepare() function. Otherwise, the execution continues until the first break point.

Updating Indicators

When the indicator is initialized, the debugger starts simulating its updating on the market. For every bar of the price data, the Update() function is called once or several times (depending on the value of the Pre-deliver Prices parameter).

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

  • The indicator source data and output (on the Streams tab).
  • The indicator drawn on a chart (on the Chart tab).

Stream View

In the stream view, the following data is shown:

  • The source data. A whole bar is always shown, even if the indicator is a tick one.
  • The indicator output streams: first - all numeric (line, bar, or dot) streams, then - all text streams.

The streams are displayed in the same order as they are created.

A numeric stream shows the value of the indicator line, and optionally:

  • The sign ^ if the break of the line flag is put on that bar.
  • The color in [rrggbb] form (for example, [ff0000] for red) if the color is specified for this particular bar.

A text stream shows the message, tool tip, and price if the label is put on the bar.

When the debugger is stopped, the line of the bar, for which the Update() function has most recently been called, is highlighted.

Luadebugging4.png

Chart View

The chart view displays the indicator lines and labels on the price chart or in an additional area below it. In addition to the stream view, all objects such as lines and labels drawn via core.host:execute() are also displayed here.

The price chart's time frame is always determined by the time frame of the price data selected for debugging.

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 on the Chart menu.

Luadebugging5.png

GetHistory Simulation

An additional data access using the core.host:execute(getHistory) call can be used in the debugging process. Its behavior depends on the value of the Pre-deliver Prices parameter.

When Simulating Live Market (pre-deliver == false)

When the price history is requested, only data which precedes the currently simulated moment is taken from the data file. All further bars are created on the basis of the simulated ticks. So, unfortunately, only the same instrument can be requested when the indicator is simulated on live market data. If you don't need historical part of the data, you can choose "Empty History" instead of the price source when it is requested by the debugger. In that case, the collection will be filled only on the basis of all further ticks.

When Simulating Historical Market (pre-deliver == true)

When the price history is requested, the data is loaded from the data file "as is", so you can load data of any instruments.

See Also

Integrated Lua EditorDebugger, Lua Debugging.

This Article in Other Languages

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