The Hacklemore strategy is designed for backtesting trading strategies. It involves the following steps:
Populate Indicators: This method calculates various indicators using the input dataframe and metadata. It performs the following actions:
Initializes trade-related data for the current pair.
Checks for active trades and calculates the current profit, peak profit, and current-to-peak profit ratio for the active trade.
Checks for other open trades and calculates the average profit for those trades.
Populates additional indicators like volume mean, RMI (Relative Momentum Index), SAR (Stop and Reverse), MACD (Moving Average Convergence Divergence), rolling maximum and minimum values, upper and lower bands of Bollinger Bands, and breakout levels. Populate Buy Trend: This method determines the conditions for entering a buy trade based on the indicators and trade data. It checks the following conditions:
If there is an active trade, the current-to-peak profit ratio should be greater than 0.8 and the RMI-slow value should be greater than or equal to 60. If there is no active trade, it checks various conditions like up trend, RMI-slow value, MACD histogram, breakout level, volume, moving averages, SAR, and price patterns. It also considers the average profit of other trades if they exist. Populate Sell Trend: This method determines the conditions for exiting a buy trade based on the indicators and trade data. It checks the following conditions:
If there is an active trade, the current profit should be negative but greater than the stop loss value, the dn_trend should be 1, the RMI-fast value should be less than 50, and there should be positive volume. If there are other trades, it checks the average profit condition. If there is no active trade, it checks for negative volume. The strategy also includes some custom methods for ordering, price protection, and timeouts. These methods interact with the order book and current price to determine whether to execute or cancel an order. Please note that this description provides a high-level overview of the strategy's functionality.