Logging

Some general advice on how to use logging and debugging while backtesting a trading bot strategy.

  1. Enable logging: First, you need to enable logging within your trading bot script. If you’re using HaasScript, you can use the Log() function to write log messages. For example:
Log("Backtesting started");
  1. Include debug information: Make sure your log messages include relevant debug information, such as variable values, function calls, and decision points. This will help you understand what’s happening in your script during the backtest.
Log("Current price: " .. price);
Log("Buy signal triggered, placing buy order");
  1. Monitor the logs: As you run the backtest, keep an eye on the log messages. This will help you identify any issues or unexpected behavior in your trading strategy. HaasOnline TradeServer Cloud should display the log messages in a dedicated log section, usually accessible through the web interface.
  2. Use breakpoints (if supported): Some development environments offer breakpoint functionality, allowing you to pause the execution of your script at specific points. This enables you to inspect the values of variables and the state of the program at that point in time. If HaasOnline TradeServer Cloud supports this functionality, you can use it to debug your trading strategy more effectively.
  3. Review the backtest results: Once the backtest is complete, review the results to identify any issues or areas of improvement. Look for any discrepancies between the backtest results and the expected outcome of your strategy. Analyze the log messages and identify any patterns or trends that could help you understand the cause of these discrepancies.
  4. Refine your strategy: Based on your analysis of the log messages and backtest results, make adjustments to your trading strategy as needed. This may involve modifying your script, tweaking parameters, or even changing your overall approach.

Remember that the process of developing a trading strategy is iterative. You may need to run multiple backtests, analyze the results, and make adjustments before arriving at a strategy that meets your desired performance criteria.

Back to: HaasScript Fundamentals > Debugging and Troubleshooting