gitee.com/quant1x/engine@v1.8.4/factors/feature_box_dkqs.go (about)

     1  package factors
     2  
     3  import (
     4  	"gitee.com/quant1x/engine/utils"
     5  	"gitee.com/quant1x/pandas"
     6  	. "gitee.com/quant1x/pandas/formula"
     7  )
     8  
     9  // DuoKongQuShi 多空趋势
    10  type DuoKongQuShi struct {
    11  	Col float64 // 多空能量
    12  	K0  float64
    13  	K   float64
    14  	D   float64
    15  	B   bool
    16  	S   bool
    17  }
    18  
    19  // 多空趋势
    20  func computeDuoKongQuShi(OPEN, CLOSE, HIGH, LOW pandas.Series) *DuoKongQuShi {
    21  	//{多空趋势, V1.1.2, 2023-09-13}
    22  	//{量能柱}
    23  	//SCALE:=100;
    24  	SCALE := 100
    25  	//N:=3;
    26  	N := 3
    27  	//NN:=MIN(BARSCOUNT(CLOSE),N);
    28  	//NN := MIN(BARSCOUNT(CLOSE), N)
    29  	NN := N
    30  	//CNN:=REF(CLOSE,NN);
    31  	CNN := REF(CLOSE, NN)
    32  	//CDIFF:=CLOSE-CNN,COLORSTICK;
    33  	CDIFF := CLOSE.Sub(CNN)
    34  	//FF:=CDIFF/CNN;
    35  	FF := CDIFF.Div(CNN)
    36  	//MADK:SCALE*FF,COLORSTICK;
    37  	MADK := FF.Mul(SCALE)
    38  	//
    39  	//{多空趋势}
    40  	//MAXH:=MAX(HIGH,REF(CLOSE,1));
    41  	//MINL:=MIN(LOW,REF(CLOSE,1));
    42  	MINL := MIN(LOW, REF(CLOSE, 1))
    43  	//
    44  	//DIFFK:=IFF(OPEN>=CLOSE,OPEN-CLOSE,OPEN-LOW);
    45  	DIFFK := IFF(OPEN.Gte(CLOSE), OPEN.Sub(CLOSE), OPEN.Sub(LOW))
    46  	//TZ1:=OPEN-REF(CLOSE,1)-DIFFK;
    47  	TZ1 := OPEN.Sub(REF(CLOSE, 1)).Sub(DIFFK)
    48  	//TZ2:=TZ1/OPEN;
    49  	TZ2 := TZ1.Div(OPEN)
    50  	//K0:SCALE*TZ2;
    51  	K0 := TZ2.Mul(SCALE)
    52  	//K:ABS(K0),DOTLINE;
    53  	K := ABS(K0)
    54  	//DIFFD:=IFF(OPEN>=CLOSE,HIGH-OPEN,HIGH-CLOSE);
    55  	DIFFD := IFF(OPEN.Gte(CLOSE), HIGH.Sub(OPEN), HIGH.Sub(CLOSE))
    56  	//TD1:=CLOSE-MINL+DIFFD;
    57  	TD1 := CLOSE.Sub(MINL).Add(DIFFD)
    58  	//TD2:=TD1/CLOSE;
    59  	TD2 := TD1.Div(CLOSE)
    60  	//D:SCALE*TD2;
    61  	D := TD2.Mul(SCALE)
    62  	//B:CROSS(D,K);
    63  	B := CROSS(D, K)
    64  	//S:CROSS(K,D);
    65  	S := CROSS(K, D)
    66  	//DRAWICON(B,20,1);
    67  	//DRAWICON(S,20,2);
    68  	dkqs := DuoKongQuShi{
    69  		Col: utils.SeriesIndexOf(MADK, -1),
    70  		K0:  utils.SeriesIndexOf(K0, -1),
    71  		K:   utils.SeriesIndexOf(K, -1),
    72  		D:   utils.SeriesIndexOf(D, -1),
    73  		B:   utils.BoolIndexOf(B, -1),
    74  		S:   utils.BoolIndexOf(S, -1),
    75  	}
    76  	return &dkqs
    77  }