This commit is contained in:
2026-08-24 20:53:21 +08:00
commit 6e78bba16a
287 changed files with 32443 additions and 0 deletions

64
org/fmz/BearMACD.go Normal file
View File

@@ -0,0 +1,64 @@
package fmz
import (
"github.com/banbox/banbot/config"
"github.com/banbox/banbot/core"
"github.com/banbox/banbot/strat"
"github.com/banbox/banstagy/com"
ta "github.com/banbox/banta"
"math"
)
/*
https://www.fmz.com/strategy/426836
该策略专注于熊市下跌行情中的做空交易,同时确保资产处于大周期下行通道中,然后在进一步下跌后止盈退出。
测试在48个品种,210101-250101, 1h,收益296%,回撤17%,夏普7.42
空头优化620轮,取25%位置,maS: 7 maSLen: 191 rate: 2.35
多头优化182轮,取22%位置,maL: 1 maLLen: 219 rate: 2.33
后续优化方向:
止损止盈的倍率,开单倍率
*/
func BearMACD(p *config.RunPolicyConfig) *strat.TradeStrat {
// short: 7 191 2.35
// long: 1 219 2.33
maSType := com.DefMaType(p, "maS", com.MaALMA)
maSLen := int(p.Def("maSLen", 191, core.PNormF(30, 800, 230, 0)))
maLType := com.DefMaType(p, "maL", com.MaEMA)
maLLen := int(p.Def("maLLen", 219, core.PNormF(30, 800, 230, 0)))
rate := p.Def("rate", 2.35, core.PNormF(0.5, 3, 1.6, 0))
mc1 := int(math.Round(12 * rate))
mc2 := int(math.Round(26 * rate))
mc3 := int(math.Round(9 * rate))
return &strat.TradeStrat{
WarmupNum: max(maSLen, maLLen),
OnBar: func(s *strat.StratJob) {
e := s.Env
c := e.Close.Get(0)
maS := com.GetMA(e.Close, e.Volume, maSType, maSLen).Get(0)
maL := com.GetMA(e.Close, e.Volume, maLType, maLLen).Get(0)
macd, signal := ta.MACD(e.Close, mc1, mc2, mc3)
macdX := macd.Cross(signal)
atr := ta.ATR(e.High, e.Low, e.Close, 14).Get(0)
if s.OrderNum > 0 {
return
}
if macdX == -1 && c < maS {
s.OpenOrder(&strat.EnterReq{
Tag: "short",
Short: true,
StopLossVal: atr * 1.3,
TakeProfitVal: atr * 4,
})
} else if macdX == 1 && c > maL {
s.OpenOrder(&strat.EnterReq{
Tag: "long",
StopLossVal: atr * 1.3,
TakeProfitVal: atr * 6,
})
}
},
}
}

91
org/fmz/ComboMaBear.go Normal file
View File

@@ -0,0 +1,91 @@
package fmz
import (
"github.com/banbox/banbot/config"
"github.com/banbox/banbot/strat"
ta "github.com/banbox/banta"
"math"
"strconv"
)
/*
https://www.fmz.com/strategy/429466
本策略结合了均线先行指标和熊强力指标,形成短期看跌方向信号的组合策略。均线先行指标判断趋势,熊强力指标确定做空时机。策略适合短线操作,追踪市场调整行情。
在48个品种,210101-241101上,表现很差
4h,1h,15m均震荡严重
*/
type CMA struct {
maPos float64
bpPos float64
}
func ComboMaBear(p *config.RunPolicyConfig) *strat.TradeStrat {
bpShort := 4.0
bpLong := 0.3
return &strat.TradeStrat{
WarmupNum: 50,
OnStartUp: func(s *strat.StratJob) {
s.More = &CMA{}
},
OnBar: func(s *strat.StratJob) {
e := s.Env
o, h, l, c, c1 := e.Open.Get(0), e.High.Get(0), e.Low.Get(0), e.Close.Get(0), e.Close.Get(1)
m, _ := s.More.(*CMA)
ma := ta.EMA(e.Close, 14).Get(0)
atr := ta.ATR(e.High, e.Low, e.Close, 14).Get(0)
hh := max(e.High.Get(0), e.High.Get(1))
ll := min(e.Low.Get(0), e.Low.Get(1))
nXS := hh
if ll > ma || hh < ma {
nXS = ll
}
xsDiff := nXS - c1
if xsDiff < 0 {
m.maPos = 1
} else if xsDiff > 0 {
m.maPos = -1
}
var bp float64
solRate := math.Abs(c-o) / (h - l)
var isBear bool
if solRate < 0.1 {
// 实体不足10%,看上下影线
isBear = h-c > c-l
} else {
// 实体较大,直接判断
isBear = c < o
}
if isBear {
// 阴线取全部
bp = h - l
} else {
// 阳线取较大影线
bp = max(h-c, c-l)
}
bpRate := bp / atr
if bpRate > bpShort {
m.bpPos = -1
} else if bpRate < bpLong {
m.bpPos = 1
}
openDirt := 0
if m.maPos == 1 && m.bpPos == 1 {
openDirt = 1
} else if m.maPos == -1 && m.bpPos == -1 {
openDirt = -1
} else if s.OrderNum > 0 {
s.CloseOrders(&strat.ExitReq{Tag: "exit"})
}
if openDirt != 0 && s.OrderNum == 0 {
s.OpenOrder(&strat.EnterReq{
Tag: strconv.Itoa(openDirt),
Short: openDirt < 0,
})
}
},
}
}

10
org/fmz/common.go Normal file
View File

@@ -0,0 +1,10 @@
package fmz
import "github.com/banbox/banbot/strat"
func init() {
strat.AddStratGroup("fmz", map[string]strat.FuncMakeStrat{
"ComboMaBear": ComboMaBear,
"BearMACD": BearMACD,
})
}