Files
banstagy/trend/maMulti.go
2026-08-24 20:53:21 +08:00

56 lines
1.5 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package trend
import (
"github.com/banbox/banbot/config"
"github.com/banbox/banbot/core"
"github.com/banbox/banbot/strat"
ta "github.com/banbox/banta"
)
/*
视频号:六叔大师兄:散户用一个战法,当天100%不亏 2025/01/25
5日上穿10日买入;5日上穿20日加仓;
5日向下减仓,5日下穿10日平仓;
反之做空亦然;
去掉5日向下减仓,更好一点。
5,10,20适合8h;目前10,20,40适合4h
固定50品种在23年持平
滚动50品种在23年小亏
*/
func MaMulti(p *config.RunPolicyConfig) *strat.TradeStrat {
return &strat.TradeStrat{
WarmupNum: 100,
OnBar: func(s *strat.StratJob) {
e := s.Env
ma5 := ta.SMA(e.Close, 10)
ma10 := ta.SMA(e.Close, 20)
ma20 := ta.SMA(e.Close, 40)
ma5X10 := ma5.Cross(ma10)
ma5x20 := ma5.Cross(ma20)
if len(s.LongOrders) == 1 && ma5x20 == 1 {
s.OpenOrder(&strat.EnterReq{Tag: "l2", CostRate: 0.5})
}
if len(s.LongOrders) > 0 {
if ma5X10 == -1 {
s.CloseOrders(&strat.ExitReq{Tag: "exit", Dirt: core.OdDirtLong})
}
} else if ma5X10 == 1 {
s.OpenOrder(&strat.EnterReq{Tag: "l1", CostRate: 0.5})
}
if len(s.ShortOrders) == 1 && ma5x20 == -1 {
s.OpenOrder(&strat.EnterReq{Tag: "s2", Short: true, CostRate: 0.5})
}
if len(s.ShortOrders) > 0 {
if ma5X10 == 1 {
s.CloseOrders(&strat.ExitReq{Tag: "exitS", Dirt: core.OdDirtShort})
}
} else if ma5X10 == -1 {
s.OpenOrder(&strat.EnterReq{Tag: "s1", Short: true, CostRate: 0.5})
}
},
}
}