| 
					
				 | 
			
			
				@@ -1,7 +1,9 @@ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 package main 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import ( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	"fmt" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	"git.beejay.kim/Gshopper/sentio" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	"git.beejay.kim/Gshopper/sentio/indicator" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	"time" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 ) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -72,6 +74,36 @@ func (s alpacaQQQ) Handle(market sentio.Market, ts time.Time, proba float64) ([] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 			ok = false 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		if ok { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			var ( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				sl   []float64 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				bars []sentio.Bar 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			if bars, err = market.HistoricalBars(symbol, time.Minute, nil); err == nil && len(bars) > 0 { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				h := make([]float64, len(bars)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				l := make([]float64, len(bars)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				c := make([]float64, len(bars)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				for i := range bars { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					h[i] = bars[i].High 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					l[i] = bars[i].Low 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					c[i] = bars[i].Close 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				sl = indicator.AtrTrailingStopLoss(h, l, c, ATR_PERIOD, ATR_MULTIPLIER, ATR_HHV) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				fmt.Printf("ATR Trailing StopLoss: [%f]\n", sl[len(sl)-1]) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				if position.GetCurrentPrice() < sl[len(sl)-1] { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					return []sentio.StrategyOrder{{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+						Symbol: symbol, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+						Action: sentio.OrderSell, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+						Ratio:  1, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					}}, nil 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		// Close positions before market closed 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		if ok && now.Hour() == 15 && now.Minute() > 55 { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 			return []sentio.StrategyOrder{{ 
			 |