mirror of
https://github.com/lukewilson2002/autotrader.git
synced 2025-08-02 05:09:33 +00:00
Display stats on returns
This commit is contained in:
@@ -15,18 +15,13 @@ func (s *SMAStrategy) Next(t *auto.Trader) {
|
||||
sma1 := t.Data().Closes().Rolling(s.period1).Mean()
|
||||
sma2 := t.Data().Closes().Rolling(s.period2).Mean()
|
||||
// If the shorter SMA crosses above the longer SMA, buy.
|
||||
if crossover(sma1, sma2) {
|
||||
if auto.Crossover(sma1, sma2) {
|
||||
t.Buy(1000)
|
||||
} else if crossover(sma2, sma1) {
|
||||
} else if auto.Crossover(sma2, sma1) {
|
||||
t.Sell(1000)
|
||||
}
|
||||
}
|
||||
|
||||
// crossover returns true if s1 crosses above s2 at the latest float.
|
||||
func crossover(s1, s2 auto.Series) bool {
|
||||
return s1.Float(-1) > s2.Float(-1) && s1.Float(-2) <= s2.Float(-2)
|
||||
}
|
||||
|
||||
func main() {
|
||||
data, err := auto.EURUSD()
|
||||
if err != nil {
|
||||
|
Reference in New Issue
Block a user