The strategy implemented in this code is called "CombinedBinHAndCluc." It combines elements from two different trading strategies, namely "BinHV45" and "ClucMay72018," to generate buy and sell signals for backtesting. Here's a breakdown of what the strategy does:
It uses Bollinger Bands to identify potential buy signals. It calculates the Bollinger Bands for the 'close' price using a window size of 40 and 2 standard deviations.
It computes the lower band and the difference between the middle band and the lower band.
It calculates the absolute difference between consecutive closing prices and the absolute difference between the closing price and the low price.
These indicators are stored in the dataframe. It applies the ClucMay72018 strategy to identify additional buy signals. It calculates the Bollinger Bands for the typical price using a window size of 20 and 2 standard deviations. It computes the exponential moving average (EMA) with a time period of 50. It calculates the mean volume over a rolling window of 30 periods. These indicators are stored in the dataframe. It generates buy signals based on specific conditions. For the BinHV45 strategy:
The lower band from the Bollinger Bands must be positive (shifted one period). The difference between the middle band and the lower band must be greater than 0.008 times the closing price. The absolute difference between consecutive closing prices must be greater than 0.0175 times the closing price. The absolute difference between the closing price and the low price must be less than 0.25 times the difference between the middle band and the lower band. The closing price must be less than the shifted lower band. The closing price must be less than or equal to the previous closing price. For the ClucMay72018 strategy:
The closing price must be below the EMA. The closing price must be below 0.985 times the lower band from the Bollinger Bands. The volume must be below 20 times the previous mean volume. It generates sell signals based on a condition. If the closing price is above the middle band from the Bollinger Bands, a sell signal is generated. The strategy uses these generated signals to perform backtesting and evaluate its performance.