How to use dynamic adjustment policy parameters to interact with dynamic adjustment policy

Author: momox, Date: 2015-12-13 23:30:51
Tags: Tool

The strategy requires constant test adjustments, and the parameters are often changed and changed, each time they stop and restart, costing a lot of effort, and also losing the original profitability progress (although it can also be restored through global parameters), in fact botvs has provided a way to dynamically adjust the parameters.


var Interval=2000;

//AAA,BBB为策略中希望动态调整的参数
var AAA=0;
var BBB="hello world";

function main() {
    while(true){
        onTick();
        Sleep(Interval);
    }
}

function onTick(){
    set_command();
    Log("AAA="+AAA,"       BBB="+BBB);
}

//获取动态参数(策略交互内容)
 function set_command() {

     var get_command = GetCommand();//  GetCommand方法是获取参数方法,获取的参数是字符串形式 格式为 "参数名:参数值" 参见BotVS API文档
     if (get_command != null) {
         if (get_command.indexOf("A3:") == 0) {  //如果传入的参数名为A3(以“A3:”打头,即表明是A3参数)

             AAA = (get_command.replace("A3:", "")); //赋值给策略里面的AAA(将打头字符串替换为空,剩下就是我们的参数值)

             Log("AAA变成:" + AAA);
         }
         
          if (get_command.indexOf("B3:") == 0) {  //如果传入的参数名为B3(以“B3:”打头,即表明是B3参数)

             BBB = (get_command.replace("B3:", "")); //赋值给策略里面的BBB(将打头字符串替换为空,剩下就是我们的参数值)

             Log("BBB变成:" + BBB);
         }

     }
 }

Related

More

OnionsIs there a way to trigger it automatically?

jxhbtcGood. Thank you.

jxhbtcHi, is this to be copied into the policy or run independently?

OnionsNewcomer, thank you for your guidance

momoxIt's a bit strange to ask, automatically triggering yourself to write in the OnTick function is fine, in it you judge the conditions, satisfied, why why why?

momoxThis is just an example that can be run independently to see what happens, but the real thing is to reference my code and then use it in your own policy, and the way to do that is to copy and paste the code into your policy, and AAA, BBB, and change it to the parameters in your own policy.