The resource loading... loading...

Tests - on the long-term effects of Martin

Author: xxs1xxs1, Date: 2021-09-04 01:47:51
Tags:

I don't know if that counts as Martin. I want to do more. I just want to find a price to start trading. For example, a small initial buffer is prepared for a 10% decline. A large buffer can be slowly set to 10% 20% 50% If it can be felt to some extent, there is a high probability of falling. So it's important to stock up. I hope you can use your talents and make some suggestions to make a mechanical trade together. The most important thing is to calculate the acceptance point. Don't blow it up.


/*backtest
start: 2021-05-1 00:00:00
end: 2021-08-28 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
args: [["OpType",1]]
*/

//各功能测试
exchange.SetContractType("swap") //合约设置
// exchange.SetCurrency("TRX_USDT");
//    exchange.SetMarginLevel(20) //合约倍数设置 

//exchange.IO("trade_margin")
//exchange.IO("currency", "STPT_USDT")
var account = _C(exchange.GetAccount) //帐户信息
var log_profit = 0
var log_profit_intervel = 1000 * 60 * 5
var symbol_list = [] //"1.5倍vol,kdj与ma多头"
var symbol_list1 = [] //"3倍vol,当前涨幅4%或者vol5倍"
var symbol_list2 = [] //"三连涨"
var order_list = []
var num = 0 //记录补仓数量
if (_G("symbol")) {
    symbol_list = _G("symbol")
    order_list = _G("orderlist")
    Log("上一次数据", symbol_list)
    Log("上一次数据完成数据", order_list)
}

// 撤单函数
function CancelPendingOrders() {
    Sleep(1000); // 休眠 1秒
    var ret = false;
    while (true) {
        var orders = null;
        // 持续获取未成交订单数组,如果返回异常,则继续获取
        while (!(orders = exchange.GetOrders())) {
            Sleep(1000); // 休眠 1秒
        }
        if (orders.length == 0) { // 如果订单数组为空
            return ret; // 返回撤单状态
        }
        for (var j = 0; j < orders.length; j++) { // 遍历未成交订单数组
            exchange.CancelOrder(orders[j].Id); // 依次取消未成交订单
            ret = true;
            if (j < (orders.length - 1)) {
                Sleep(1000); // 休眠 1秒
            }
        }
    }
}

function symbols() {


    log_profit_intervel = 1000 * 60 * 5


    if (Date.now() - log_profit > log_profit_intervel && !IsVirtual()) { //全部交易对 
        log_profit = Date.now()
        var symbol = JSON.parse(HttpQuery("https://www.binance.com/fapi/v1/exchangeInfo"))
        let symbol_all = []
        symbol.symbols.forEach(function(v, k, arr) {
            if (v.quoteAsset == "USDT" && v.contractType == "PERPETUAL") {
                let str = v.symbol.split("USDT", 1)
                str = str + "_USDT"
                symbol_all.push([str, v.pricePrecision, v.quantityPrecision])
            }
        })

        // exchange.SetCurrency("TRX_USDT");                        //交易对设置
        //exchange.SetPrecision(priceScale, amountScale)            //精度设置


        for (let i = 0; i < symbol_all.length; i++) {

            if (symbol_list.length > 0) {

                let flag = false
                symbol_list.forEach(function(v, k, arr) {
                    //   Log(v[0],symbol_all[i][0])
                    if (v[0] == symbol_all[i][0]) {
                        flag = true;
                    }
                })
                if (flag) {
                    continue;
                }
            }



            exchange.SetCurrency(symbol_all[i][0])
            //  exchange.SetCurrency("DOGE_USDT")
            exchange.SetPrecision(symbol_all[i][1], symbol_all[i][2])
            let records = exchange.GetRecords(60 * 60 * 1)
            let kdj = TA.KDJ(records, 9, 3, 3)
            let ma7 = TA.EMA(records, 7)
            let ma25 = TA.EMA(records, 25)

            //      let records1 = exchange.GetRecords(60 * 15)
            //      let kdj1 = TA.KDJ(records1, 9, 3, 3)

            let len = records.length - 1
            let rs = records[len]
            //      let rs1 = records[len]
            //      if ((rs.Close > rs.Open && rs.Volume > rs1.Volume * 1.5 && rs.Close / rs.Open > 1.04) || (rs.Close > rs.Open && rs.Volume > rs1.Volume * 2)) 
            //     if (rs.Close > rs.Open && _Cross(kdj[0], kdj[1]) > 0 && _Cross(kdj[0], kdj[1]) < 3 && rs.Close / rs.Low < 1.03 && _Cross(kdj1[0], kdj1[1]) > 0 && _Cross(kdj1[0], kdj1[1]) < 3) 

            if (rs.Close > rs.Open && rs.Volume > rs1.Volume * 1.5 && _Cross(kdj[0], kdj[1]) > 0 && _Cross(kdj[0], kdj[1]) < 5 && _Cross(ma7, ma25) > 0) {

                symbol_list.push([symbol_all[i][0], symbol_all[i][1], symbol_all[i][2]]) //加入数据保存

            }
            if ((rs.Close > rs.Open && rs.Volume > rs1.Volume * 2 && rs.Close / rs.Open > 1.04) || (rs.Close > rs.Open && rs.Volume > rs1.Volume * 4)) {
                symbol_list1.push([symbol_all[i][0], symbol_all[i][1], symbol_all[i][2]]) //加入数据保存
            }
            if (records[len - 3].Close > records[len - 3].Open && records[len - 1].Close > records[len - 1].Open && records[len - 2].Close > records[len - 2].Open) {
                symbol_list2.push([symbol_all[i][0], symbol_all[i][1], symbol_all[i][2]]) //加入数据保存
            }

            Sleep(100)
        }
        Log("没数据", symbol_list)
        Log("没数据", symbol_list1)
        Log("三连涨", symbol_list2)

    }
}







