Type/to search
Welcome to FMZ Quant Trading Platform
Programming Languages
JavaScript
TypeScript
Python
C++
MyLanguage
PINE Language
Blockly Visual Programming
Workflow
Key Security
Live Trading
Strategy Library
Docker
Deploy Docker
One-Click Docker Rental
Manual Deployment of Bot
Docker Operation Precautions
Global IP Address Specification
Command Line Parameters for Bot Program
Live Trading Data Migration
Docker Monitor
Exchange
Strategy Editor
Backtesting System
Strategy Entry Functions
Strategy Framework and API Functions
Template Library
Strategy Parameters
Interactive Controls
Options Trading
C++ Strategy Writing Guide
JavaScript Strategy Writing Guide
Web3
Built-in Libraries
Extended API Interface
MCP Service
Trading Terminal
Data Explorer
Alpha Factor Analysis Tool
General Protocol
Debugging Tool
Remote Editing
Import and Export of Complete Strategies
Multi-language Support
Live Trading and Strategy Grouping
Live Trading Display
Strategy Sharing and Renting
Live Trading Message Push
Common Causes of Live Trading Errors and Abnormal Exits
Exchange-Specific Notes

Template Library is a reusable code module in the FMZ Quant Trading Platform, which belongs to a category of strategy code. The programming languages that support template library functionality on the FMZ Quant Trading Platform include: JavaScript, Python, C++, Blockly Visual. When creating a strategy, if the category is set to Template Library, the system will create a template library in the strategy repository of the currently logged-in account on the FMZ Quant Trading Platform. Once created, this category cannot be changed back to a regular strategy.

Create Template Library Page

Export functions are the interface functions of template libraries, which can be called by strategies that reference the template library.

Examples

  • Different programming languages have different formats for writing template libraries. The following are example codes for declaring and implementing export functions in template libraries:

    javascript
    /* -- 策略引用该模板以后直接用 $.Test() 调用此方法 -- main 函数在策略中不会触发, 只做为模板调试的入口 */ $.Test = function() { Log('Test') } function main() { $.Test() }
    python
    def Test(): Log("template call") # 导出Test函数, 主策略可以通过ext.Test()调用 ext.Test = Test
    c++
    // 策略引用该模板以后直接用 ext::Test() 调用此方法 void Test() { Log("template call"); }
  • Strategies written in Blockly visual mode can implement library functions through JavaScript language template libraries. Please use the following format.

    javascript
    /*blockly { "type": "ext_testA", "message0": "testA|testA", "template": "function(){return 99;}()", "order": "ORDER_ATOMIC", "output": "Number" },{ "type": "ext_MA", "message0": "MA 周期 %1| MA Period %1", "args0": [{ "type": "input_value", "check": "Number" }], "template": "(function(){var r = exchange.GetRecords(); return (!r || r.length < %1) ? false : TA.MA(r, %1); })()", "order": "ORDER_ATOMIC", "output": null, "colour": 85 } */

Template libraries can also set their own interface parameters. Template library parameters are used as global variables in the template library code.

For example, we set a template library parameter:

Template Parameter

Variable Name in Strategy CodeParameter Name Displayed on Strategy InterfaceTypeDefault Value
param1Template Parameter 1Number99

Examples

  • Template library code for testing the param1 parameter:

    javascript
    $.SetParam1 = function(p1) { param1 = p1 } $.GetParam1 = function() { Log("param1:", param1) return param1 }
    python
    def SetParam1(p1): global param1 param1 = p1 def GetParam1(): Log("param1:", param1) return param1 ext.SetParam1 = SetParam1 ext.GetParam1 = GetParam1
    c++
    void SetParam1(float p1) { param1 = p1; } float GetParam1() { Log("param1:", param1); return param1; }
  • Strategy code referencing the above template library example, using the template library's exported functions to get parameter param1 and modify parameter param1.

    javascript
    function main () { Log("Calling $.GetParam1:", $.GetParam1()) Log("Calling $.SetParam1:", "#FF0000") $.SetParam1(20) Log("Calling $.GetParam1:", $.GetParam1()) }
    python
    def main(): Log("Calling ext.GetParam1:", ext.GetParam1()) Log("Calling ext.SetParam1:", "#FF0000") ext.SetParam1(20) Log("Calling ext.GetParam1:", ext.GetParam1())
    c++
    void main() { Log("Calling ext::GetParam1:", ext::GetParam1()); Log("Calling ext::SetParam1:", "#FF0000"); ext::SetParam1(20); Log("Calling ext::GetParam1:", ext::GetParam1()); }

When a strategy references a template library, the currently logged-in FMZ Quant Trading Platform account must have available template libraries in its strategy library. On the Strategy Edit Page, check the templates you need to reference in the Template section, then save the strategy to complete the reference.

Template Reference Screenshot