The resource loading... loading...

Statistical K-line retrospective on whether there is a trend

Author: The grass, Date: 2014-10-24 21:00:21
Tags: Trend

This strategy is mainly to investigate from the retest data whether it is possible to predict the next fall based on the previous fall. Specifically, if in the 5 K line, there are 4 or 5 increases, then whether the next one is more uptrending, the strategy will statistically determine the frequency of the rise. Of course, the parameters of the strategy have also been changed to statistically determine other increases or decreases.


function adjustFloat(v) {

    return Math.floor(v*1000)/1000;
}
function main(){
    var arr=[0,0,0,0,0,0];//总共考察六根K线,用前五个的结果去预测第六个,可以自由选择
    var appear=0;         //模式的出现次数
    var fit=0;            //第六根K线的结果符合预期
    var diff=0;           //预定模式出现后,第六根的收盘价和开盘价之差。
    while(true){
    var records=exchange.GetRecords();
    i=records.length-1;
    if(i>1&&(records[i].Close-records[i].Open>0)){
        arr.push(1);
        arr.shift();      //把最近一个K线的插入数组末尾,删去元素一以保持长度不变。上涨插入1,否则插入0
    }
    if(i>1&&!(records[i].Close-records[i].Open>0)){
        arr.push(0);
        arr.shift();
    }
    if(i>5){
        var count=0;
        for(k=0;k<5;k++){
            if(arr[k]<1){
                count++;   //前5根K线上涨的个数
            }
        }
        if(count<2){       //设定需要多少个上涨K线,在这里要求四个或五个。
            appear++;      //所需模式出现一次
            diff+=(records[i].Close-records[i].Open);//统计第六根,也是最近一根的差价和
            if(arr[5]<1){  //这里所期望的结果是上涨,也可以写成其它的
                fit++;     //期待结果出现一次
                Log("出现模式次数",appear,"符合预计次数",fit,"所占比例",adjustFloat(fit/appear),"差价之和",adjustFloat(diff));
                LogProfit(adjustFloat(fit/appear));   //把比例输出为收益曲线
            }
        }
    }
    Sleep(300000);       //间隔时间,应与所选K线周期相同?这里是5分钟
    }
}

Related

More

Selling outHow many QQs do you have, add up, exchange! My QQ is 472725682

Selling outI'm not sure if you can share this with me.

The grass QQ1051804485

The grassThis is not a strategy, just a boring test of the market's fluctuating laws, it doesn't make much sense.