How to search for candle patterns on lower timeframes contained within a single candle in MQL5?

Jackery
259
Jackery  

Generally I know how to search for a pattern in lower timeframes between two datetime values. I need to do something a bit different now. How can I search within for patterns on lower timeframes within one candle? For example, say, I have an H1 bullish candle and I want to search for a candle pattern on say, M20, M15 and M10 with that H1, how will this be done.

Vladimir Karputov
Moderator
234291
Vladimir Karputov  
Jackery :

Generally I know how to search for a pattern in lower timeframes between two datetime values. I need to do something a bit different now. How can I search within for patterns on lower timeframes within one candle? For example, say, I have an H1 bullish candle and I want to search for a candle pattern on say, M20, M15 and M10 with that H1, how will this be done.

You need to work with the CopyRates function (apply the third form - request from time to time).

int  CopyRates(
   string           symbol_name,       // symbol name
   ENUM_TIMEFRAMES  timeframe,         // period
   datetime         start_time,        // start date and time
   datetime         stop_time,         // end date and time
   MqlRates         rates_array[]      // target array to copy
   );

Use the opening time of candles on a higher timeframe as the start and end time.


Here it will be like this: 'timeframe' is the timeframe on which you will search for the pattern (for example, it will be PERIOD_M15). 'start_time' and 'stop_time' - opening time of candles from the PERIOD_H1 timeframe

Documentation on MQL5: Timeseries and Indicators Access / CopyRates
Documentation on MQL5: Timeseries and Indicators Access / CopyRates
  • www.mql5.com
CopyRates - Timeseries and Indicators Access - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
Jackery
259
Jackery  
Vladimir Karputov:

You need to work with the CopyRates function (apply the third form - request from time to time).

Use the opening time of candles on a higher timeframe as the start and end time.


Here it will be like this: 'timeframe' is the timeframe on which you will search for the pattern (for example, it will be PERIOD_M15). 'start_time' and 'stop_time' - opening time of candles from the PERIOD_H1 timeframe

iTime and iBarShift feel sufficient for what I want to achieve. Though I would definitely want to check how I could implement it with CopyRates in the near future.

Using the same timeframe for both start and end time causes an issues when trying to get the range of indexes for lower timeframes for my search with iBarShift.


EDIT:

After looking at the definition of CopyRates I think I understand why you recommend I use it. Though I'm still trying to fully understand how to apply it. I would really appreciate some more info on applying it directly to my problem.

Vladimir Karputov
Moderator
234291
Vladimir Karputov  
Jackery :

iTime and iBarShift feel sufficient for what I want to achieve. Though I would definitely want to check how I could implement it with CopyRates in the near future.

Using the same timeframe for both start and end time causes an issues when trying to get the range of indexes for lower timeframes for my search with iBarShift.


EDIT:

After looking at the definition of CopyRates I think I understand why you recommend I use it. Though I'm still trying to fully understand how to apply it. I would really appreciate some more info on applying it directly to my problem.

I cannot tell you anything, since you did not indicate what you need. For example, I expect something like this: how can I find two candles that go in sequence (two bullish candles or two bearish ones) inside the 'H1' candle on the 'PERIOD_M15' timeframe)

Jackery
259
Jackery  
Vladimir Karputov:

I cannot tell you anything, since you did not indicate what you need. For example, I expect something like this: how can I find two candles that go in sequence (two bullish candles or two bearish ones) inside the 'H1' candle on the 'PERIOD_M15' timeframe)

Okay, let me be more specific.  I am looking for a bearish candle on M20 which has a close the same as another bearish candle contained in an M30 candle and finally both contained within an H1 bullish candle with the same close as the two M20 and M30 candles.

So we have the close of candles on 3 timeframes coinciding with the H1 being a bullish candle and M30 and M20 being bearish.


In case this is a bit confusing, I’ve attached screenshots to an example with the three timeframes.


EDIT:


The original screenshots that I provided didn't have enough information explaining what I desire to achieve. I've updated the screenshots now.

Vladimir Karputov
Moderator
234291
Vladimir Karputov  
Jackery :


On any timeframe, the current candle has the same 'Close' price. Therefore, your 'pattern' is not really any pattern.

Jackery
259
Jackery  
Vladimir Karputov:

On any timeframe, the current candle has the same 'Close' price. Therefore, your 'pattern' is not really any pattern.

But the current candle could be a bullish or a bearish candle too. Also please note that this is just one use case of certain types of patterns that I am researching on that have a high/low/open or close preserved over various lower timeframes within a given candle. I decided to start with this.


EDIT:

Being able to get this one would greatly serve as a foundation for me to work on other more complex patterns

Vladimir Karputov
Moderator
234291
Vladimir Karputov  
Jackery :

But the current candle could be a bullish or a bearish candle too. Also please note that this is just one use case of certain types of patterns that I am researching on that have a high/low/open or close preserved over various lower timeframes within a given candle. I decided to start with this.


EDIT:

Being able to get this one would greatly serve as a foundation for me to work on other more complex patterns

Why did you choose this particular candlestick on the H1 timeframe:

  • is it (for example) index 15?
  • or did it open at a specific time?
Jackery
259
Jackery  
Vladimir Karputov:

Why did you choose this particular candlestick on the H1 timeframe:

  • is it (for example) index 15?
  • or did it open at a specific time?
Simply because it satisfied the conditions I stated in the screenshots. No other reason in particular 
Vladimir Karputov
Moderator
234291
Vladimir Karputov  
Jackery :
Simply because it satisfied the conditions I stated in the screenshots. No other reason in particular 

This is not an answer. To refer to a candle you need: either its number or date. Without this data, the train will not run.

Jackery
259
Jackery  
Vladimir Karputov:

This is not an answer. To refer to a candle you need: either its number or date. Without this data, the train will not run.

You asked me why I chose the candle on H1. I haven’t been able to figure out coding this. I manually picked it out from looking at the charts. I realised that when the upper wick is sizeable then the it is more likely that the conditions are satisfied.