Negociação em rede de contratos bidirecionais v1.0.2

Autora:vento, Data: 2021-06-24 15:37:17
Tags:Grelha

Negociação em rede de contratos bidirecionais v1.0.2

Funções

Negociação de grelhas A diferença de lucro é feita por fazer mais tempo livre. A estratégia bidireccional é uma estratégia que tem pouca probabilidade de explodir.

  • Comprar com antecedência
  • Duplicação
  • Listagem automática
  • Tendências abertas (a ser desenvolvidas, versão paga)
  • Dinâmica de mudança de taxa de crescimento (em desenvolvimento, versão paga)
  • A tendência de forcados de ouro se juntou (em desenvolvimento, versão paga)

Revisão de dados

img

img

duplicou nos seis meses do ano 2000. Os benefícios são óbvios, que podem ser mantidos, seja em alta ou em baixa.

Manutenção

Optimização contínua



/*backtest
start: 2021-01-01 00:00:00
end: 2021-06-21 23:59:00
period: 1m
basePeriod: 1m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT","balance":2000}]
*/

// 首次买入
let FIRST_BUY = true;
// 已存在买涨订单
let MANY_BUYING = false;
// 已存在做空订单
let SHORT_BUYING = false;
// 买涨订单创建时间
let MANY_BUY_TIME = null;
// 做空订单创建时间
let SHORT_BUY_TIME = null;
// 买涨空仓时间
let MANY_EMPTY_STEP_TIME = null;
// 做空空仓时间
let SHORT_EMPTY_STEP_TIME = null;
// 校验空仓时间
let CHECK_TIME = null;

let QUANTITY = [0.001, 0.002, 0.004, 0.008, 0.016, 0.032, 0.064];
// 下次购买价格(多仓)
let MANY_NEXT_BUY_PRICE = 0;
// 下次购买价格(空仓)
let SHORT_NEXT_BUY_PRICE = 0;
// 当前仓位(多仓)
let MANY_STEP = 0;
// 当前仓位(空仓)
let SHORT_STEP = 0;
// 止盈比率
let PROFIT_RATIO = 1;
// 补仓比率
let DOUBLE_THROW_RATIO = 1.5;
// 卖出后下次购买金额下浮比率
let BUY_PRICE_RATIO = 1;
// 交易订单列表(多仓)
let MANY_ORDER_LIST = [];
// 交易订单列表(空仓)
let SHORT_ORDER_LIST = [];

function getManyQuantity() {
    if (MANY_STEP < QUANTITY.length) {
        return QUANTITY[MANY_STEP]
    }
    return QUANTITY[0]
}

function getShortQuantity() {
    if (SHORT_STEP < QUANTITY.length) {
        return QUANTITY[SHORT_STEP]
    }
    return QUANTITY[0]
}

function firstManyBuy(ticker) {
    if (MANY_BUYING) {
        return
    }
    exchange.SetDirection("buy")
    let orderId = exchange.Buy(ticker.Last, getManyQuantity())
    if (!orderId) {
        return
    }
    MANY_BUYING = true
    while (true) {
        exchange.SetDirection("buy") 
        let order = exchange.GetOrder(orderId)
        if (null === order) {
            continue
        }
        if (1 === order.Status || 2 === order.Status) {
            MANY_NEXT_BUY_PRICE = order.Price * ((100 - DOUBLE_THROW_RATIO) / 100)
            MANY_STEP = MANY_STEP + 1
            MANY_BUYING = false
            MANY_EMPTY_STEP_TIME = null
            let sellPrice = order.Price * ((100 + PROFIT_RATIO) / 100)
            MANY_ORDER_LIST.push({
                buyPrice: order.Price,
                sellPrice: sellPrice,
                quantity: order.Amount,
                isSell: false,
            })
            break
        }
    }
}

