Large and small three-cycle leap strategies V2.0_ spot_test

Author: Quantification of district classes, Date: 2019-12-07 17:52:33
Tags:

In general, the big cycle indicates the direction of the market, the middle cycle is the current operating cycle, and the small cycle indicates the trend stop signal. When you enter, as long as you visit the state of the big and small three-cycle, you can be like Grigori, take a multi-faceted strategy to deal with complex markets. If your operating cycle frequency is several times a day, the big cycle can choose the day line, the middle cycle can choose 4 hours, the small cycle can choose 30 minutes; if your operating cycle frequency is ten times a day, the big cycle can choose 4 hours, the middle cycle can choose 30 minutes, the small cycle can choose 5 minutes; the difference between the end of one cycle and the next cycle is always 6 to 8 times. And then we're going to draw the relationship between the K-line and the B-line of each cycle, and we're going to have eight states, three cycles, eight states.88 = 512 states, which are enough to handle all possible disks, and the technically competent programmer can design the best single-point sub-bit and stop-loss bit of each state in advance. To give everyone a basis for discussion, the block manager has also made the policy public on the inventor platform, and you are welcome to improve on this basis. And then we go back and we can see the ageing of 29 and the retracement is slightly higher, up to 36%.img img
imgThe main reasons for this analysis are: 1st, the structure of large and medium-sized cycles is good, but the strategy of how small cycles affect the medium cycle is poorly conceived, it can be simplified first and then supplemented; 2nd, when the market is empty, you should firmly abandon the position The orientation of the 3-day and 5-day averages is important and is not reflected in the strategy. 4th, rapid decline outside the brown line, should sell 5th, stop the rise and stop the loss in time when the reason for the fallimg imgAfter targeted improvements, dozens of iterations, we finally made the annualization rate to 210, reversed to 16.4, and the number of transactions dropped.


/*backtest
start: 2019-01-01 00:00:00
end: 2019-10-10 00:00:00
period: 1d
exchanges: [{"eid":"OKEX","currency":"ETH_USDT","stocks":0}]
args: [["OpMode",1,10989],["MaxAmount",1,10989],["TradeFee",0.001,10989]]
*/
//注册币乎后https://m.bihu.com/signup?i=1ewtKO&s=4&c=4
//搜索 物联网区块链 可以联系到作者区班主 你也可以给我写邮件tomjava@163.com
var midStatus = 0; //中周期状态
var bigStatus = 0; //大周期状态
var beforeBigStatus = 0; //之前大周期状态
var operPrice;
var markTime=0;

function mySell(rate){
   var account = _C(exchange.GetAccount);
   var ticker = _C(exchange.GetTicker);
   var nowPrice=ticker.Sell;
     
   //以下开始卖出
   var allAmount=account.Balance+account.Stocks*ticker.Sell; //计算出总金额
   var cashRatio=account.Balance*100/allAmount;
   
   if(cashRatio<90){  //现金比率小于10,才可以卖出
      if(rate==1){ //卖出1份
          if(cashRatio<80){
              $.Sell(allAmount*0.1/nowPrice);
              Log("现金比率",cashRatio+10);
          }else{
              $.Sell(allAmount*0.05/nowPrice);
              Log("现金比率",cashRatio+5);
          }
      }else{
          if(cashRatio<75){
              $.Sell(allAmount*0.2/nowPrice);
              Log("现金比率",cashRatio+20);
          }else{
              $.Sell(allAmount*0.1/nowPrice);
              Log("现金比率",cashRatio+10);
          }
      }
   }
}

function myBuy(rate){
   var account = _C(exchange.GetAccount);
   var ticker = _C(exchange.GetTicker);
   var nowPrice=ticker.Sell;
     
   //以下开始买入
   var allAmount=account.Balance+account.Stocks*ticker.Sell; //计算出总金额
   var cashRatio=account.Balance*100/allAmount;
   //Log("需要买入比率",rate);
   if(cashRatio>10){  //现金比率大于10,才可以买入
      if(rate==1){ //买入1份
          if(cashRatio>20){
              $.Buy(allAmount*0.1/nowPrice);
              Log("现金比率",cashRatio-10);
          }else{
              $.Buy(allAmount*0.05/nowPrice);
              Log("现金比率",cashRatio-5);
          }
      }else{
          if(cashRatio>25){
              $.Buy(allAmount*0.2/nowPrice);
              Log("现金比率",cashRatio-20);
          }else{
              $.Buy(allAmount*0.1/nowPrice);
              Log("现金比率",cashRatio-10);
          }
      }
   }
}

