mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
Merge pull request #784 from c9s/strategy/pivotshort
strategy: pivotshort: fix stopEMA
This commit is contained in:
commit
ccfaf0e070
|
@ -14,7 +14,7 @@ type ExitMethod struct {
|
|||
CumulatedVolumeTakeProfit *CumulatedVolumeTakeProfit `json:"cumulatedVolumeTakeProfit"`
|
||||
}
|
||||
|
||||
func (m *ExitMethod) Subscribe() {
|
||||
func (m *ExitMethod) Subscribe(session *ExchangeSession) {
|
||||
// TODO: pull out this implementation as a simple function to reflect.go
|
||||
rv := reflect.ValueOf(m)
|
||||
rt := reflect.TypeOf(m)
|
||||
|
@ -22,11 +22,13 @@ func (m *ExitMethod) Subscribe() {
|
|||
rv = rv.Elem()
|
||||
rt = rt.Elem()
|
||||
infType := reflect.TypeOf((*types.Subscriber)(nil)).Elem()
|
||||
|
||||
argValues := toReflectValues(session)
|
||||
for i := 0; i < rt.NumField(); i++ {
|
||||
fieldType := rt.Field(i)
|
||||
if fieldType.Type.Implements(infType) {
|
||||
method := rv.Field(i).MethodByName("Subscribe")
|
||||
method.Call(nil)
|
||||
method.Call(argValues)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,5 +4,5 @@ import "testing"
|
|||
|
||||
func TestExitMethod(t *testing.T) {
|
||||
em := &ExitMethod{}
|
||||
em.Subscribe()
|
||||
em.Subscribe(&ExchangeSession{})
|
||||
}
|
||||
|
|
|
@ -125,7 +125,6 @@ func (e *GeneralOrderExecutor) ClosePosition(ctx context.Context, percentage fix
|
|||
}
|
||||
|
||||
submitOrder.Tag = strings.Join(tags, ",")
|
||||
|
||||
_, err := e.SubmitOrders(ctx, *submitOrder)
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -110,3 +110,11 @@ func newTypeValueInterface(typ reflect.Type) interface{} {
|
|||
dst := reflect.New(typ)
|
||||
return dst.Interface()
|
||||
}
|
||||
|
||||
func toReflectValues(args ...interface{}) (values []reflect.Value) {
|
||||
for _, arg := range args {
|
||||
values = append(values, reflect.ValueOf(arg))
|
||||
}
|
||||
|
||||
return values
|
||||
}
|
||||
|
|
|
@ -174,7 +174,6 @@ func (s *Strategy) CurrentPosition() *types.Position {
|
|||
}
|
||||
|
||||
func (s *Strategy) ClosePosition(ctx context.Context, percentage fixedpoint.Value) error {
|
||||
bbgo.Notify("Closing position", s.Position)
|
||||
return s.orderExecutor.ClosePosition(ctx, percentage)
|
||||
}
|
||||
|
||||
|
@ -338,7 +337,7 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, se
|
|||
log.Infof("%s breakLow signal detected, closed price %f < breakPrice %f", kline.Symbol, closePrice.Float64(), breakPrice.Float64())
|
||||
|
||||
// stop EMA protection
|
||||
if s.stopEWMA != nil && !s.BreakLow.StopEMARange.IsZero() {
|
||||
if s.stopEWMA != nil {
|
||||
ema := fixedpoint.NewFromFloat(s.stopEWMA.Last())
|
||||
if ema.IsZero() {
|
||||
return
|
||||
|
|
|
@ -45,7 +45,7 @@ func (s *TradeStats) Add(pnl fixedpoint.Value) {
|
|||
s.WinningRatio = fixedpoint.NewFromFloat(float64(s.NumOfProfitTrade) / float64(s.NumOfLossTrade))
|
||||
}
|
||||
|
||||
s.ProfitFactor = s.GrossProfit.Div(s.GrossLoss)
|
||||
s.ProfitFactor = s.GrossProfit.Div(s.GrossLoss.Abs())
|
||||
}
|
||||
|
||||
func (s *TradeStats) String() string {
|
||||
|
|
Loading…
Reference in New Issue
Block a user