function firstShortBuy(ticker) {
    if (SHORT_BUYING) {
        return
    }
    exchange.SetDirection("sell")
    let orderId = exchange.Sell(ticker.Last, getShortQuantity())
    if (!orderId) {
        return
    }
    SHORT_BUYING = true
    while (true) {
        let order = exchange.GetOrder(orderId)
        if (null === order) {
            continue
        }
        if (1 === order.Status || 2 === order.Status) {
            SHORT_NEXT_BUY_PRICE = order.Price * ((100 + DOUBLE_THROW_RATIO) / 100)
            SHORT_STEP = SHORT_STEP + 1
            SHORT_BUYING = false
            SHORT_EMPTY_STEP_TIME = null
            let sellPrice = order.Price * ((100 - PROFIT_RATIO) / 100)
            SHORT_ORDER_LIST.push({
                buyPrice: order.Price,
                sellPrice: sellPrice,
                quantity: order.Amount,
                isSell: false,
            })
            break
        }
    }
}

function manyBuy(ticker) {
    if (MANY_BUYING) {
        return
    }
    Log('ticker: ' + ticker.Last + ' MANY_NEXT_BUY_PRICE: ' + MANY_NEXT_BUY_PRICE)
    if (ticker.Last > MANY_NEXT_BUY_PRICE) {
        return
    }
    exchange.SetDirection("buy")
    let orderId = exchange.Buy(ticker.Last, getManyQuantity())
    if (!orderId) {
        return
    }
    MANY_BUYING = true
    MANY_BUY_TIME = Unix()
    while (true) {
        let now = Unix()
        let order = exchange.GetOrder(orderId)
        let expire = MANY_BUY_TIME + (60 * 30)
        if (null === order) {
            continue
        }
        // 买入成功处理
        if (1 === order.Status || 2 === order.Status) {
            MANY_NEXT_BUY_PRICE = order.Price * ((100 - DOUBLE_THROW_RATIO) / 100)
            MANY_STEP = MANY_STEP + 1
            MANY_BUYING = false
            MANY_EMPTY_STEP_TIME = null
            let sellPrice = order.Price * ((100 + PROFIT_RATIO) / 100)
            MANY_ORDER_LIST.push({
                buyPrice: order.Price,
                sellPrice: sellPrice,
                quantity: order.Amount,
                isSell: false,
            })
            break
        }
        // 买入超时处理
        if (now >= expire) {
            exchange.CancelOrder(orderId)
            MANY_BUYING = false
            MANY_BUY_TIME = null
            MANY_NEXT_BUY_PRICE = ticker.Last * ((100 - DOUBLE_THROW_RATIO) / 100)
            return
        }
    }
}

function shortBuy(ticker) {
    if (SHORT_BUYING) {
        return
    }
    Log('ticker: ' + ticker.Last + ' SHORT_NEXT_BUY_PRICE: ' + SHORT_NEXT_BUY_PRICE)
    if (ticker.Last < SHORT_NEXT_BUY_PRICE) {
        return
    }
    exchange.SetDirection("sell")
    let orderId = exchange.Sell(ticker.Last, getShortQuantity())
    if (!orderId) {
        return
    }
    SHORT_BUYING = true
    SHORT_BUY_TIME = Unix()
    while (true) {
        let now = Unix()
        let expire = SHORT_BUY_TIME + (60 * 30)
        let order = exchange.GetOrder(orderId)
        if (null === order) {
            continue
        }
        // 买入成功处理
        if (1 === order.Status || 2 === order.Status) {
            SHORT_NEXT_BUY_PRICE = order.Price * ((100 + DOUBLE_THROW_RATIO) / 100)
            SHORT_STEP = SHORT_STEP + 1
            SHORT_BUYING = false
            SHORT_EMPTY_STEP_TIME = null
            let sellPrice = order.Price * ((100 - PROFIT_RATIO) / 100)
            SHORT_ORDER_LIST.push({
                buyPrice: order.Price,
                sellPrice: sellPrice,
                quantity: order.Amount,
                isSell: false,
            })
            break
        }
        // 买入超时处理
        if (now >= expire) {
            exchange.CancelOrder(orderId)
            SHORT_BUYING = false
            SHORT_BUY_TIME = null
            SHORT_NEXT_BUY_PRICE = ticker.Last * ((100 + DOUBLE_THROW_RATIO) / 100)
            return
        }
    }
}


