mirror of
https://github.com/lukewilson2002/autotrader.git
synced 2025-08-02 13:19:32 +00:00
Fixed so many IndexedSeries bugs...
This commit is contained in:
35
cmd/ichimoku.go
Normal file
35
cmd/ichimoku.go
Normal file
@@ -0,0 +1,35 @@
|
||||
//go:build ignore
|
||||
|
||||
package main
|
||||
|
||||
import auto "github.com/fivemoreminix/autotrader"
|
||||
|
||||
type IchimokuStrategy struct {
|
||||
convPeriod, basePeriod, leadingPeriods int
|
||||
}
|
||||
|
||||
func (s *IchimokuStrategy) Init(_ *auto.Trader) {
|
||||
}
|
||||
|
||||
func (s *IchimokuStrategy) Next(t *auto.Trader) {
|
||||
ichimoku := auto.Ichimoku(t.Data().Closes(), s.convPeriod, s.basePeriod, s.leadingPeriods)
|
||||
time := t.Data().Date(-1)
|
||||
// If the price crosses above the Conversion Line, buy.
|
||||
if auto.CrossoverIndex(*time, t.Data().Closes(), ichimoku.Series("Conversion")) {
|
||||
t.Buy(1000)
|
||||
}
|
||||
// If the price crosses below the Conversion Line, sell.
|
||||
if auto.CrossoverIndex(*time, ichimoku.Series("Conversion"), t.Data().Closes()) {
|
||||
t.Sell(1000)
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
auto.Backtest(auto.NewTrader(auto.TraderConfig{
|
||||
Broker: auto.NewTestBroker(nil, nil, 10000, 50, 0.0002, 0),
|
||||
Strategy: &IchimokuStrategy{convPeriod: 9, basePeriod: 26, leadingPeriods: 52},
|
||||
Symbol: "EUR_USD",
|
||||
Frequency: "M15",
|
||||
CandlesToKeep: 2500,
|
||||
}))
|
||||
}
|
Reference in New Issue
Block a user