Moving averages crossovers only happen after the trend as already begin to change, so you'll lose most part of the movement. Thats why also they give false signals. The price breaking a slower moving average like 50 or 100 is much more interesting. And still not ideal, you need to combine 2 studies. The ability of backtesting all this ideas with a programme is just so goooood. Studies don't work the same for each instrument, backtesting is ideal and usually alot of work. I might open a polionex account to try this out in the future :)
You are viewing a single comment's thread from:
Nice and easy to test. Minimal change to existing code.
class PriceCrossSMABackTest(BackTest): def addindicators(self, **kwargs): self.ma = kwargs["ma"] self.data["ma"] = self.data["close"].rolling(self.ma).mean() def dostep(self): if self.step > self.ma: prevprice = self.data.ix[self.step-1, "close"] price = self.data.ix[self.step, "close"] prevma = self.data.ix[self.step-1, "ma"] ma = self.data.ix[self.step, "ma"] if price > ma and prevprice < prevma: self.buy(price) elif price < ma and prevprice > prevma: self.sell(price)
Really need to get a GUI going so I can visualise what the strategy is actually doing.
Later bud. :-)
Oh, need to change the call as well.
test = PriceCrossSMABackTest(portfolio.chartdata["ETH"], ma=50)
Geez, do you think in code?
I wish. :-)