function manySell(ticker) {
    // 遍历卖出订单
    for (let item of MANY_ORDER_LIST) {
        if (item.isSell) {
            continue
        }
        if (ticker.Last >= item.sellPrice) {
            item.isSell = true;
            exchange.SetDirection("closebuy")
            let orderId = exchange.Sell(ticker.Last, item.quantity)
            if (!orderId) {
                return
            }
            while (true) {
                let order = exchange.GetOrder(orderId)
                if (null === order) {
                    continue
                }
                if (1 === order.Status || 2 === order.Status) {
                    MANY_NEXT_BUY_PRICE = ticker.Last * ((100 - BUY_PRICE_RATIO) / 100)
                    MANY_STEP = MANY_STEP - 1
                    if (0 === MANY_STEP) {
                        MANY_EMPTY_STEP_TIME = Unix()
                    }
                    break
                }
            }
        }
    }
}

function shortSell(ticker) {
    // 遍历卖出订单
    for (let item of SHORT_ORDER_LIST) {
        if (item.isSell) {
            continue
        }
        if (ticker.Last <= item.sellPrice) {
            item.isSell = true;
            exchange.SetDirection("closesell")
            let orderId = exchange.Buy(ticker.Last, item.quantity)
            if (!orderId) {
                return
            }
            while (true) {
                let order = exchange.GetOrder(orderId)
                if (null === order) {
                    continue
                }
                if (1 === order.Status || 2 === order.Status) {
                    SHORT_NEXT_BUY_PRICE = ticker.Last * ((100 + BUY_PRICE_RATIO) / 100)
                    SHORT_STEP = SHORT_STEP - 1
                    if (0 === SHORT_STEP) {
                        SHORT_EMPTY_STEP_TIME = Unix()
                    }
                    break
                }
            }
        }
    }
}

function check(ticker) {
    let now = Unix()
    if (null !== CHECK_TIME) {
        let expire = CHECK_TIME + (60 * 10)
        if (now < expire) {
            return
        }
    }
    CHECK_TIME = now

    if (null !== MANY_EMPTY_STEP_TIME) {
        let expire = MANY_EMPTY_STEP_TIME + (60 * 30)
        if (now >= expire) {
            MANY_NEXT_BUY_PRICE = ticker.Last * ((100 - DOUBLE_THROW_RATIO) / 100)
            Log('没有买涨持仓, 调整买入价: ' + MANY_NEXT_BUY_PRICE)
        }
    }
    
    if (null !== SHORT_EMPTY_STEP_TIME) {
        let expire = SHORT_EMPTY_STEP_TIME + (60 * 30)
        if (now >= expire) {
            SHORT_NEXT_BUY_PRICE = ticker.Last * ((100 + DOUBLE_THROW_RATIO) / 100)
            Log('没有做空持仓, 调整买入价: ' + SHORT_NEXT_BUY_PRICE)
        }
    }
}

function onTick() {
    // 在这里写策略逻辑,将会不断调用,例如打印行情信息
    let ticker = exchange.GetTicker()
    if (!ticker) {
        return
    }
    if (FIRST_BUY) {
        // 首次做多购买
        firstManyBuy(ticker)
        // 首次做空购买
        firstShortBuy(ticker)
        FIRST_BUY = false
        return
    }
    
    // 做多买入
    manyBuy(ticker)
    // 做空买入
    shortBuy(ticker)
    // 做多卖出
    manySell(ticker)
    // 做空卖出
    shortSell(ticker)
    // 空仓检测
    check(ticker)
}

function main() {
    // 开合约
    exchange.SetContractType("swap")

    while(true){
        onTick()
        // Sleep函数主要用于数字货币策略的轮询频率控制,防止访问交易所API接口过于频繁
        Sleep(60000)
    }
}


Relacionados

Mais.

Hexie8Pode-se ter mais moeda?

Rich_roryO que significa check...........................................................................................................................................................................................................................................................

artronComo é que isto não tem parâmetros de política definidos?

