Visualizing modules to build trading strategies - a basic understanding

Author: The Little Dream, Created: 2019-07-08 09:23:59, Updated: 2023-10-24 21:40:14

img

Visualize modules to build trading strategies

Visualizing programming has always been a coveted goal of software tool developers, even in the field of quantitative trading. This is because the way to visualize this kind of puzzle is to reduce the technical threshold for programming development. Users will no longer have to deal with a bunch of boring code, but will simply use their imagination and logical thinking to focus on the business itself. It's amazing to be able to implement a program of your own choice.

So let's get into the field of visualization programming to quantify trading strategies!

  • Visual programming quantified by the original inventor

    Sign inhttps://www.fmz.comAfter that, you can register your account (if you have already registered, log in directly) by clicking on Control Center - > Policy Library - > Create new policy.

    img

    We can see an initial visualization strategy. The function is simply to output the account asset information of the default configured exchange (retest or on the robot, the first exchange object added). (Figure below)

    img

    Before we start learning how to use visualization, we can understand some of the design concepts of visualization.

    • One, spell.

      Careful observation reveals that the modules are both convex and convex, meaning that the modules can be "connected" and "connected". If the functional code represented by the two modules can be connected, then you will be attracted to each other when you bring the two modules together.

      img

    • Module setup and adjustment

      Some modules have special settings, such as:

      img

      You can drag the left-hand "item" module to the "join" module to add a "spell" position, which adds a spell text position. This allows you to pass, click on the gearbox, and make some adjustments and settings to the module.

    • 3, the default input parameters of the module

      Some modules require input of parameters, such as numbers, strings, etc. If the variable is not added as the input parameter of the module, the module is executed according to the default input parameter.

      imgA computation module like this, which takes the square root of the sum of its digits, produces the result of this module.imgAs you can see, if the input parameter is left out, the square root of 9 is calculated using the default value of 9 as the input parameter.img

      Of course, if you want to use a variable module as an input parameter, you can directly spell the variable module in the () position.img

    • 4, operation

      Modules can be pointed and dragged with the left mouse button. Modules can be copied and pasted using Ctrl + C and Ctrl + V, which is as easy as copying and pasting code or text. The operating area can be scaled up with a mouse slide, and all modules can be scaled up or down. Drag the space in the operating area, which can move the operating area. On the right side of the trash can, record the most recently deleted modules. Most importantly, spell out the module policy and don't forget to save.

  • Visualization tools and module introduction

    You can see that there are a lot of module classifications on the left side of the visualization editor, and there are a lot of visualization modules available for each category item.

    imgIn total, there are 11 categories.

    • The tool module:

      img


      • 1, output information:

        The module is usually used in combination with the text class module, as shown below:imgStrings can be entered into the text class module, so that when you run the "Export information" module, the content of the strings in the text module will be printed.imgThis is not the first time.img

        For example, JavaScript language code:

        function main(){
            Log("你好,可视化编程!")
        }
        

      • WeChat pushed:

        The module is similar in appearance to "Export Information", but differs in that it pushes information to WeChat tied to the current account while also exporting information.img img

        For example, JavaScript language code:

        function main () {
            Log("微信推送!@")
        }
        

      • 3, throw the exception.

        Throwing an exception module causes the program to issue an error, and then the program stops executing (unless you write exception handling code).img

        Similar to the main function in the JavaScript policy, the throw function directly executes the throw function.

        function main () {
            throw "第一句就抛出异常,让程序停止!"
        }
        

        The results of the tests:imgIt is more commonly used during debugging, for example, when you want a program to stop under a certain condition, and some of the data that was printed at the time is easier to observe. Or throw out an unusual module in the code process that might cause problems, allowing the program to report errors and find some errors.


      • Four, sleep

        The sleeping moduleimgThe following is the JavaScript policy:

        function main () {
            Sleep(1000 * 5)
        }
        

        The sleep module is tested:imgThe results of the tests:img


      • 5 Printing profits

        img

        The module, like the inventor quantified trading platform API function LogProfit, prints earnings logs and automatically draws earnings curves based on the input parameters.

        For example:imgThe results of the re-test are as follows:imgThe corresponding JavaScript policy code is as follows:

        function main () {
            LogProfit(1)
            Sleep(1000 * 5)
            LogProfit(2)
            Sleep(1000 * 5)
            LogProfit(3)
            Sleep(1000 * 5)
            LogProfit(2)
            Sleep(1000 * 5)
            LogProfit(5)
        }
        

        It can be spelled anywhere you want to export the earnings information.


      • 6th cycle

        imgA loop module can be encapsulated in a series of stacked module combinations, allowing this module combination to execute a loop.

        The test:imgThe results of the tests:imgAs you can see, after a combination of modules consisting of print gain and sleep, the module combination is executed over and over again.


      • 7 cycles per N seconds

        imgThe module is basically the same as the circulating module, the only difference being that the module is self-dormant.img


      • Precision processing

        imgA variable module or a numerical value can be handled with this module when precision control is required. The value of the parameter portion is entered, and the value of the specified decimal digit is output according to the setting.

        For example, the value 3.1415926535897 is handled with precision.img

        The results showed:img


      • 9th, empty logs

        img

        For blank logs, a part of the log can be kept depending on the input parameters. As in the API documentation:

        LogReset()
        

      • 10 - Clear the income log

        img

        For empty earnings logs, a portion of the logs can be kept depending on the input parameters. As in the API documentation:

        LogProfitReset()
        

      The following are some of the most commonly used tool modules.

      • 11, access to a functional module of a market attribute

        img

        This tool module needs to be used in conjunction with the industry module in "Trading Module Types", as shown below:img

        Use the output information module to output the latest ticker transaction price for the following transaction:img

        The results showed:img

        For example, JavaScript policy code:

        function main () {
            Log(exchange.GetTicker().Last)
        }
        
      • 12, get K-line data from a bar-based property module

        img

        The module also needs to be used with the acquisition K-line data module in the "Transaction Module Type".

        The first step is to create a variable module called K-line.imgThen, the K-line data is obtained using the K-line data module and assigned a value to the variable module: "K-line".imgThen use the list length module in the "List Module Type" to obtain the length of the variable module in the K-line to specify which Bar of the data in the K-line to obtain.imgIt's like the following:imgThe retest is run, and the last K-line Bar time stamp is printed.img

      • 13 modules for obtaining some order data from the order sheet

        img

        It should also be used in conjunction with the acquisition of deep data modules in the "Transaction Module Type".

        img

        The index is set to 0, the order is set to sell, and you get the information about this order.

        img

        For example, JavaScript policy code:

        function main () {
            Log(exchange.GetDepth().Asks[0])
        }
        
      • 14. Module to access an attribute in the asset information

        imgThe module needs to be used with the asset information module.img

        For example, print the number of coins available in the current accountimg

        The results showed:img

        For example, the JavaScript policy:

        function main () {
            Log(exchange.GetAccount().Stocks)
        }
        
      • 15 Module to get an attribute from order data

        img

        This module is used to retrieve the value of an attribute in the order data, such as the price or quantity of a sale in the order sheet (example of order number 13).img

        The results of the tests:imgFor example, the JavaScript policy:

        function main () {
            Log(exchange.GetDepth().Asks[0].Price)
        }
        

        An attribute in the order information returned by the "Query Order Details Module" can also be used (explained in the next section).

      • 16, Module for obtaining position attributes for a position in the holding information

        img

        Similarly, to be used in conjunction with "get futures holdings module", it is important to note that the holdings data returned by get futures holdings module is an array (list), which is a data structure containing different contracts, positions in different directions.

        After learning so much, we came together to combine a hedging operation, which is to hedge both short-term and long-term contracts. We do a positive leverage hedge, that is, we open one long-term contract, one more contract in the near term.

        img

        The results of the tests:img

Visualizing the paradigm strategy:

More tips can be found at:https://www.fmz.com/square

Other articles in this series

It's boring programming, it's easy to do with blocks, try it out, it's fun!


Related

More

15650463856There's no cc in the indicator, so I can't create this visualization if I'm going to use cc or not.

Black and white.Please tell me how to use the indicator module in the visualization

The Little Dream https://www.fmz.com/digest-topic/6182

15650463856In addition to in-depth, basic, and advanced, there are three other articles in this series, why haven't I found custom modules and indicator modules to use?

The Little DreamThis article in this series discusses how to implement custom modules.

Black and white.Good, thank you. Found it.

The Little DreamThis series of articles can be read and re-told.