Trend-following strategy – implementation
Since we’re going to use the backtesting code that we developed in the previous chapter (see the Backtesting platform with historical data feed section in Chapter 11, Backtesting and Theoretical Performance), we need to add only small pieces of code that support the required objects.
Note
Don’t forget to change the data source to the file with the daily AUDUSD data that we’ve just created!
Let’s start with adding the slidingWindow
class to implement moving averages. Obviously, we copy it from the code in the preceding section. The code (as usual with class declaration) goes somewhere after the imports and before the declaration of the first function:
class slidingWindow: def __init__(self, len): self.data = [0 for i in range(len)] def add(self, element): ...