The resource loading... loading...

60 lines of code to implement an idea -- the contract copying strategy.

Author: Inventors quantify - small dreams, Created: 2022-03-19 14:37:08, Updated: 2023-09-20 09:03:57

img

网格策略、马丁策略这种喜欢震荡行情的策略有其固有弊端,在ETH合约市场上也测试了一段时间的类似策略。也经常和FMZ.COM上的新老玩家们聊天分享经验。对于此类策略,有一点是非常赞同一位朋友的说法的。那就是币圈中做合约,做多相对于做空风险小了那么一丢丢。或者简单说就是下跌最惨就是归零,上涨是无限的。

So, Martin, is a strategy like doing more, doing nothing, pulling a long-range distribution of transcription risks better than doing both sides? This sounds good, but no one knows if it will stand up to the real world. But at least we can simply retest this idea. So we have today's article on how to design a contract transcription strategy.

基于FMZ.COM迅捷开发

The code to implement this idea is really very simple, thanks to the flexibility of the platform, the interface packaging, the powerful feedback system, etc. The entire code is only 60 lines (for code writing specifications, a lot of what can be abbreviated is not abbreviated).

The design of the strategy idea is simple, according to the initial price at the beginning of the logic, the interval is hung up and down, the price continues to go down, then continue to hang up the invoice, continue to copy. Then hang up the settlement order based on the holding price increases a certain profit margin, wait for the settlement. If the holding, then at the current price as the initial price repeat the above logic.

The source code of the strategy:

function cancelAll() {
    while (true) {
        var orders = _C(exchange.GetOrders)
        if (orders.length == 0) { 
            break 
        }
        for (var i = 0 ; i < orders.length ; i++) {
            exchange.CancelOrder(orders[i].Id, orders[i])
            Sleep(interval)
        }
    }
}

function getLong(arr, kind) {
    var ret = null 
    for (var i = 0 ; i < arr.length ; i++) {
        if (arr[i].Type == (kind == "pos" ? PD_LONG : ORDER_TYPE_BUY)) {
            ret = arr[i]
        }
    }
    return ret
}

function pendingBidOrders(firstPrice) {
    var index = 0
    var amount = baseAmount
    while (true) {
        var pos = _C(exchange.GetPosition)
        var price = firstPrice - index * baseSpacing
        amount *= ratio
        index++
        exchange.SetDirection("buy")
        exchange.Buy(price, amount)        
        if (pos.length != 0) {
            var longPos = getLong(pos, "pos")
            if (longPos) {
                exchange.SetDirection("closebuy")
                exchange.Sell(longPos.Price + profitTarget, longPos.Amount)
            }
        }
        while (true) {
            Sleep(interval)
            if (!getLong(_C(exchange.GetOrders), "orders")) {
                cancelAll()
                break
            }
            if (!getLong(_C(exchange.GetPosition), "pos")) {
                cancelAll()
                return 
            }
        }
    }
}

function main() {
    exchange.SetContractType(symbol)
    while (true) {
        pendingBidOrders(_C(exchange.GetTicker).Last)
    }
}

The design of the parameters is also simple:

img

This is just a few parameters.

Look at these dozens of lines of code.

In this case, you can set the timeframe of the retest:

img

Re-testing is running:

img

img

It looks like a lot of grid, Martin-type tactics taste.• New students who are learning the introduction are not afraid of the long strategy, easy to be dissuaded.• Short refined strategies are more suitable for introduction, easier to digest strategic ideas, learn logical design.

Strategic code is only for learning, research and development.


Related

More

Ally/upload/asset/1dd6dcfd4579dc0b239a6.jpeg After running it, it returns an error and then it keeps hanging up, unrolling indefinitely, how to solve it

Dreams are worth eight figures.Is this strategy only for Binance?

Dreams are worth eight figures.What does the position growth coefficient mean?

Dreams are worth eight figures.Why is there no policy address?

Inventors quantify - small dreamsIs it running multiple disks, if two disks are running on one server, the frequency doubles, and so on.

Ally/upload/asset/1dd36e54848c3bdf8c759.jpeg This is a list of all the different ways /upload/asset/1dd36e54848c3bdf8c759.jpeg is credited in the database. So I'm logically going to say that this parameter is two rounds of up to 120 visits per minute, and it's not going to exceed the Binance limit of 1200 visits per minute.

Inventors quantify - small dreamsHello, this is not about strategy, you can set the routing interval in the Mac language template parameters to be a little larger. If you run multiple disks on a server and all access the interface of an exchange, then the frequency will be doubled, it is easy to exceed the frequency limit.

Ally/upload/asset/1dce38677beaf3c7ca065.jpeg I'm not sure what you mean. Now that Binance can't support the Mac language policy, it will tell you how to use the web to update in real time to avoid the API block.

Inventors quantify - small dreamsI'm not being polite, I just wrote to support FMZ's quantification.

AllyWell, thank you. I know.

Inventors quantify - small dreamsHello, this is a teaching strategy, mainly explaining the idea that you can run a binary futures perpetual contract, running OK needs to modify the strategy. The reason for the above problem is that the next unit is a prime number, OKX is the one that requires the next unit to be a contract integer.

Inventors quantify - small dreamsIt is possible to run all of them, i.e. the parameters can be adjusted and run.

Inventors quantify - small dreamsThis strategy is just a teaching strategy, never play it, retesting research learning can be done. Copy the source code of the strategy, but also add policy parameters, such as the screenshot in the article.

Inventors quantify - small dreamsSetting 2 is 2 times the storage.