8

I am trying to search figure out how to search for a pattern within a range of timeframes. Obviously, it is likely that the pattern would occur several times based on the timeframes, that’s why I’m particularly interested in the largest number of times it repeats.

To explain what I’m trying to achieve further, say I am searching for a pattern from 2 hour to 15 minute chart and I find it on the 2 hour chart, then I drill into the next timeframe 1 hour, and I end up with two of the patterns on the 1 hour chart, I’ll continue to the 30 minute (in both 1 hour patterns) and to 15 minutes till I get the largest time it occurs.

I believe that a method that returns the next lower timeframe would be needed. I’ve been able to write that, see code below. I would really appreciate some help.

ENUM_TIMEFRAMES findLowerTimeframe(ENUM_TIMEFRAMES timePeriod)
{
   int timeFrames[5] = {15, 20, 30, 60, 120};

   int TFIndex=ArrayBsearch(timeFrames, (int)timePeriod);

   return((ENUM_TIMEFRAMES) timeFrames[TFIndex - 1]);
}

EDIT

I didn't add the specific candlestick pattern because I believe it isn't the most important part of my problem. The crux of the question is how to search for a pattern on several consecutive timeframes to find the largest number of times it occurs within the range of times.

TenOutOfTen
  • 427
  • 3
  • 13
  • I do not quite understand what you want to achieve. Is it MQL4 or MQL5 (you've added both tags). In MQL5, PERIOD_H1 (for example) wont cast to 60, so your casting won't work. In MQL4 it will, but 20- and 120- minute tfs are custom charts – Daniel Kniaz Oct 16 '19 at 10:20
  • @DanielKniaz okay, I want a solution in MQL5. I've edited the tags. – TenOutOfTen Oct 16 '19 at 17:32
  • @DanielKniaz I asked another question a bit similar but with more detail and provided a working EA with a precise candlestick pattern here https://stackoverflow.com/questions/62479581/how-to-search-for-a-candlestick-pattern-on-multiple-timeframes – TenOutOfTen Jun 19 '20 at 22:53

1 Answers1

0
const ENUM_TIMEFRAMES DEFAULT_TIMEFRAMES[5] = {PERIOD_M15, PERIOD_M20, PERIOD_M30, PERIOD_H1, PERIOD_H2};
ENUM_TIMEFRAMES findLowerTimeframe(ENUM_TIMEFRAMES timePeriod)
  {
   int TFIndex=ArrayBsearch(DEFAULT_TIMEFRAMES,timePeriod);
   return(TFIndex>0 ? timeFrames[TFIndex - 1] : PERIOD_CURRENT);
  }
Daniel Kniaz
  • 4,338
  • 2
  • 11
  • 18
  • Thanks. How can I use this to search for the largest number of times a candlestick pattern occurs from 2 hours to 15 minutes as I explained above? – TenOutOfTen Oct 16 '19 at 21:07
  • 1
    I have no idea. show what pattern you tried to search, both in words and in text – Daniel Kniaz Oct 17 '19 at 09:09
  • I am interested in searching for a bearish candle with the upper and lower wick similar/equal in length followed by a bullish pinbar. I want to search on this pattern on all times from 2 hours to 15 minutes and find where the pattern appears the largest number of times within the timeframes. – TenOutOfTen Oct 17 '19 at 20:42
  • @DanielKniaz I would really appreciate some help with this https://stackoverflow.com/questions/62528297/how-to-use-copyrates-to-search-and-filter-through-several-timeframes-for-bulli – SuperHueman Jun 23 '20 at 06:28
  • @DanielKniaz I've created a bounty for the question with additional info. Please take a look https://stackoverflow.com/questions/62528297/how-to-use-copyrates-to-search-and-filter-through-several-timeframes-for-bulli – SuperHueman Jun 25 '20 at 08:07
  • @SuperHueman If you could describe what is bullish engulfing pattern, from your point of view, that would make things easier. – Daniel Kniaz Jun 26 '20 at 10:15
  • @DanielKniaz I have updated the question with the description of the bullish engulfing pattern. – SuperHueman Jun 26 '20 at 10:53