Display stats on returns

This commit is contained in:
Luke I. Wilson
2023-05-17 12:02:16 -05:00
parent 8fcd7f5cc9
commit ef9659b450
6 changed files with 136 additions and 26 deletions

View File

@@ -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 {