8
votes

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.

1
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 chartsDaniel Kniaz
@DanielKniaz okay, I want a solution in MQL5. I've edited the tags.TenOutOfTen
@DanielKniaz I asked another question a bit similar but with more detail and provided a working EA with a precise candlestick pattern here stackoverflow.com/questions/62479581/…TenOutOfTen

1 Answers

0
votes
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);
  }