Skip to content
All library documents

FMZ Strategy Entry, Initialization, Error, and Cleanup Functions

Article FMZ guides

Summary

This FMZ guide explains the lifecycle functions available to strategies written in JavaScript, Python, Rust, and C++. The main function is the strategy entry point; init runs first for initialization; onexit handles cleanup after normal termination; and onerror handles abnormal termination where supported. The guide notes language-specific and environment-specific differences, including that Python and C++ strategies do not support onerror and that the backtesting system does not support it either. It also says child threads end when main finishes.

Examples show initialization logging, cleanup hooks, and ticker polling loops across the supported languages. The guide gives onexit a maximum execution time of five minutes and explains that a previously triggered onerror prevents onexit from running in live trading. It cautions that an infinite polling loop may not naturally reach cleanup when a backtest ends; the strategy can detect the backtest end marker and exit the loop to trigger cleanup. These examples explain platform behavior rather than trading signals or strategy performance.

Key ideas

  • The main function is the strategy entry point, while init runs first during startup.
  • The onexit hook performs cleanup after normal termination and has a five-minute limit.
  • The onerror hook handles abnormal exits where supported, but Python, C++, and backtesting do not support it.
  • Child threads are automatically terminated when main finishes.
  • A backtest polling loop may need to detect the end marker and exit to run cleanup.

Tags

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.