资源加载中... loading...

商品期货网格参数生成器

Author: 扫地僧, Date: 2021-11-04 17:12:16
Tags: 商品期货网格My语言


/*
(合约A&合约B)开仓价差:平仓价差:操作数量,开仓价差:平仓价差:操作数量
(MA705&MA709)30:15:1;40:25:1;50:35:1;60:45:1(FG705&FG709)10:0:1;15:5:1;20:10:1;25:15:1
(MA705&MA709)30:15:1;40:25:1;50:35:1;60:45:1(FG705&FG709)10:0:1;15:5:1;20:10:1;25:15:1
(MA705&MA709)30:15:1;40:25:1;50:35:1;60:45:1(FG705&FG709)10:0:1;15:5:1;20:10:1;25:15:1(rb1805&rb1809)10:0:1;15:5:1;20:10:1;25:15:1;30:20:1;35:25:1;40:30:1;45:35:1;50:40:1;55:45:1
*/

// 参数
/*
1、 起始差价       DiffBegin
2、 结束差价       DiffEnd
3、 平仓利润       CoverProfit
4、 节点操作数量    PointDealAmount
5、 节点间距       PointDistance
说明: 合约组合,起始差价,结束差价,平仓利润,节点操作数量,节点间距
*/ 

// 参数 
/*
var Configure_1 = "MA705&MA709,30,60,15,1,10"
var Configure_2 = "FG705&FG709,10,25,10,1,5"
var Configure_3 = "null"
var Configure_4 = "null"
var Configure_5 = "null"
var Configure_6 = "null"
*/

var Configures = [Configure_1, Configure_2, Configure_3, Configure_4, Configure_5, Configure_6]

function String2Number(pstr){
	var ret = Number(pstr)
	if(isNaN(ret)) {
		throw "参数不是 数值字符串!参数:" + pstr
	}
	return ret
}

function main(){
	var paramStr = ""
	var paramArr = []
    for(var i = 0; i < Configures.length; i++){
    	if(Configures[i] == "null"){
    		continue
    	}
    	var configureStrArr = Configures[i].split(",")
    	if(configureStrArr.length !== 6){
    		throw "参数配置错误:" + configureStrArr + " 位置: 第" + (i + 1) + "组参数。"
    	}
        
        // 赋值 生成 仓位控制表的 参数
        var diffBegin = String2Number(configureStrArr[1])
        var diffEnd = String2Number(configureStrArr[2])
        var coverProfit = String2Number(configureStrArr[3])
        var pointDealAmount = String2Number(configureStrArr[4])
        var pointDistance = String2Number(configureStrArr[5])
        
        // 生成参数
        var strPartOfParam = ""
        for(var j = diffBegin; j <= diffEnd; j += pointDistance){
            if(j == diffBegin){
                strPartOfParam += j + ":" + (j - coverProfit) + ":" + pointDealAmount
            }else{
                strPartOfParam += ";" + j + ":" + (j - coverProfit) + ":" + pointDealAmount
            }
        }

        paramArr.push("(" + configureStrArr[0] + ")" + strPartOfParam)
    }
    
    for(var n = 0; n < paramArr.length; n++){
    	paramStr += paramArr[n]
    }

    Log(paramStr)
}

template: strategy.tpl:40:21: executing "strategy.tpl" at <.api.GetStrategyListByName>: wrong number of args for GetStrategyListByName: want 7 got 6