mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-25 16:25:16 +00:00
strategy/linregmaker: initial trend
This commit is contained in:
parent
5c60ad0e41
commit
02a67a3de8
|
@ -25,7 +25,6 @@ var two = fixedpoint.NewFromInt(2)
|
||||||
var log = logrus.WithField("strategy", ID)
|
var log = logrus.WithField("strategy", ID)
|
||||||
|
|
||||||
// TODO: Logic for backtest
|
// TODO: Logic for backtest
|
||||||
// TODO: initial trend
|
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
bbgo.RegisterStrategy(ID, &Strategy{})
|
bbgo.RegisterStrategy(ID, &Strategy{})
|
||||||
|
@ -586,6 +585,31 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, se
|
||||||
_ = s.ClosePosition(ctx, fixedpoint.NewFromFloat(1.0))
|
_ = s.ClosePosition(ctx, fixedpoint.NewFromFloat(1.0))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// Initial trend
|
||||||
|
session.UserDataStream.OnStart(func() {
|
||||||
|
var closePrice fixedpoint.Value
|
||||||
|
if !bbgo.IsBackTesting {
|
||||||
|
ticker, err := s.session.Exchange.QueryTicker(ctx, s.Symbol)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
closePrice = ticker.Buy.Add(ticker.Sell).Div(two)
|
||||||
|
} else {
|
||||||
|
if price, ok := session.LastPrice(s.Symbol); ok {
|
||||||
|
closePrice = price
|
||||||
|
}
|
||||||
|
}
|
||||||
|
priceReverseEMA := fixedpoint.NewFromFloat(s.ReverseEMA.Last())
|
||||||
|
|
||||||
|
// Main trend by ReverseEMA
|
||||||
|
if closePrice.Compare(priceReverseEMA) > 0 {
|
||||||
|
s.mainTrendCurrent = types.DirectionUp
|
||||||
|
} else if closePrice.Compare(priceReverseEMA) < 0 {
|
||||||
|
s.mainTrendCurrent = types.DirectionDown
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
// Check trend reversal
|
// Check trend reversal
|
||||||
session.MarketDataStream.OnKLineClosed(types.KLineWith(s.Symbol, s.ReverseInterval, func(kline types.KLine) {
|
session.MarketDataStream.OnKLineClosed(types.KLineWith(s.Symbol, s.ReverseInterval, func(kline types.KLine) {
|
||||||
// closePrice is the close price of current kline
|
// closePrice is the close price of current kline
|
||||||
|
|
Loading…
Reference in New Issue
Block a user