gitee.com/quant1x/engine@v1.8.4/factors/feature_box_breaks.go (about) 1 package factors 2 3 import ( 4 "gitee.com/quant1x/engine/cache" 5 "gitee.com/quant1x/engine/datasource/base" 6 "gitee.com/quant1x/engine/utils" 7 "gitee.com/quant1x/exchange" 8 "gitee.com/quant1x/num" 9 "gitee.com/quant1x/pandas" 10 . "gitee.com/quant1x/pandas/formula" 11 ) 12 13 // KLineBox 有效突破(BreaksThrough)平台 14 type KLineBox struct { 15 Code string // 证券代码 16 Date string // 数据日期 17 DoubletPeriod int // box: 倍量周期 18 DoubleHigh float64 // box: 倍量最高 19 DoubleLow float64 // box: 倍量最低 20 Buy bool // box: 买入 21 HalfPeriod int // box: 半量周期 22 HalfHigh float64 // box: 半量最高 23 HalfLow float64 // box: 半量最低 24 Sell bool // box: 卖出 25 TendencyPeriod int // box: 趋势周期 26 QSFZ bool // qsfz: 信号 27 QSCP float64 // qsfz: cp 28 QSCV float64 // qsfz: cv 29 QSVP float64 // qsfz: vp 30 QSVP3 float64 // qsfz: vp3 31 QSVP5 float64 // qsfz: vp5 32 DkCol float64 // dkqs: 能量柱, 通达信分时指标DkCol 33 DkD float64 // dkqs: 多头力量 34 DkK float64 // dkqs: 空头力量 35 DkB bool // dkqs: 买入 36 DkS bool // dkqs: 卖出 37 DxDivergence float64 // madx: 综合发散度评估值 38 DxDm0 float64 // madx: 均线发散度-超短线 39 DxDm1 float64 // madx: 均线发散度-短线 40 DxDm2 float64 // madx: 均线发散度-中线 41 DxB bool // madx: 买入 42 } 43 44 // NewKLineBox 构建有效突破数据 45 func NewKLineBox(code, date string) *KLineBox { 46 securityCode := exchange.CorrectSecurityCode(code) 47 tradeDate := exchange.FixTradeDate(date) 48 klines := base.CheckoutKLines(securityCode, tradeDate) 49 if len(klines) < cache.KLineMin { 50 return nil 51 } 52 //digits := 2 53 //securityInfo, ok := securities.CheckoutSecurityInfo(securityCode) 54 //if ok { 55 // digits = int(securityInfo.DecimalPoint) 56 //} 57 df := pandas.LoadStructs(klines) 58 var ( 59 OPEN = df.ColAsNDArray("open") 60 CLOSE = df.ColAsNDArray("close") 61 VOL = df.ColAsNDArray("volume") 62 HIGH = df.ColAsNDArray("high") 63 LOW = df.ColAsNDArray("low") 64 //AMOUNT = df.ColAsNDArray("amount") 65 ) 66 //{T05: 有效突破平台, V1.0.9 2023-07-22} 67 //{倍量1, 以5日均量线的2倍计算} 68 //ICON_B_RATIO:=0.999; 69 //ICON_S_RATIO:=1.029; 70 //VRATIO:=2.00; 71 VRATIO := 2.00 72 //BL1:=VOL/REF(VOL,1); 73 BL1 := VOL.Div(REF(VOL, 1)) 74 //BOXH:=MAX(OPEN,CLOSE); 75 BOXH := MAX(OPEN, CLOSE) 76 //BOXL:=MIN(OPEN,CLOSE); 77 BOXL := MIN(OPEN, CLOSE) 78 //BLN1:=BARSLAST(BL1>=VRATIO AND CLOSE>OPEN),NODRAW; 79 BLN1 := BARSLAST(BL1.Gte(VRATIO).And(CLOSE.Gt(OPEN))) 80 //倍量周期:BLN1,NODRAW; 81 //{为HHV修复BLN1的值,需要+1} 82 //BLN:=IFF(BLN1>=0,BLN1,BLN1),NODRAW; 83 BLN := BLN1 84 v1 := BLN.IndexOf(-1) 85 doublePeriod := int(num.AnyToInt64(v1)) 86 //BLH:=IFF(BLN=0,BOXH,REF(BOXH,BLN)),DOTLINE; 87 BLH := IFF(BLN.Eq(0), BOXH, REF(BOXH, BLN)) 88 //BLL:=IFF(BLN=0,BOXL,REF(BOXL,BLN)),DOTLINE; 89 BLL := IFF(BLN.Eq(0), BOXL, REF(BOXL, BLN)) 90 //倍量H:IFF(BLN=0,REF(BLH,1),BLH),DOTLINE; 91 dvH := IFF(BLN.Eq(0), REF(BLH, 1), BLH) 92 doubleHigh := utils.SeriesIndexOf(dvH, -1) 93 //倍量L:IFF(BLN=0,REF(BLL,1),BLL),DOTLINE; 94 dvL := IFF(BLN.Eq(0), REF(BLL, 1), BLL) 95 doubleLow := utils.SeriesIndexOf(dvL, -1) 96 //倍量压力:IFF(BLN=0,HIGH,HHV(HIGH,BLN)),DOTLINE; 97 // 98 //MA3:MA(CLOSE,3),COLORYELLOW; 99 MA3 := MA(CLOSE, 3) 100 // 101 //{绘制买入信号} 102 //B:CROSS(CLOSE,倍量H),COLORRED; 103 B := CROSS(CLOSE, dvH) 104 v2 := B.IndexOf(-1) 105 buy := num.AnyToBool(v2) 106 //B1:CLOSE>倍量H AND REF(CLOSE,1)<MA3,COLORRED; 107 //DRAWICON(B,LOW*ICON_B_RATIO,1); 108 // 109 //{绘制卖出信号} 110 //S:CROSS(MA3,CLOSE); 111 S := CROSS(MA3, CLOSE) 112 v3 := S.IndexOf(-1) 113 sell := num.AnyToBool(v3) 114 //DRAWICON(S,HIGH*ICON_S_RATIO,2); 115 //df = df.Join(BLN, dvH, dvL, B, S) 116 //fmt.Println(df) 117 118 // 多空趋势周期 119 //MA5:=MA(CLOSE,5) 120 MA5 := MA(CLOSE, 5) 121 //D:=MA5>REF(MA5,1) AND CLOSE>=MA5; 122 D := MA5.Gt(REF(MA5, 1)).And(CLOSE.Gte(MA5)) 123 //K:=MA5<=REF(MA5,1) OR CLOSE<MA5 124 K := MA5.Lte(REF(MA5, 1)).Or(CLOSE.Lt(MA5)) 125 //FD:=BARSLASTCOUNT(D); 126 FD := BARSLASTCOUNT(D) 127 //FK:=BARSLASTCOUNT(K); 128 FK := BARSLASTCOUNT(K) 129 //多空:IFF(FD>0,FD,-1*FK),NODRAW 130 DK := IFF(FD.Gt(0), FD, FK.Mul(-1)) 131 tendencyPeriod := DK.IndexOf(-1) 132 133 box := KLineBox{ 134 Code: securityCode, 135 Date: tradeDate, 136 DoubletPeriod: doublePeriod, 137 DoubleHigh: doubleHigh, 138 DoubleLow: doubleLow, 139 Buy: buy, 140 Sell: sell, 141 TendencyPeriod: int(num.AnyToInt64(tendencyPeriod)), 142 } 143 // 附加 趋势反转 144 qsfz := computeQuShiFanZhuan(tradeDate, OPEN, CLOSE, HIGH, LOW, VOL) 145 box.QSFZ = qsfz.QSFZ 146 box.QSCP = qsfz.CP 147 box.QSCV = qsfz.CV 148 box.QSVP = qsfz.VP 149 box.QSVP3 = qsfz.VP3 150 box.QSVP5 = qsfz.VP5 151 152 // 附加 多空趋势 153 dkqs := computeDuoKongQuShi(OPEN, CLOSE, HIGH, LOW) 154 box.DkCol = dkqs.Col 155 box.DkD = dkqs.D 156 box.DkK = dkqs.K0 157 box.DkB = dkqs.B 158 box.DkS = dkqs.S 159 // 附加 均线动向 160 madx := computeJuXianDongXiang(OPEN, CLOSE, HIGH, LOW) 161 box.DxDivergence = madx.Diverging 162 box.DxDm0 = madx.Dm0 163 box.DxDm1 = madx.Dm1 164 box.DxDm2 = madx.Dm2 165 box.DxB = madx.B 166 return &box 167 } 168 169 func (k *KLineBox) Kind() cache.Kind { 170 return FeatureBreaksThroughBox 171 } 172 173 func (k *KLineBox) Name() string { 174 return "突破平台" 175 }