EA31337 / Strategy-HeikenAshi

Strategy based on the Heiken Ashi candlesticks.
3 stars 4 forks source link

Heiken Ashi strategy is opening buy positions only #6

Open mavidelisi opened 1 year ago

mavidelisi commented 1 year ago

Hi Kenorb;

Heiken Ashi strategy is constantly opening a Buy position .

I have constantly changed the parameters, but it still opens the buy position. In no way is sell opening the position. Can you check the source code? Is there a bug, I wonder?

Thanks.

kenorb commented 1 year ago

In general, Heiken Ashi indicator produces OHLC candles which are more smooth to regular one. So the strategy have to work on candle pattern conditions.

In general, I don't think there is a particular problem with the logic, it's how the strategy was written and optimized, and how the list of pattern is structured.

Let me explain the logic behind it (code as per v1.013):

      case ORDER_TYPE_BUY:
        _result &= _method == 0 ? PatternCandle2::CheckPattern(PATTERN_2CANDLE_BULLS, _ohlc)  : PatternCandle1::CheckPattern(PATTERN_1CANDLE_BULL, _ohlc[0]);
        _result &= _method > 0 ? PatternCandle3::CheckPattern((ENUM_PATTERN_3CANDLE)(1 << (_method - 1)), _ohlc) : _result;
        _result &= _method < 0 ? PatternCandle4::CheckPattern((ENUM_PATTERN_4CANDLE)(1 << -(_method + 1)), _ohlc) : _result;
        break;
      case ORDER_TYPE_SELL:
        _result &= _method == 0 ? PatternCandle2::CheckPattern(PATTERN_2CANDLE_BEARS, _ohlc) : PatternCandle1::CheckPattern(PATTERN_1CANDLE_BEAR, _ohlc[0]);
        _result &=  _method > 0 ? PatternCandle3::CheckPattern((ENUM_PATTERN_3CANDLE)(1 << (_method - 1)), _ohlc) : _result;
        _result &=  _method < 0 ? PatternCandle4::CheckPattern((ENUM_PATTERN_4CANDLE)(1 << -(_method + 1)), _ohlc) : _result;
        break;

Code explanation:

So the issue here is more in selected method that these patterns aren't neutral, but open signal is focused more on bull pattern. So the problem is that on open signal, we expect only one pattern shared across both buy and sell which is kind of limitation.

What the code should have is to have look for different/separate patterns for buy and sell. This has been already solved in Pattern strategy where _method value have information about 2 patterns (one for buy, another for sell). I'm going to revise this strategy and improve its logic based on it, so buy and sell could have different patterns being set.

Another way is to refactor Pattern code and organize enums by split them into 3 categories: bullish, bearish and neutral. But I'm not sure at this point if that's possible (to categorize) with all the patterns.

At this point, you'll have to re-optimize Signal open/close method params so the trades works better.

mavidelisi commented 1 year ago

just like you said, I changed the logic and open signal parameters. Bull continuation and bear continuation values (UDDU and DUUP) are different. i just made a few changes to the logic part of the heiken ashi strategy. thank you. i solved the problem.