Topic: Developing a new Programming Language for Addons

Hello Traders,

I spend the last month on prototyping a new programming language for integration in our software.

Cinonim at GitHub

My goal was:
- the language to be with "Context free grammar"
- to be statically typed
- to be able to compile to WebAssembly online without third party modules.
- to be suitable for writing backtesting algorithms and custom indicators.

Currently the language is Turing Complete (proven by calculating Rule 110): https://en.wikipedia.org/wiki/Rule_110

The language is similar to C so I called it "Cinonim" (it is "synonym" in Bulgarian and starts with "c")

Cinonim source code

// Rule 110
// https://en.wikipedia.org/wiki/Rule_110

#import-func js setCell    = void setCell(int index, int value)
#import-func js printTable = void printTable()
#export-func rule110 = rule110

int table[100];
const int SIZE = 100;

void logTable()
{
    int i;

    for (i=0; i<SIZE; i+=1)
        setCell(i, table[i]);

    printTable();
}

void initTable()
{
    int i;

    for (i=0; i<SIZE; i+=1)
        table[i] = 0;

    table[SIZE-1] = 1;
}

void rule110(const int maxCycles)
{
    int i, cycle;
    int pattern, temp;

    initTable();
    logTable();

    cycle = 0;
    while (cycle < maxCycles) {
        temp = table[0];

        for (i=1; i<SIZE-1; i+=1) {
            pattern = 100*temp + 10*table[i] + table[i+1];
            temp = table[i];

            if (pattern == 111) table[i] = 0;
            if (pattern == 110) table[i] = 1;
            if (pattern == 101) table[i] = 1;
            if (pattern == 100) table[i] = 0;
            if (pattern == 011) table[i] = 1;
            if (pattern == 010) table[i] = 1;
            if (pattern == 001) table[i] = 1;
            if (pattern == 000) table[i] = 0;
        }

        logTable();
        cycle += 1;
    }
}

Exported WebAssembly text format;

(module
    (import "js" "setCell" (func $setCell (param i32) (param i32)))
    (import "js" "printTable" (func $printTable ))
    (export "rule110" (func $rule110))
    (global $SIZE i32 (i32.const 100))
    (memory 1)
    (func $logTable
        (local $i i32)
        (local.set $i (i32.const 0))
        (block (loop
            (br_if 1 (i32.eqz (local.get $i) (global.get $SIZE) (i32.lt_s)))
            (local.get $i)
            (i32.load (i32.add (i32.const 0) (i32.shl (local.get $i) (i32.const 2))))
            (call $setCell)
            (local.set $i (local.get $i) (i32.const 1) (i32.add))
            (br 0)
        ))
        
        (call $printTable)
    )
    (func $initTable
        (local $i i32)
        (local.set $i (i32.const 0))
        (block (loop
            (br_if 1 (i32.eqz (local.get $i) (global.get $SIZE) (i32.lt_s)))
            (i32.store (i32.add (i32.const 0) (i32.shl (local.get $i) (i32.const 2))) (i32.const 0))
            (local.set $i (local.get $i) (i32.const 1) (i32.add))
            (br 0)
        ))
        (i32.store (i32.add (i32.const 0) (i32.shl (global.get $SIZE) (i32.const 1) (i32.sub) (i32.const 2))) (i32.const 1))
    )
    (func $rule110 (param $maxCycles i32)
        (local $i i32)
        (local $cycle i32)
        (local $pattern i32)
        (local $temp i32)
        
        (call $initTable)
        
        (call $logTable)
        (local.set $cycle (i32.const 0))
        (block (loop
            (br_if 1 (i32.eqz (local.get $cycle) (local.get $maxCycles) (i32.lt_s)))
            (local.set $temp (i32.load (i32.add (i32.const 0) (i32.shl (i32.const 0) (i32.const 2)))))
            (local.set $i (i32.const 1))
            (block (loop
                (br_if 1 (i32.eqz (local.get $i) (global.get $SIZE) (i32.const 1) (i32.sub) (i32.lt_s)))
                (local.set $pattern (i32.const 100) (local.get $temp) (i32.mul) (i32.const 10) (i32.load (i32.add (i32.const 0) (i32.shl (local.get $i) (i32.const 2)))) (i32.mul) (i32.add) (i32.load (i32.add (i32.const 0) (i32.shl (local.get $i) (i32.const 1) (i32.add) (i32.const 2)))) (i32.add))
                (local.set $temp (i32.load (i32.add (i32.const 0) (i32.shl (local.get $i) (i32.const 2)))))
                (local.get $pattern) (i32.const 111) (i32.eq)
                (if (then
                    (i32.store (i32.add (i32.const 0) (i32.shl (local.get $i) (i32.const 2))) (i32.const 0))
                ))
                (local.get $pattern) (i32.const 110) (i32.eq)
                (if (then
                    (i32.store (i32.add (i32.const 0) (i32.shl (local.get $i) (i32.const 2))) (i32.const 1))
                ))
                (local.get $pattern) (i32.const 101) (i32.eq)
                (if (then
                    (i32.store (i32.add (i32.const 0) (i32.shl (local.get $i) (i32.const 2))) (i32.const 1))
                ))
                (local.get $pattern) (i32.const 100) (i32.eq)
                (if (then
                    (i32.store (i32.add (i32.const 0) (i32.shl (local.get $i) (i32.const 2))) (i32.const 0))
                ))
                (local.get $pattern) (i32.const 11) (i32.eq)
                (if (then
                    (i32.store (i32.add (i32.const 0) (i32.shl (local.get $i) (i32.const 2))) (i32.const 1))
                ))
                (local.get $pattern) (i32.const 10) (i32.eq)
                (if (then
                    (i32.store (i32.add (i32.const 0) (i32.shl (local.get $i) (i32.const 2))) (i32.const 1))
                ))
                (local.get $pattern) (i32.const 1) (i32.eq)
                (if (then
                    (i32.store (i32.add (i32.const 0) (i32.shl (local.get $i) (i32.const 2))) (i32.const 1))
                ))
                (local.get $pattern) (i32.const 0) (i32.eq)
                (if (then
                    (i32.store (i32.add (i32.const 0) (i32.shl (local.get $i) (i32.const 2))) (i32.const 0))
                ))
                (local.set $i (local.get $i) (i32.const 1) (i32.add))
                (br 0)
            ))
            
            (call $logTable)
            (local.set $cycle (local.get $cycle) (i32.const 1) (i32.add))
            (br 0)
        ))
    )
)

