Zwei-Wege-Kontrakt-Gitterhandel v1.0.2

Schriftsteller:Wind, Datum: 2021-06-24 15:37:17
Tags:Gitter

Zwei-Wege-Kontrakt-Gitterhandel v1.0.2

Funktionen

Vertragsgittergeschäft Und die Differenz wird durch mehr Arbeitszeit profitiert. Es gibt nur wenige Chancen, dass die Zwei-Wege-Strategie platzt.

  • Kaufüberschreitung
  • Verdoppelung
  • Automatisierte Abrechnung
  • Der Trend ist offen (entwickelt, kostenpflichtig)
  • Dynamische Änderungen der Anzahl der Einträge (in der Entwicklung, kostenpflichtige Version)
  • Gold-Fork-Tod-Fork-Trend ist dabei (in Entwicklung, kostenpflichtige Version)

Daten aus der Recherche

img

img

Zweifache Zunahme im Halbjahr 2000 Die Gewinne sind offensichtlich, egal ob der Aufstieg oder der Abstieg.

Pflege

Dauerhafte Optimierung



/*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)
    }
}


Verwandt

Mehr

Hexie8Kann man mehr Währungen haben?

Rich_roryWas bedeutet check. Eine regelmäßige Erhöhung oder Verringerung der Kaufschwelle?

ArtronWie kommt es, dass hier keine Strategieparameter eingestellt sind?

[Übersetzt von Exodus]Auch das Problem wurde entdeckt, dass der gesamte Roboter bei der Rückprüfung von 2020-1-1 bis 2020-6 um 3-30 gestoppt wurde, außerdem wird der Test von ETH bei der Prüfung von 2021-1-1 bis 201-6-21 um 1-2 gestoppt, ob es sich um ein FMZ-Problem oder ein Roboterproblem handelt.

- Ich weiß.Das ist nicht echtes Multi-Space-Hedging, es ist wie ein Netzwerk.

[Übersetzt von Exodus]Der Autor von WeChat reagierte nicht, er konnte nur ein paar Worte sagen und kam hierher, lief 7 Tage, 200 Klingen und 70 Klingen. 1. Ist die zweiseitige Einzahlungsfunktion normal? Siehe, die Strategie sagt, dass die zweiseitige Einzahlung, die Wahrscheinlichkeit, dass der Markt explodiert, sehr gering ist, aber in sieben Tagen, außer wenn der Roboter gerade gestartet wurde, wurde ein zweiseitiges Einzahlungsverfahren durchgeführt, fast kein zweiseitiges Einzahlungsverfahren. Nach meiner Forschung wurde festgestellt, dass eine 10-minütige Aktualisierung der Einzahlungsposition keine Bedeutung hat, was zu langsameren Veränderungen führt, und auch keine zweiseitige Einzahlung. 2. Blasen über die standardmäßige Aufstockung, wenn Sie nicht wollen, dass die Aufstockung benötigt, um sicherzustellen, dass 1.000 bis 2.000 oder mehr Schwergefäße sind, ich habe heute zweihundert Schwergefäße, wenn ich nicht auf einmal aufwache, ich habe die Aufstockung, eine vorläufige Garantie. 3. Bitte fragen Sie mich, ob es bei ausreichend Kapital nie zu einem Börsengang kommt, weil es nie zu einem Verlust kommt, aber warum es bei der Rückprüfung zu einem Verlust kommt? Diese Strategie gefällt mir sehr gut, sie kann unabhängig von der Richtung profitieren, die Anpassung der Aufstockung und des Kapitalbetrags ist nicht sehr riskant, das Gefühl, dass die Anpassung der Offenheiten und der Preise optimiert werden kann, je nachdem, ob das Kapital hinzugefügt wird, die Anpassung der Aufstockung usw.

JaXDer alte Bruder Wechselt

[Übersetzt von Exodus]Das Problem ist gelöst.

[Übersetzt von Exodus]Das ist ein tolles Gefühl, aber es ist nicht möglich, es auf der echten Festplatte zu verwenden. Wenn ich das Token bch öffne, gibt es einen Fehler, 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].

WbsyEs gibt keine echten Platten?

[Übersetzt von Exodus]Das ist eine schreckliche Gewinnkurve, mit einem Verlust von über 120%.

Trunken, mit Licht und Schwert.Sie lachten mich zu Tode.

[Übersetzt von Exodus]Es ist traurig, dass wir heute einen Verlust erlitten haben, und ich freue mich auf 2.0, aber wie kann ich die neue Strategie erleben?

WindDiese Probleme wurden in der Entwicklungsversion 2.0 gefunden. Der Grund dafür, dass es nicht möglich ist, einen Tausch zu machen, ist, dass die Anzahlung festgesetzt ist, also ein Prozent steigt, ein Prozent sinkt, ein Prozent sinkt, ein Prozent steigt. Da es sich um ein Prozent handelt, und das Prozentsatz der Kaufrückgänge gleich ist, von 1.000 Tonnen bis 1.500 Tonnen, sind die 1000 Prozent und die 1500 Prozent unterschiedlich, und es ist schwieriger zu kaufen, und die Preise werden zu häufig geändert, was dazu führt, dass die Ausfälle möglicherweise nicht gekauft werden. Das Problem mit dem Stopp-Loss, in der Version 2.0 wurde eine bestimmte Behandlung durchgeführt, eine sehr einfache Stopp-Loss-Behandlung, aber aus Rückmessdaten ausgehend ist es auch möglich, wenn Sie einen Kurs kaufen oder eine leere Position einnehmen, wenn ein bestimmter Schwellenwert erreicht wird, beginnt der Gesamtbestand zu verkaufen, 1.0 wird nicht behandelt, so dass einige Bestellungen nie ausgeführt werden können. /upload/asset/2034c4ec56c423120b9c6.png /upload/asset/203032c94e60a3915cc9f.png /upload/asset/2030b880b030476977f4b.png /upload/asset/2030d89e9fd59f528be4c.png

WindIch habe mit Binance getestet, ob die laufende Festplatte Fehler auf anderen Plattformen verursachen könnte.

WindDie Festplatte läuft noch, es braucht Zeit.

WindSchauen Sie sich die neueste Kurve an, die zuvor gerade geschrieben wurde.