function main() {

    let loss = 2
    let loss_m = 0

    while (1) {
        // symbols()



        exchange.SetPrecision(priceScale, amountScale) //精度设置

        exchange.SetMarginLevel(MarginLevel) //合约倍数

        let records = exchange.GetRecords(60 * 60 * 4)
        let kdj = TA.KDJ(records, 9, 3, 3)
        let account = exchange.GetAccount()
        let position = _C(exchange.GetPosition) //持仓信息
        let Amount = position[0] ? position[0].Amount : 0
        let ticker = _C(exchange.GetTicker); // 获取 Tick 数据
        let ma7 = TA.EMA(records, 7)
        let ma25 = TA.EMA(records, 25)
        let money = bet * MarginLevel //买入数量为 2U的商品                

        if (_N(money / ticker.Sell, amountScale) == 0) {
            continue;
        }
        let len = records.length - 1
        if (!position[0] && _Cross(kdj[0], kdj[1]) > 0 && kdj[2][len] > kdj[1][len] + 2) {
            exchange.SetDirection("buy")
            exchange.Buy(-1, money / ticker.Sell, ticker.Last,"开仓价:", ticker.Sell)


        } else if (position[0] && position[0].Profit > position[0].Margin * 0.2) { //盈利20%就清仓

            //     Log(loss_m,position[0])
            exchange.SetDirection("closebuy")
            exchange.Sell(-1, position[0].Amount,ticker.Last, "盈利", position[0].Profit, ticker.Last, "#ff0000")
            loss = 0.6
            num = 0 //计数清零
            CancelPendingOrders() //清理无效定单

        } else if (position[0] &&  _Cross(kdj[0], kdj[1]) < 0 && position[0].Profit > position[0].Margin * 0.1) { //死叉平仓

            //     Log(loss_m,position[0])
            exchange.SetDirection("closebuy")
            exchange.Sell(-1, position[0].Amount,ticker.Last, "死叉平仓", position[0].Profit, ticker.Last, "#00009c")
            loss = 0.6
            num = 0 //计数清零
            CancelPendingOrders() //清理无效定单

        }else if (position[0] && position[0].Margin / bet < 2.5 && position[0].Profit * -1 > position[0].Margin * 0.4) { //本金亏完在补一次

            let nn = 0.2 //指数
            if (position[0].Profit * -1 / position[0].Margin > 0.4) {
                nn = position[0].Profit * -1 / position[0].Margin
                Log(nn, "---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------")

            }

            exchange.SetDirection("buy")
            exchange.Buy(-1, position[0].Amount * nn, ticker.Last,"小补仓", ticker.Last, "持仓数量:", position[0].Amount, "| 浮动亏盈:", position[0].Profit, "| Margin:", position[0].Margin, "| 现有资金:", account.Balance, "| 持仓均价:", position[0].Price, "-------|最大单次浮亏", loss_m, "#0000ff")

            //      CancelPendingOrders() //清理无效定单
        } else if (position[0] && position[0].Margin / bet >= 2.5 && position[0].Margin / bet < 6 && position[0].Profit * -1 > position[0].Margin * 2) { //本金亏完在补一次


            exchange.SetDirection("buy")
            exchange.Buy(-1, position[0].Amount * 2, ticker.Last,"大补仓", ticker.Last, "持仓数量:", position[0].Amount, "| 浮动亏盈:", position[0].Profit, "| Margin:", position[0].Margin, "| 现有资金:", account.Balance, "| 持仓均价:", position[0].Price, "-------|最大单次浮亏", loss_m, "#ccff00")

            //    CancelPendingOrders() //清理无效定单
        }

        Sleep(1000)

        // Log("已经清算的数据",order_list)
        //     Log("结束", symbol_list)
        _G("orderlist", order_list)
        _G("symbol", symbol_list)
        Sleep(1000 * 2)

        if (position[0]) loss_m = position[0].Profit < loss_m ? position[0].Profit : loss_m

        let cmd = GetCommand()
        if (cmd) {
            Log(cmd)
            let arr = cmd.split(":")
            if (arr[0] == "要做空") {
                dan = 100
            } else if (arr[0] == "检查symbol_list") {
                Log("没数据就是没有符合条件的", symbol_list)
            } else if (arr[0] == "已经清算的数据") {

                Log("已经清算的数据", order_list)

            } else if (arr[0] == "清除持久数据数据") {

                Log("已经清算的数据")
                _G(null)

            }



        }
    }
Log( _C(exchange.GetPosition))





}

More

hexie8Can you have multiple currencies?

The BeggarHi, I have a contact number, and I'd like to ask you a few questions, like how to calculate the minimum number of orders for all currencies.

xxs1xxs1You can enter your own currency. You can also choose your conditions. It is recommended that you write in, https://www.fmz.com/strategy/313036, this is the multi-currency version.

xxs1xxs1You need to calculate the point at which you will replenish your position. For example, how much you will lose or how much the current price of the current price of the current price of the current price of the current price of the current price of the current price of the current price of the current price of the current price of the current price of the current price of the current price of the current price of the current price of the current price of the current price of the current price of the current price of the current price of the current price of the current price of the current price of the current price of the current price of the current price of the current price of the current price of the current price of the current price of the current price of the current price of the current price of the current price of the current price of the current price of the current price of the current price of the current price.

The BeggarKDJ has been in condition satisfied, and every minute after that, it triggers a buildup, how am I supposed to handle it?

xxs1xxs1This is about 0.25 U*20 times the current price of the coin, which is probably the minimum order quantity.