Output:

                                                                                                   #
                                                                                                  ##
                                                                                                 ###
                                                                                                ## #
                                                                                               #####
                                                                                              ##   #
                                                                                             ###  ##
                                                                                            ## # ###
                                                                                           ####### #
                                                                                          ##     ###
                                                                                         ###    ## #
                                                                                        ## #   #####
                                                                                       #####  ##   #
                                                                                      ##   # ###  ##
                                                                                     ###  #### # ###
                                                                                    ## # ##  ##### #
                                                                                   ######## ##   ###
                                                                                  ##      ####  ## #
                                                                                 ###     ##  # #####
                                                                                ## #    ### ####   #
                                                                               #####   ## ###  #  ##
                                                                              ##   #  ##### # ## ###
                                                                             ###  ## ##   ######## #
                                                                            ## # ######  ##      ###
                                                                           #######    # ###     ## #
                                                                          ##     #   #### #    #####
                                                                         ###    ##  ##  ###   ##   #
                                                                        ## #   ### ### ## #  ###  ##
                                                                       #####  ## ### ###### ## # ###
                                                                      ##   # ##### ###    ######## #
                                                                     ###  ####   ### #   ##      ###
                                                                    ## # ##  #  ## ###  ###     ## #
                                                                   ######## ## ##### # ## #    #####
                                                                  ##      ######   ########   ##   #
                                                                 ###     ##    #  ##      #  ###  ##
                                                                ## #    ###   ## ###     ## ## # ###
                                                               #####   ## #  ##### #    ########## #
                                                              ##   #  ##### ##   ###   ##        ###
                                                             ###  ## ##   ####  ## #  ###       ## #
                                                            ## # ######  ##  # ##### ## #      #####
                                                           #######    # ### ####   ######     ##   #
                                                          ##     #   #### ###  #  ##    #    ###  ##
                                                         ###    ##  ##  ### # ## ###   ##   ## # ###
                                                        ## #   ### ### ## ######## #  ###  ####### #
                                                       #####  ## ### ######      ### ## # ##     ###
                                                      ##   # ##### ###    #     ## #########    ## #
                                                     ###  ####   ### #   ##    #####       #   #####
                                                    ## # ##  #  ## ###  ###   ##   #      ##  ##   #
                                                   ######## ## ##### # ## #  ###  ##     ### ###  ##
                                                  ##      ######   ######## ## # ###    ## ### # ###
                                                 ###     ##    #  ##      ######## #   ##### ##### #
                                                ## #    ###   ## ###     ##      ###  ##   ###   ###
                                               #####   ## #  ##### #    ###     ## # ###  ## #  ## #
                                              ##   #  ##### ##   ###   ## #    ####### # ##### #####
                                             ###  ## ##   ####  ## #  #####   ##     #####   ###   #
                                            ## # ######  ##  # ##### ##   #  ###    ##   #  ## #  ##
                                           #######    # ### ####   ####  ## ## #   ###  ## ##### ###
                                          ##     #   #### ###  #  ##  # ########  ## # #####   ### #
                                         ###    ##  ##  ### # ## ### ####      # #######   #  ## ###
                                        ## #   ### ### ## ######## ###  #     ####     #  ## ##### #
                                       #####  ## ### ######      ### # ##    ##  #    ## #####   ###
                                      ##   # ##### ###    #     ## ######   ### ##   #####   #  ## #
                                     ###  ####   ### #   ##    #####    #  ## ####  ##   #  ## #####
                                    ## # ##  #  ## ###  ###   ##   #   ## #####  # ###  ## #####   #
                                   ######## ## ##### # ## #  ###  ##  #####   # #### # #####   #  ##
                                  ##      ######   ######## ## # ### ##   #  ####  #####   #  ## ###
                                 ###     ##    #  ##      ######## ####  ## ##  # ##   #  ## ##### #
                                ## #    ###   ## ###     ##      ###  # ###### #####  ## #####   ###
                               #####   ## #  ##### #    ###     ## # ####    ###   # #####   #  ## #
                              ##   #  ##### ##   ###   ## #    #######  #   ## #  ####   #  ## #####
                             ###  ## ##   ####  ## #  #####   ##     # ##  ##### ##  #  ## #####   #
                            ## # ######  ##  # ##### ##   #  ###    ##### ##   #### ## #####   #  ##
                           #######    # ### ####   ####  ## ## #   ##   ####  ##  ######   #  ## ###
                          ##     #   #### ###  #  ##  # ########  ###  ##  # ### ##    #  ## ##### #
                         ###    ##  ##  ### # ## ### ####      # ## # ### #### ####   ## #####   ###
                        ## #   ### ### ## ######## ###  #     ######### ###  ###  #  #####   #  ## #
                       #####  ## ### ######      ### # ##    ##       ### # ## # ## ##   #  ## #####
                      ##   # ##### ###    #     ## ######   ###      ## ##############  ## #####   #
                     ###  ####   ### #   ##    #####    #  ## #     #####            # #####   #  ##
                    ## # ##  #  ## ###  ###   ##   #   ## #####    ##   #           ####   #  ## ###
                   ######## ## ##### # ## #  ###  ##  #####   #   ###  ##          ##  #  ## ##### #
                  ##      ######   ######## ## # ### ##   #  ##  ## # ###         ### ## #####   ###
                 ###     ##    #  ##      ######## ####  ## ### ####### #        ## ######   #  ## #
                ## #    ###   ## ###     ##      ###  # ##### ###     ###       #####    #  ## #####
               #####   ## #  ##### #    ###     ## # ####   ### #    ## #      ##   #   ## #####   #
              ##   #  ##### ##   ###   ## #    #######  #  ## ###   #####     ###  ##  #####   #  ##
             ###  ## ##   ####  ## #  #####   ##     # ## ##### #  ##   #    ## # ### ##   #  ## ###
            ## # ######  ##  # ##### ##   #  ###    #######   ### ###  ##   ####### ####  ## ##### #
           #######    # ### ####   ####  ## ## #   ##     #  ## ### # ###  ##     ###  # #####   ###
          ##     #   #### ###  #  ##  # ########  ###    ## ##### ##### # ###    ## # ####   #  ## #
         ###    ##  ##  ### # ## ### ####      # ## #   #####   ###   ##### #   #######  #  ## #####
        ## #   ### ### ## ######## ###  #     #######  ##   #  ## #  ##   ###  ##     # ## #####   #
       #####  ## ### ######      ### # ##    ##     # ###  ## ##### ###  ## # ###    #######   #  ##
      ##   # ##### ###    #     ## ######   ###    #### # #####   ### # ####### #   ##     #  ## ###
     ###  ####   ### #   ##    #####    #  ## #   ##  #####   #  ## #####     ###  ###    ## ##### #
    ## # ##  #  ## ###  ###   ##   #   ## #####  ### ##   #  ## #####   #    ## # ## #   #####   ###
   ######## ## ##### # ## #  ###  ##  #####   # ## ####  ## #####   #  ##   ##########  ##   #  ## #
  ##      ######   ######## ## # ### ##   #  #######  # #####   #  ## ###  ##        # ###  ## #####
 ###     ##    #  ##      ######## ####  ## ##     # ####   #  ## ##### # ###       #### # #####   #
 # #    ###   ## ###     ##      ###  # ######    ####  #  ## #####   ##### #      ##  #####   #  ##
 ###   ## #  ##### #    ###     ## # ####    #   ##  # ## #####   #  ##   ###     ### ##   #  ## ###

