Lua Debugging

From FxCodeBaseWiki
Jump to: navigation, search

Step-by-Step Execution

Step and Run commands

When a Lua file (an indicator or strategy) just starts being executed, the debugger is in the Step-by-Step mode. The Step-by-Step mode means that the debugger displays a line to be executed next and waits until it is permitted to execute the line.

The line to be executed is highlighted and framed.


Luadebugging1.png

When the debugger is stopped before the line execution, it also updates all the data monitored:

  • watches
  • price streams (and indicator output for indicators or action log for strategies)
  • chart
  • tables and statistics (for strategies)

You can either execute just one line (the Debug->Step command) or run the code (Debug->Run). If the Step command is used, the debugger executes the highlighted line only and stops again. If the Run command is used, the debugger executes all lines without stopping until:

  • the execution is finished
  • the breakpoint is met
  • the user executes the Debug->Break command.

The execution is finished when no more data is to be simulated. However, the indicators and strategies are not terminated yet, and you can see all the output data and statistics. To terminate the execution and close all the related data (charts, streams, tables) use the Debug->Terminate command. If ReleaseInstance function exists in the indicator/strategy it is executed before the debugging session is terminated.

If a break point is met or the Debug->Break command is executed, the debugger stops before executing the next line and waits for the next Step or Run command

Break points

The break points are indicated by red circles placed to the left of the code line . When the code execution is initiated by the Run command, and the code generated from the source line marked with a break point is about to be executed, the execution stops.

To add or remove a break point, click the source line of your choice and on the Debug menu, point to Breakpoints, and then click Toggle Breakpoint.

Watches

All watches are stored under the Watches tab. A watch is any Lua expression. Every time the debugger stops, all watches are recalculated, and the result is updated. The data type and the default string presentation of the result is shown. To add a watch, on the Debug menu, point to Watches, and then click Add Watch.

To edit a watch, select the watch of your choice from the list of available watches, on the Debug menu, point to Watches, and then click Edit Watch.

To remove a watch, select the watch of your choice from the list of available watches, on the Debug menu, point to Watches, and then click Remove Watch.

These commands are also available on the context menu that opens by right-clicking the watch list.

Luadebugging2.png

Project File

When use start the debug session using Open indicator (Open Strategy) command of the debugger, a new session is started. No watches, nor breakpoints are created, and the default indicator or strategy parameters are used. When you debug a strategy or indicator for a long time, the configuring of the session may be annoying. Therefore, you can save all files containing watches, breakpoints, indicator/strategy parameters, and pricees of the session into a project file (File->Save Project). The next time you start the debugger, just use the Open Project command instead of the Open Indicator (Strategy) one, and all the debugging session's parameters.

Hints

Displaying the dates

In Indicator Core, the dates are stored in the form of numbers. To see a date in a more convenient format, use the core.formatData function.

Action Tracing

To output trace records into the Output window of the debugger, use the core.host:trace() or print function.

The print function is available in the debugger only and takes one or more arguments. The first argument is same as the format string of the string.format function of Lua. Thus, print(a, b, c) is equal to core.host:trace(string.format(a, b, c)).

This Article in Other Languages

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