Browse Source

Alpaca: qqq06f

- LONG: prevent LONG positions if current price is under DEMA(8)
- decrease order size down to .3 if its after 4pm
Alexey Kim 1 month ago
parent
commit
16e2a34f77
1 changed files with 20 additions and 2 deletions
  1. 20 2
      strategy/alpaca/qqq06f/strategy.go

+ 20 - 2
strategy/alpaca/qqq06f/strategy.go

@@ -92,16 +92,34 @@ func (s alpacaQQQ) Handle(market sentio.Market, proba float64) ([]sentio.Strateg
 		}
 
 		if sentio.LONG == side && proba > 1.00109 {
+			var (
+				dema []float64
+				lb   *sentio.Bar
+			)
+
 			if ok && position != nil && position.GetCurrentPrice() > position.GetAvgPrice() {
 				continue
 			}
 
+			if dema = market.SMA(s.PositionSymbols()[sentio.LONG], 15, 8, 1); dema == nil || len(dema) < 1 {
+				continue
+			}
+
+			if lb, err = market.LatestBar(s.PositionSymbols()[sentio.LONG]); err != nil {
+				continue
+			}
+
+			// prevent SHORTing if current price is under DEMA(8)
+			if lb.Close/dema[0] < .999 {
+				continue
+			}
+
 			orders = append(orders, sentio.StrategyOrder{
 				Symbol: symbol,
 				Action: sentio.OrderBuy,
 				Ratio: func() float64 {
 					if t.Hour() >= 16 {
-						return .1
+						return .3
 					}
 
 					if ok {
@@ -143,7 +161,7 @@ func (s alpacaQQQ) Handle(market sentio.Market, proba float64) ([]sentio.Strateg
 				Action: sentio.OrderBuy,
 				Ratio: func() float64 {
 					if t.Hour() >= 16 {
-						return .1
+						return .3
 					}
 
 					if ok {