Re: Developing a new Programming Language for Addons

Amazing, just saw this now. So we can even edit/code our own backtesting engine? Wow. When will this be implemented?

Re: Developing a new Programming Language for Addons

> So we can even edit/code our own backtesting engine?

This is my long-term goal.

The problem with JavaScript is that we cannot expand it with a custom code. WebAssembly allows that to happen. However, the problem is that it doesn't accept WebAsembly text format (like the code above). It needs a bytecode. Yes, there is a "standard" Text to binary compiler, but it is too heavy for my taste.

I want a simple, fast and elegant solution which can be integrated into our products and can compile code in real time.

I work on a Forth compiler during the last month, but it appears it is not optimal for our needs also.

I'll probably develop a custom Human readable language that will translate to a native binary WebAssdembly code.
The purpose is to have our indicators and the Backtesting core code included and easily customisable.

My previous attempts failed in misery smile))
- EASL - excellent functional capabilities, but too complex for the general users
- Scheme interpreter - standard Scheme code, but too slow for the purpose.
- Cinonim - standard C code, but unfinished smile) (it has potential)
- Forth interpreter - complex for user, slow ( because it is interpreter)

Now I'm working on a Forth implementation that strictly follows the standard Forth practices - however, I found out it is designed to work directly on the processor (of course) and is not suitable for the browser )))

