mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
rename kline trend to direction
This commit is contained in:
parent
22771288eb
commit
936650d879
|
@ -400,8 +400,8 @@ func (m *SimplePriceMatching) SellToPrice(price fixedpoint.Value) (closedOrders
|
|||
func (m *SimplePriceMatching) processKLine(kline types.KLine) {
|
||||
m.CurrentTime = kline.EndTime
|
||||
|
||||
switch kline.GetTrend() {
|
||||
case types.TrendDown:
|
||||
switch kline.Direction() {
|
||||
case types.DirectionDown:
|
||||
if kline.High > kline.Open {
|
||||
m.BuyToPrice(fixedpoint.NewFromFloat(kline.High))
|
||||
}
|
||||
|
@ -413,7 +413,7 @@ func (m *SimplePriceMatching) processKLine(kline types.KLine) {
|
|||
m.SellToPrice(fixedpoint.NewFromFloat(kline.Close))
|
||||
}
|
||||
|
||||
case types.TrendUp:
|
||||
case types.DirectionUp:
|
||||
if kline.Low < kline.Open {
|
||||
m.SellToPrice(fixedpoint.NewFromFloat(kline.Low))
|
||||
}
|
||||
|
|
|
@ -119,9 +119,9 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, se
|
|||
changePercentage := kline.GetChange() / kline.Open
|
||||
quantity := s.BaseQuantity * (1.0 + math.Abs(changePercentage))
|
||||
|
||||
trend := kline.GetTrend()
|
||||
trend := kline.Direction()
|
||||
switch trend {
|
||||
case types.TrendUp:
|
||||
case types.DirectionUp:
|
||||
// if it goes up and it's above the moving average price, then we sell
|
||||
if 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")
|
||||
}
|
||||
}
|
||||
case types.TrendDown:
|
||||
case types.DirectionDown:
|
||||
// if it goes down and it's below the moving average price, then we buy
|
||||
if closePrice < movingAveragePrice {
|
||||
s.notify(":chart_with_downwards_trend: closePrice %f is below movingAveragePrice %f, submitting BUY order", closePrice, movingAveragePrice)
|
||||
|
|
|
@ -10,15 +10,15 @@ import (
|
|||
"github.com/c9s/bbgo/pkg/util"
|
||||
)
|
||||
|
||||
type Trend int
|
||||
type Direction int
|
||||
|
||||
const TrendUp = 1
|
||||
const TrendFlat = 0
|
||||
const TrendDown = -1
|
||||
const DirectionUp = 1
|
||||
const DirectionNone = 0
|
||||
const DirectionDown = -1
|
||||
|
||||
type KLineOrWindow interface {
|
||||
GetInterval() string
|
||||
GetTrend() int
|
||||
Direction() Direction
|
||||
GetChange() float64
|
||||
GetMaxChange() float64
|
||||
GetThickness() float64
|
||||
|
@ -86,27 +86,27 @@ func (k KLine) Mid() float64 {
|
|||
// green candle with open and close near high price
|
||||
func (k KLine) BounceUp() bool {
|
||||
mid := k.Mid()
|
||||
trend := k.GetTrend()
|
||||
trend := k.Direction()
|
||||
return trend > 0 && k.Open > mid && k.Close > mid
|
||||
}
|
||||
|
||||
// red candle with open and close near low price
|
||||
func (k KLine) BounceDown() bool {
|
||||
mid := k.Mid()
|
||||
trend := k.GetTrend()
|
||||
trend := k.Direction()
|
||||
return trend > 0 && k.Open < mid && k.Close < mid
|
||||
}
|
||||
|
||||
func (k KLine) GetTrend() Trend {
|
||||
func (k KLine) Direction() Direction {
|
||||
o := k.GetOpen()
|
||||
c := k.GetClose()
|
||||
|
||||
if c > o {
|
||||
return TrendUp
|
||||
return DirectionUp
|
||||
} else if c < o {
|
||||
return TrendDown
|
||||
return DirectionDown
|
||||
}
|
||||
return TrendFlat
|
||||
return DirectionNone
|
||||
}
|
||||
|
||||
func (k KLine) GetHigh() float64 {
|
||||
|
@ -175,9 +175,9 @@ func (k KLine) String() string {
|
|||
}
|
||||
|
||||
func (k KLine) Color() string {
|
||||
if k.GetTrend() > 0 {
|
||||
if k.Direction() > 0 {
|
||||
return Green
|
||||
} else if k.GetTrend() < 0 {
|
||||
} else if k.Direction() < 0 {
|
||||
return Red
|
||||
}
|
||||
return "#f0f0f0"
|
||||
|
@ -282,7 +282,7 @@ func (k KLineWindow) GetMaxChange() float64 {
|
|||
|
||||
func (k KLineWindow) AllDrop() bool {
|
||||
for _, n := range k {
|
||||
if n.GetTrend() >= 0 {
|
||||
if n.Direction() >= 0 {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
@ -291,7 +291,7 @@ func (k KLineWindow) AllDrop() bool {
|
|||
|
||||
func (k KLineWindow) AllRise() bool {
|
||||
for _, n := range k {
|
||||
if n.GetTrend() <= 0 {
|
||||
if n.Direction() <= 0 {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user