The resource loading... loading...

The balance strategy of the bearish bullish U

Author: VIC, Date: 2022-01-08 19:35:36
Tags:

  • The contract version of Buffett's money-balance strategy, which is the default for direct half-trades, is a multi-contract.
  • Binance BUSD does not have a fee attached to the transaction, which allows you to minimize the interval between balance processing and eat the maximum profit and return of the transaction fee.
  • Both the principle and the code are very simple, based on the writing of the builders, to calculate in advance the hanging single point, the number of hands to be hanged, theoretically the larger the capital, the higher the yield.
  • Less than 1000 U is not recommended to run, and the restriction of the minimum order value causes the hanging order gap to be too large.
  • In addition, the government has also announced that it will not be able to make a profit if the price of the currency rises or falls.
  • Can be replicated directly
  • The downside is that the market needs to be volatile or slow, and long-term bear markets will accumulate more positions, but will not break out.
  • Finally, after trying Martin's negative expectations, the high competition of high-frequency bidding, maybe returning to value investing is the ultimate way to win.
  • Welcome to share this strategy with my VX.



/*backtest
start: 2019-12-01 00:00:00
end: 2024-02-07 23:59:00
period: 30m
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"ETH_USDT","balance":100000}]
args: [["pricePrecision",2],["amountPrecision",3],["linjie",30]]
*/

function cancelAll() {
    while (1) {
        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].Id)
            Sleep(100)
        }
        Sleep(100)
    }
}
function onexit() {
    //
    cancelAll()
}

function main() {
    exchange.SetContractType("swap")
    exchange.SetPrecision(pricePrecision, amountPrecision) //精度
    exchange.SetMarginLevel(leverage) //杠杆
    //LogProfitReset()
    LogReset(1)
    var buyOrderId
    var sellOrderId
    while (1) {
        var pos = _C(exchange.GetPosition)
        if (pos.length > 0) {
            var Mar = pos[0].Margin //保证金
        } else {
            var Mar = 0
        }

        var MarginLevel = leverage //杠杆
        var account = _C(exchange.GetAccount)
        var Bala = account.Balance //可用余额
        var Bal = Bala - Mar * (MarginLevel - 1) //去掉仓位的余额
        var ticker = _C(exchange.GetTicker)
        var price = ticker.Last //最新价
        var Qian = Mar + Bala
        LogStatus("币价:", price,"权益:",Qian)
        var orders = _C(exchange.GetOrders)
        if (orders.length == 0) { //没有订单
            if (Mar * MarginLevel - Bal > 2 * linjie) { //仓位价值多于余额 //临界价值
                exchange.SetDirection("closebuy")
                var Amount = 0.5 * (Mar * MarginLevel - Bal) / price
                exchange.Sell(-1, Amount)
            } else if (Bal - Mar * MarginLevel > 2 * linjie) { //余额多于仓位价值 //临界价值
                var Amount = 0.5 * (Bal - Mar * MarginLevel) / price
                exchange.SetDirection("buy")
                exchange.Buy(-1, Amount)
            } else {//状态平衡时双向挂单
                var Bprice = price * (Bal - linjie) / (Mar * leverage)
                var BAmount = 0.5 * linjie / Bprice
                exchange.SetDirection("buy")
                buyOrderId = exchange.Buy(Bprice, BAmount)
                var Sprice = price * (Bal - (-linjie)) / (Mar * leverage)
                var SAmount = 0.5 * linjie / Sprice
                exchange.SetDirection("closebuy")
                sellOrderId = exchange.Sell(Sprice, SAmount)
            }


        } else { //有订单
            var isFindBuyId = false
            var isFindSellId = false
            //Log("初始状态")
            for (var i = 0; i < orders.length; i++) {

                if (buyOrderId == orders[i].Id) {
                    isFindBuyId = true
                    //Log("有买单")
                }
                if (sellOrderId == orders[i].Id) {
                    isFindSellId = true
                    //Log("有卖单")
                }
            }
            if (!isFindBuyId || !isFindSellId) { //有一方成交,取消订单进入新循环
                cancelAll()
                var Qian = Mar + Bala
                LogProfit(Qian)
                //LogStatus("币价:", price)
            }

        }
        Sleep(5000)
    }
}

More

hexie8Is it possible to have multiple varieties?

VICIn the meantime, I'm going to go and see if I can get my money back.

VICIt's a single coin that can be customized if the owner wants it.