@@ -50,6 +50,10 @@ func Sum(obj *Series, period int) *Series {
5050 if sta == nil {
5151 sta = & sumState {}
5252 res .More = sta
53+ res .DupMore = func (more interface {}) interface {} {
54+ sta := more .(* sumState )
55+ return & sumState {sta .sumVal , append ([]float64 {}, sta .arr ... )}
56+ }
5357 }
5458 curVal := obj .Get (0 )
5559 if ! math .IsNaN (curVal ) {
@@ -104,6 +108,10 @@ func VWMA(price *Series, vol *Series, period int) *Series {
104108 if more == nil {
105109 more = & moreVWMA {}
106110 res .More = more
111+ res .DupMore = func (mAny interface {}) interface {} {
112+ m := mAny .(* moreVWMA )
113+ return & moreVWMA {m .sumCost , m .sumWei , append ([]float64 {}, m .costs ... ), append ([]float64 {}, m .volumes ... )}
114+ }
107115 }
108116 if math .IsNaN (cost ) {
109117 return res .Append (math .NaN ())
@@ -254,6 +262,10 @@ func WMA(obj *Series, period int) *Series {
254262 if more == nil {
255263 more = & wmaSta {}
256264 res .More = more
265+ res .DupMore = func (mAny interface {}) interface {} {
266+ m := mAny .(* wmaSta )
267+ return & wmaSta {append ([]float64 {}, m .arr ... ), m .allSum , m .weiSum }
268+ }
257269 }
258270 more .arr = append (more .arr , val )
259271 if len (more .arr ) > period {
@@ -362,6 +374,9 @@ func rsiBy(obj *Series, period int, subVal float64) *Series {
362374 // 状态: [0:prevVal, 1:avgGain, 2:avgLoss, 3:validCount]
363375 more = []float64 {math .NaN (), 0 , 0 , 0 }
364376 res .More = more
377+ res .DupMore = func (more interface {}) interface {} {
378+ return append ([]float64 {}, more .([]float64 )... )
379+ }
365380 }
366381
367382 prevVal := more [0 ]
@@ -742,6 +757,9 @@ func WrapFloatArr(res *Series, period int, inVal float64) []float64 {
742757 var more []float64
743758 if res .More == nil {
744759 more = make ([]float64 , 0 , period )
760+ res .DupMore = func (more interface {}) interface {} {
761+ return append ([]float64 {}, more .([]float64 )... )
762+ }
745763 } else {
746764 more = res .More .([]float64 )
747765 }
@@ -946,6 +964,10 @@ func pluMinDMBy(high *Series, low *Series, close *Series, period, method int) (*
946964 if state == nil {
947965 state = & dmState {}
948966 res .More = state
967+ res .DupMore = func (more interface {}) interface {} {
968+ m := more .(* dmState )
969+ return & dmState {m .Num , m .DmPosMA , m .DmNegMA , m .TRMA }
970+ }
949971 }
950972 if math .IsNaN (tr ) {
951973 res .Append ([]float64 {math .NaN (), math .NaN ()})
@@ -987,7 +1009,12 @@ func ROC(obj *Series, period int) *Series {
9871009 if res .Cached () {
9881010 return res
9891011 }
990- prevs , _ := res .More .([]float64 )
1012+ prevs , ok := res .More .([]float64 )
1013+ if ! ok {
1014+ res .DupMore = func (more interface {}) interface {} {
1015+ return append ([]float64 {}, more .([]float64 )... )
1016+ }
1017+ }
9911018 curVal := obj .Get (0 )
9921019 if math .IsNaN (curVal ) {
9931020 return res .Append (math .NaN ())
@@ -1063,6 +1090,10 @@ func ER(obj *Series, period int) *Series {
10631090 prevIn : math .NaN (),
10641091 }
10651092 res .More = sta
1093+ res .DupMore = func (more interface {}) interface {} {
1094+ m := more .(* tnrState )
1095+ return & tnrState {append ([]float64 {}, m .arr ... ), m .sumVal , m .prevIn , append ([]float64 {}, m .arrIn ... )}
1096+ }
10661097 }
10671098 inVal := obj .Get (0 )
10681099 curVal := math .Abs (inVal - sta .prevIn )
@@ -1187,6 +1218,10 @@ func CMF(env *BarEnv, period int) *Series {
11871218 if sta == nil {
11881219 sta = & cmfState {}
11891220 res .More = sta
1221+ res .DupMore = func (more interface {}) interface {} {
1222+ m := more .(* cmfState )
1223+ return & cmfState {append ([]float64 {}, m .mfSum ... ), append ([]float64 {}, m .volSum ... ), m .sumMfVal , m .sumVol }
1224+ }
11901225 }
11911226
11921227 var resVal = math .NaN ()
@@ -1358,6 +1393,10 @@ func MFI(e *BarEnv, period int) *Series {
13581393 if sta == nil {
13591394 sta = & mfiState {sumNeg : math .NaN (), sumPos : math .NaN (), prev : math .NaN ()}
13601395 res .More = sta
1396+ res .DupMore = func (more interface {}) interface {} {
1397+ m := more .(* mfiState )
1398+ return & mfiState {append ([]float64 {}, m .posArr ... ), append ([]float64 {}, m .negArr ... ), m .sumPos , m .sumNeg , m .prev }
1399+ }
13611400 }
13621401 avgPrice := AvgPrice (e )
13631402 price0 := avgPrice .Get (0 )
@@ -1569,6 +1608,10 @@ func CMOBy(obj *Series, period int, maType int) *Series {
15691608 prevIn : math .NaN (),
15701609 }
15711610 res .More = sta
1611+ res .DupMore = func (more interface {}) interface {} {
1612+ m := more .(* cmdSta )
1613+ return & cmdSta {append ([]float64 {}, m .subs ... ), m .sumPos , m .sumNeg , m .prevIn }
1614+ }
15721615 }
15731616 inVal := obj .Get (0 )
15741617 val := inVal - sta .prevIn
@@ -1736,6 +1779,10 @@ func DV2(h, l, c *Series, period, maLen int) *Series {
17361779 if sta == nil {
17371780 sta = & dv2Sta {}
17381781 res .More = sta
1782+ res .DupMore = func (more interface {}) interface {} {
1783+ m := more .(* dv2Sta )
1784+ return & dv2Sta {append ([]float64 {}, m .chl ... ), append ([]float64 {}, m .dv ... )}
1785+ }
17391786 }
17401787 h0 , l0 , c0 := h .Get (0 ), l .Get (0 ), c .Get (0 )
17411788 // 如果当前输入值为 NaN,返回 NaN然后跳过,不重置状态
@@ -1889,6 +1936,10 @@ func STC(obj *Series, period, fast, slow int, alpha float64) *Series {
18891936 prevSTC : math .NaN (),
18901937 }
18911938 res .More = s
1939+ res .DupMore = func (more interface {}) interface {} {
1940+ m := more .(* stcSta )
1941+ return & stcSta {append ([]float64 {}, m .macdHis ... ), append ([]float64 {}, m .dddHis ... ), m .prevDDD , m .prevSTC }
1942+ }
18921943 }
18931944 // 1. 计算MACD差值
18941945 fastEMA := EMA (obj , fast ).Get (0 )
0 commit comments