The YoyoActionStrategy is a trading strategy implemented as a class that inherits from the IStrategy interface. Here's a description of what the strategy does:
The strategy begins by populating various indicators based on the input dataframe, including:
'ohlc4': Calculating the average of the open, high, low, and close prices. 'ema_fast': Calculating the Exponential Moving Average (EMA) with a user-defined fast period.
'ema_slow': Calculating the Exponential Moving Average (EMA) with a user-defined slow period.
'rsi': Calculating the Relative Strength Index (RSI) with a user-defined period.
'macd': Calculating the Moving Average Convergence Divergence (MACD) by subtracting the fast EMA from the slow EMA. 'bullish' and 'bearish': Identifying bullish and bearish conditions based on the MACD values. Next, the strategy sets up stop-loss levels ('sl1' and 'sl2') based on the Average True Range (ATR) multiplied by user-defined factors. It then removes rows with missing values. The strategy defines various boolean columns for different states and signals, such as 'green', 'blue', 'yellow', 'brown', 'red', 'long', 'preBuy', 'short', 'preSell', 'trail2', 'greenLine', 'greenLine_last', 'short_last', 'green_last', 'red_last', and 'hold_state'. For each index in the dataframe, the strategy assigns values to these boolean columns based on specific conditions and calculations involving the indicators and previous values. These conditions determine the state of the strategy at each index and help generate buy and sell signals. After setting up these boolean columns, the strategy drops rows with missing values and continues with the remaining dataframe. Next, the strategy defines the 'signal_buy' and 'signal_sell' columns based on specific conditions. The 'signal_buy' column is set to True when there is a green buy signal or when the price crosses above the trailing stop loss (green line) and turns blue. The 'signal_sell' column is set to True when there is a red sell signal or when the green line is crossed below and turns false. Finally, the strategy populates the 'buy' and 'sell' columns in the dataframe based on the 'signal_buy' and 'signal_sell' values, respectively. Overall, the YoyoActionStrategy uses a combination of indicators, conditions, and trailing stop losses to generate buy and sell signals for trading.