The resource loading... loading...

Visualize editing strategies to extend custom libraries

Author: Inventors quantify - small dreams, Created: 2020-10-17 11:27:43, Updated: 2023-09-27 19:39:37

img

Visualize editing strategies to extend custom libraries

How can I extend the custom class library I need to the visualization strategy? For example, I want to calculate the MA indicator, but the system only comes with:imgHow can we add some custom code to these metrics? We explain how to extend the visualization module by adding a custom MA indicator calculation module.

Directory of digital currencies

First of all, let's talk about the template for the cryptocurrency spot market repository, which is:https://www.fmz.com/strategy/10989Although the template is a template for the FMZ platform JavaScript language, students who do not understand the concept of a template can consult the FMZ API documentation:https://www.fmz.com/api#模板类库What is it? However, there is a commentary at the beginning of the template that defines the code for visualizing the module, and the code that defines the code can reference the code of this JavaScript template. This is very convenient for us to expand on our own (to give a good example, let's emulate).

The digital currency spot market library, the visual definition of the opening section:

/*blockly
    {
        "type": "ext_Trade",
        "message0": "%1 币数 %2|%1 Coins %2",
        "args0": [{
            "type": "field_dropdown",
            "options": [
                ["买入|Buy", "Buy"],
                ["卖出|Sell", "Sell"]
            ]
        }, {
            "type": "input_value",
            "check": "Number"
        }],
        "template": "(function(){var r = $.%1(%2); return r ? r.amount : 0; })()",
        "order": "ORDER_ATOMIC",
        "output": "Number",
        "colour": 85
    }, {
        "type": "ext_CancelPendingOrders",
        "message0": "取消 %1 订单|Cancel %1 Orders",
        "args0": [{
            "type": "field_dropdown",
            "name": "TYPE",
            "options": [
                ["所有|All", " "],
                ["买单|Buy", "ORDER_TYPE_BUY"],
                ["卖单|Sell", "ORDER_TYPE_SELL"]
            ]
        }],
        "previousStatement": null,
        "nextStatement": null,
        "template": "$.CancelPendingOrders(%1);",
        "colour": 85
    }, {
        "type": "ext_Cross",
        "message0": "计算交叉 周期 %1 与 %2|Cross Period %1 and %2",
        "inputsInline": true,
        "args0": [{
            "type": "input_value"
        }, {
            "type": "input_value"
        }],
        "template": "$.Cross(%1,%2)",
        "order": "ORDER_ATOMIC",
        "output": "Number"
    }, {
        "type": "ext_GetAccount",
        "message0": "获取资产信息|GetAccount",
        "template": "$.GetAccount()",
        "order": "ORDER_ATOMIC",
        "output": null
    }
*/

The modules on the visualized edit page correspond to:img

Build a module for calculating a self-defined MA indicator

With ready-made examples, it's easy to build your own with your own hands, even more so than painting a canvas.

First, a new template for the JavaScript language was created.img

Edit the template code.

/*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
    }
*/
  • type: The attribute defines the module type, which can be named on its own.
  • message0: text displayed on the module.
  • template: code executed by the module.
  • output: the type of output of the module.
  • args0: the input parameter of the module, in the module definition code %1 represents the first input parameter and %2 represents the second one.

This newly created template is saved after it has been edited. In the policy where we need to use this template, select this template.img

You can see two more modules:

  • img

    The module is called testA, and let's look at its executable code:img

    function(){return 99;}()
    

    A simple JavaScript function is executed and returns a value of 99.

  • img

    It's called MA Cycle Module, and let's look at its execution code:

    img

    (function(){var r = exchange.GetRecords(); return (!r || r.length < %1) ? false : TA.MA(r, %1); })()
    

    The code is an anonymous function call, in which the anonymous function first performs the operation to obtain K-line data, K-line data.rThen depending on whether the obtained r is fornullOrrThe length is less than the input parameter of the module%1Going back to judgingfalseOr go back.TA.MA(r, %1)The results of the calculation of the indicators.

I'm going to use it later.

The test calculates the MA indicator

This is the first time I've seen this video.img

It runs:img

As you can see above, the data for the calculation of the MA indicator was obtained on a pay as you go basis.

The above is just a parsing of the cube, for the design of the visualization module, the template function can be extended by itself.


Related

More