Exodus [tradução]Também descobrimos o problema: no retest 2020-1-1 até junho de 2020, o robô inteiro parou no 3-30, além disso, no teste 2021-1-1 até 201-6-21, o ETH parou no 1-2, não sei se é um problema de fmz ou um problema do robô.

Evan.Não pode ser uma verdadeira cobertura multi-espaço, como uma rede de contratos.

Exodus [tradução]O WeChat não respondeu, só posso vir aqui e dizer algumas palavras, funcionou por 7 dias, 200 caixas de ouro e 70 caixas. 1. O binário é normal? Veja a estratégia diz binário, a probabilidade de estoque é muito pequena, mas em sete dias, exceto quando o robô é iniciado, o binário é aberto em dois sentidos, quase nenhum binário é aberto. Após minha pesquisa, descobri que 10 minutos de atualização de um posicionamento de aberto, o que resulta em mudanças lentas não faz sentido, nem o binário é aberto em dois sentidos, por exemplo, hoje a queda de 5% do BTC hoje não foi aberto. 2. explodir sobre o capital de acréscimo por padrão, não quero que o acréscimo precise garantir o financiamento de 1000 a 2000 ou mais, eu tenho 200 armas hoje se não for por algum motivo eu já explodi, dinheiro adicionado temporário. Se o dinheiro não for suficiente, você também pode ajustar manualmente o número de acréscimo, aqui lembre-se, para não ver o acréscimo do código. 3. Por favor, pergunte-me, porque nunca pára de perder, então, se o capital for suficiente, nunca vai explodir, mas por que há um prejuízo na revisão? A estratégia que eu gosto é que você pode ganhar independentemente da direção, ajustar o aumento de posições e o risco de expansão de capital não é grande, a sensação de ajustar o preço aberto e o preço excessivo pode ser otimizado, de acordo com o capital adicionado, ajuste o aumento de posições, etc.

SimXO meu irmão telegrafia

Exodus [tradução]Resolvido, o Bitcoin está pronto.

Exodus [tradução]Veja a revisão parece boa, mas parece que não pode ser usado no disco real? Se eu abrir o token bch, o erro será reportado, Sell ((490.14, 0.001): map[err_code:1067 err_msg:The volume field is illegal. Please re-enter. status:error ts:1.625132342294e+12].

WbsyNão há disco real?

Exodus [tradução]A curva de ganhos é terrível, perdemos mais de 120%.

Embebedado, pegou na lâmpada e olhou para a espada.Riram-me até à morte.

Exodus [tradução]É uma pena, hoje é uma grande perda, estou ansioso para a versão 2.0, por favor, pergunte-me como posso experimentar a nova estratégia.

ventoOs problemas foram encontrados no desenvolvimento da versão 2.0. A razão pela qual não é possível fazer um desconto é porque a percentagem de pagamento é fixa, ou seja, um aumento de um por cento, fazer um desconto, cair de um por cento, comprar um desconto. Como a queda é de um por cento, a queda na porcentagem de compra é consistente, de 1.000 toneladas para 1.500, e o por cento de 1.000 e o por cento de 1.500 são diferentes, o vazio é mais difícil de comprar, e a mudança de preço é muito frequente, o que leva o vazio pode não ser comprado. O problema do stop loss, em versão 2.0, foi feito um certo processamento, um processamento de stop loss muito simples, mas a partir dos dados de retrospecção, o efeito ainda pode ser, quando você compra um lote ou faz uma posição vazia, quando atingir um determinado limiar, o estoque completo começa a ser vendido, o 1.0 não é processado, por isso ocorrerá que algumas ordens nunca poderão ser executadas, por exemplo, no BTC 65000 o número de compradores 0.001, então o BTC caiu. /upload/asset/2034c4ec56c423120b9c6.png /upload/asset/203032c94e60a3915cc9f.png /upload/asset/2030b880b030476977f4b.png

ventoEu testei o disco real em Binance, que está sendo executado, e outras plataformas podem apresentar erros.

ventoO disco real ainda está em andamento e precisa de tempo.

ventoOlhe para a curva mais recente, há um bug escrito antes.