mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
pull out trend types
This commit is contained in:
parent
a7325e86f0
commit
b0cc128b79
|
@ -121,7 +121,7 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, se
|
||||||
|
|
||||||
trend := kline.GetTrend()
|
trend := kline.GetTrend()
|
||||||
switch trend {
|
switch trend {
|
||||||
case 1:
|
case types.TrendUp:
|
||||||
// if it goes up and it's above the moving average price, then we sell
|
// if it goes up and it's above the moving average price, then we sell
|
||||||
if closePrice > movingAveragePrice {
|
if closePrice > movingAveragePrice {
|
||||||
s.notify(":chart_with_upwards_trend: closePrice %f is above movingAveragePrice %f, submitting SELL order", closePrice, movingAveragePrice)
|
s.notify(":chart_with_upwards_trend: closePrice %f is above movingAveragePrice %f, submitting SELL order", closePrice, movingAveragePrice)
|
||||||
|
@ -137,7 +137,7 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, se
|
||||||
log.WithError(err).Error("submit order error")
|
log.WithError(err).Error("submit order error")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case -1:
|
case types.TrendDown:
|
||||||
// if it goes down and it's below the moving average price, then we buy
|
// if it goes down and it's below the moving average price, then we buy
|
||||||
if closePrice < movingAveragePrice {
|
if closePrice < movingAveragePrice {
|
||||||
s.notify(":chart_with_downwards_trend: closePrice %f is below movingAveragePrice %f, submitting BUY order", closePrice, movingAveragePrice)
|
s.notify(":chart_with_downwards_trend: closePrice %f is below movingAveragePrice %f, submitting BUY order", closePrice, movingAveragePrice)
|
||||||
|
|
|
@ -10,6 +10,12 @@ import (
|
||||||
"github.com/c9s/bbgo/pkg/util"
|
"github.com/c9s/bbgo/pkg/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type Trend int
|
||||||
|
|
||||||
|
const TrendUp = 1
|
||||||
|
const TrendFlat = 0
|
||||||
|
const TrendDown = -1
|
||||||
|
|
||||||
type KLineOrWindow interface {
|
type KLineOrWindow interface {
|
||||||
GetInterval() string
|
GetInterval() string
|
||||||
GetTrend() int
|
GetTrend() int
|
||||||
|
@ -87,16 +93,16 @@ func (k KLine) BounceDown() bool {
|
||||||
return trend > 0 && k.Open < mid && k.Close < mid
|
return trend > 0 && k.Open < mid && k.Close < mid
|
||||||
}
|
}
|
||||||
|
|
||||||
func (k KLine) GetTrend() int {
|
func (k KLine) GetTrend() Trend {
|
||||||
o := k.GetOpen()
|
o := k.GetOpen()
|
||||||
c := k.GetClose()
|
c := k.GetClose()
|
||||||
|
|
||||||
if c > o {
|
if c > o {
|
||||||
return 1
|
return TrendUp
|
||||||
} else if c < o {
|
} else if c < o {
|
||||||
return -1
|
return TrendDown
|
||||||
}
|
}
|
||||||
return 0
|
return TrendFlat
|
||||||
}
|
}
|
||||||
|
|
||||||
func (k KLine) GetHigh() float64 {
|
func (k KLine) GetHigh() float64 {
|
||||||
|
@ -442,4 +448,3 @@ func (k KLineWindow) SlackAttachment() slack.Attachment {
|
||||||
}
|
}
|
||||||
|
|
||||||
type KLineCallback func(kline KLine)
|
type KLineCallback func(kline KLine)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user