..

My next steps:
- developing a new online Generator and Pine Script code generator for TradingView
- making simple and effective WebAssembly text to binary (bytecode) compiler
- making a simple Human readable language suitable for compiling to WebAssembly bytecode format.

I'll have a lot of fun in 2023 smile))

4 (edited by opascarelli 2024-02-25 21:51:24)

Re: Developing a new Programming Language for Addons

Dear Popov,

How is the Pine Script generator for TradingView coming along?
Any idea when it will be ready?

Thx,
-OP

Re: Developing a new Programming Language for Addons

> How is the Pine Script generator for TradingView coming along?

I left this project aside for a moment.

For the last six months, I developed three new projects.

RobotParadise (unfinished) https://robots.forexsb.com/
It generates strategies with Express Generator. Then, validate the strategies on new data. The performance shown online is only on new data. (The calculation server is currently stopped)

FTMO Robot: https://eatradingacademy.com/premium-ro … robot/app/
The Robots are created manually. The application calculates the risks and sets the Entry lots and the protections.

Top 10 Robots. It will be online within several days. It generates and validates strategies with Express Generator (including Monte Carlo). The application periodically revalidates the strategies on newer data. This application has a unique calculation engine and database. It took me two months of work to develop it.

The FTMO Robot App and the Top 10 Robots App will be available only through the EA Trading Academy website.

I have plans to develop a new backtesting engine this year. We will see details later.

Re: Developing a new Programming Language for Addons

Popov wrote:

> How is the Pine Script generator for TradingView coming along?

I left this project aside for a moment.

For the last six months, I developed three new projects.

RobotParadise (unfinished) https://robots.forexsb.com/
It generates strategies with Express Generator. Then, validate the strategies on new data. The performance shown online is only on new data. (The calculation server is currently stopped)

FTMO Robot: https://eatradingacademy.com/premium-ro … robot/app/
The Robots are created manually. The application calculates the risks and sets the Entry lots and the protections.

Top 10 Robots. It will be online within several days. It generates and validates strategies with Express Generator (including Monte Carlo). The application periodically revalidates the strategies on newer data. This application has a unique calculation engine and database. It took me two months of work to develop it.

The FTMO Robot App and the Top 10 Robots App will be available only through the EA Trading Academy website.

I have plans to develop a new backtesting engine this year. We will see details later.


Wow RobotParadise is a great and very useful tool, Mr. Popov, please continue with the development of RobotParadise, it would be a great complement to EA Studio. Many of the users who use EA Studio use a slave account to test the profitability of the strategies and then use it in the live account, with this tool it would not be necessary to do this.

Re: Developing a new Programming Language for Addons

> Wow, RobotParadise is a great and very useful tool,

I was amazed when RobotParadise found 80k strategies to profit from new and unseen data!
However, I'm not sure how to present it. The problem is that it is so powerful that, in practice, it finds over-fit strategies.
We need more time to see what is going on.

I'll share more details later.