Loading ...

网格挂单加马丁倍数递增

Author: Zer3192, Date: 2022-03-27 15:32:44
Tags:


/*backtest
start: 2017-06-26 00:00:00
end: 2022-02-16 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"ETH_USDT"}]
*/
var MarginLevel=20
exchange.SetMarginLevel(MarginLevel)
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 bet=ratio
    var n = baseAmount
    while (true) {
        var pos = _C(exchange.GetPosition)
        var price = firstPrice - index * baseSpacing
         n=n*ratio
        index++
        exchange.SetDirection("buy")
        exchange.Buy(price, amount=n)        
        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)
    }
}

More

ewbit12 能不能改成现货,有偿付费.联系我13751002051微信

hexie8 有没有多币种的,可以添加很多交易对的那种