2
0
Quellcode durchsuchen

QQQ15

- impl Cooldown
- Handle: prevent BUYs for delayed probas
- Handle: prevent extra BUYs with similar avg price
Alexey Kim vor 2 Wochen
Ursprung
Commit
3209169aa5
1 geänderte Dateien mit 11 neuen und 5 gelöschten Zeilen
  1. 11 5
      strategy/alpaca/qqq15/strategy.go

+ 11 - 5
strategy/alpaca/qqq15/strategy.go

@@ -33,11 +33,11 @@ func (s alpacaQQQ) Interval() uint8 {
 	return 5
 }
 
-func (s alpacaQQQ) Cooldown() time.Duration {
-	return time.Minute * time.Duration(s.Interval()*6)
+func (s alpacaQQQ) Cooldown(periods uint8) time.Duration {
+	return time.Minute * time.Duration(s.Interval()*periods)
 }
 
-func (s alpacaQQQ) Handle(market sentio.Market, proba float64) ([]sentio.StrategyOrder, error) {
+func (s alpacaQQQ) Handle(market sentio.Market, ts time.Time, proba float64) ([]sentio.StrategyOrder, error) {
 	var (
 		portfolio sentio.Portfolio
 		orders    []sentio.StrategyOrder
@@ -105,6 +105,12 @@ func (s alpacaQQQ) Handle(market sentio.Market, proba float64) ([]sentio.Strateg
 			}}, nil
 		}
 
+		// Prevent BUYs for delayed probas
+		if ts.Add(time.Minute * time.Duration(int64(s.Interval()/2))).Before(now) {
+			continue
+		}
+
+		// Prevent BUYs on closing market
 		if now.Hour() == 15 && now.Minute() > 35 {
 			continue
 		}
@@ -112,7 +118,7 @@ func (s alpacaQQQ) Handle(market sentio.Market, proba float64) ([]sentio.Strateg
 		if sentio.LONG == side && proba > 1 {
 			size := float64(0)
 
-			if ok && position.GetAvgPrice() > position.GetCurrentPrice() {
+			if ok && position.GetAvgPrice()/position.GetCurrentPrice() > 1.002 {
 				// extra position with cheaper price
 				size = .4
 			} else if !ok && proba > 1.00065 {
@@ -134,7 +140,7 @@ func (s alpacaQQQ) Handle(market sentio.Market, proba float64) ([]sentio.Strateg
 		if sentio.SHORT == side && proba < 1 {
 			size := float64(0)
 
-			if ok && position.GetAvgPrice() > position.GetCurrentPrice() {
+			if ok && position.GetAvgPrice()/position.GetCurrentPrice() > 1.002 {
 				// extra position with cheaper price
 				size = .4
 			} else if !ok && proba < .9992 {