function oper(){
    var ticker = _C(exchange.GetTicker);
    var nowPrice=ticker.Sell;
   
    var h1records = exchange.GetRecords(PERIOD_H1);
    var h1boll;var h1upLine;var h1midLine;var h1downLine;
    var h1bw;
    if(h1records && h1records.length > 20) {
        h1boll = TA.BOLL(h1records, 20, 2);
        h1upLine = h1boll[0][h1records.length-1];
        h1midLine = h1boll[1][h1records.length-1];
        h1downLine = h1boll[2][h1records.length-1];
    }
    
    var drecords = exchange.GetRecords(PERIOD_D1);
    var dboll;var dupLine;var dmidLine;var ddownLine;
    var dbw;var beforePrice;
    if(drecords && drecords.length > 20) {
        dboll = TA.BOLL(drecords, 20, 2);
        dupLine = dboll[0][drecords.length-1];
        dmidLine = dboll[1][drecords.length-1];
        ddownLine = dboll[2][drecords.length-1];
        dbw=dupLine-dmidLine;
        beforePrice=(drecords[drecords.length-2].Open+drecords[drecords.length-2].Close)/2;
    }
    
    if(ticker.Time-markTime<15*60*1000){ //只有满足15分钟间隔,才允许判断状态
        return;
    }else{
        markTime=ticker.Time;
    }
    
    if(h1records && h1records.length > 20 && drecords && drecords.length > 20) {
        if(nowPrice>dupLine+dbw*0.1){
            bigStatus=0;
        }else if(nowPrice>dupLine-dbw*0.1){
            bigStatus=1;
        }else if(nowPrice>dmidLine+dbw*0.1){
            bigStatus=2;
        }else if(nowPrice>dmidLine){
            bigStatus=3;
        }else if(nowPrice>dmidLine-dbw*0.1){
            bigStatus=4;
        }else if(nowPrice>ddownLine+dbw*0.1){
            bigStatus=5;
        }else if(nowPrice>ddownLine-dbw*0.1){
            bigStatus=6;
        }else{
            bigStatus=7;
        }
        
        if(beforePrice>dupLine+dbw*0.1){
            beforeBigStatus=0;
        }else if(beforePrice>dupLine-dbw*0.1){
            beforeBigStatus=1;
        }else if(beforePrice>dmidLine+dbw*0.1){
            beforeBigStatus=2;
        }else if(beforePrice>dmidLine){
            beforeBigStatus=3;
        }else if(beforePrice>dmidLine-dbw*0.1){
            beforeBigStatus=4;
        }else if(beforePrice>ddownLine+dbw*0.1){
            beforeBigStatus=5;
        }else if(beforePrice>ddownLine-dbw*0.1){
            beforeBigStatus=6;
        }else{
            beforeBigStatus=7;
        }
        
        if(nowPrice>h1upLine+h1bw*0.1){
            midStatus=0;
        }else if(nowPrice>h1upLine-h1bw*0.1){
            midStatus=1;
        }else if(nowPrice>h1midLine+h1bw*0.1){
            midStatus=2;
        }else if(nowPrice>h1midLine){
            midStatus=3;
        }else if(nowPrice>h1midLine-h1bw*0.1){
            midStatus=4;
        }else if(nowPrice>h1downLine+h1bw*0.1){
            midStatus=5;
        }else if(nowPrice>h1downLine-h1bw*0.1){
            midStatus=6;
        }else{
            midStatus=7;
        }
        
        if(bigStatus-beforeBigStatus>0){ //当前有一个大周期下跌跃迁
            if(midStatus==6||midStatus==7){
                //Log("卖2份 当大",bigStatus,"前大",beforeBigStatus,"中",midStatus);
                //买2份
                mySell(2);
            }else if(midStatus==3||midStatus==4){
                //Log("卖1份 当大",bigStatus,"前大",beforeBigStatus,"中",midStatus);
                //买1份
                mySell(1);
            }else{
                //Log("当大",bigStatus,"前大",beforeBigStatus,"中",midStatus);
            }
        }else if(bigStatus-beforeBigStatus<0){  //当前有一个大周期上涨跃迁
            if(midStatus==6||midStatus==7){
                //Log("买2份 当大",bigStatus,"前大",beforeBigStatus,"中",midStatus);
                //买2份
                myBuy(2);
            }else if(midStatus==3||midStatus==4){
                //Log("买1份 当大",bigStatus,"前大",beforeBigStatus,"中",midStatus);
                //买1份
                myBuy(1);
            }else{
                //Log("当大",bigStatus,"前大",beforeBigStatus,"中",midStatus);
            }
        }else{
            //Log("当大",bigStatus,"前大",beforeBigStatus,"中",midStatus," dup",dupLine," 长度",dboll[0].length);
        }
    }
}

function main() {
    var initAccount = _C(exchange.GetAccount);
    Log(initAccount);
    exchange.SetCurrency("LTC_USDT")
    Log("BTC_USDT的计价币名称:", exchange.GetQuoteCurrency())
  
    while (true) {
        oper();
        Sleep(Interval*1000);
    }
}

More

sssuoswHow is this version of the policy now optimized?

jjkkWhere do you want to set up the major, minor, and major cycles?

hahaworldThe same

a410999923The same

lonelymanIt's unmodified code, right?