I am quite new to writing mql4
code and would be grateful if I could get some help drawing rectangles when the following candlestick patterns occur:
FIG1:
Run code snippet
<blockquote class="imgur-embed-pub" lang="en" data-id="a/fRoPzsm"><a href="//imgur.com/a/fRoPzsm">Demand Zone 1</a></blockquote><script async src="//s.imgur.com/min/embed.js" charset="utf-8"></script>
FIG2:
Run code snippet
<blockquote class="imgur-embed-pub" lang="en" data-id="a/4E8KE1R" data-context="false"><a href="//imgur.com/a/4E8KE1R">Demand Zone 2</a></blockquote><script async src="//s.imgur.com/min/embed.js" charset="utf-8"></script>
and
FIG3:
Run code snippet
<blockquote class="imgur-embed-pub" lang="en" data-id="a/h6D6o6R"><a href="//imgur.com/a/h6D6o6R">Hidden Demand Zone</a></blockquote><script async src="//s.imgur.com/min/embed.js" charset="utf-8"></script>
and respective Supply Zones
and opening a pending order with specified pips Stop Loss and Take Profit.
Pardon me for not including the images directly. I don't I have enough upvotes to do that.
Here is an explanation of the candlestick patterns in the linked images:
Demand Zone
The general candlestick pattern
(Demand Zone) occurs when at least two or more consecutive bullish candles (with the last bullish candle high being the high of the time period) are followed by one or more bearish candles whose high and low are lower than the last bullish candle. Then finally followed by a bullish candle that forms the new high. The rectangle area which is the Demand Zone is taken from the Open to the Low of the last last bearish candle.
Hidden Demand Zone
When a series of consecutive bullish candles has a candle with its low, lower than the previous candle and its High coinciding with its Close, then the Hidden Demand Zone is taken from the low to the open of the bullish candle.
The full explanation is available here for both demand and supply zones.
I am aware that bullish
and bearish
candles can be determined by
if ( ( Open[1] - Close[1] ) > 0)
{
// candle is bearish
}
else
{
// candle is bullish
}
I would really appreciate some help.
I'm late :'( Work kept me from StackOverflow :'( Anyway, I won't be able to provide a full program as per the Bounty, nor can I provide the full code to solve this Demand Zone question.
However, I still would like to provide some "starting ground" for everyone to build their own Pattern Recognizer on MT4 (MQL4).
To keep the text short, I've recorded a YouTube video to describe it. https://youtu.be/WSiyY52QyBI
Anyway, here are the codes:
More importantly, is the clsBar.mqh. Note that this is an "include file", and should be located in the include folder. Include file helps us to make our program less clutter, and help us to be able to write re-usable codes. Very useful when writing OOP classes.
clsBar.mqh: Download (OneDrive) https://1drv.ms/u/s!AoLFy6fRYNsvjTU-xSzAADCwGjPQ
Unfortunately, the file is too large to be included in this post. So I have to upload it the OneDrive.
Seems these patterns are not fully described, so it is not possible to code them correctly. Ok, let us try with pattern#1. The conditions used for pattern(what seems reasonable from the picture):
1. check at start of the new bar(bar#0).
2. bar 1(which is bar#3 in MQL4 if we compute 0 as the current) must be bullish.
3. bar 2(bar#2) is bearish. (or N bars in case of pattern#2, N can be 2 or more) 4. bar 3(bar#1 in MT4) is bullish.
5. its high=close.
6. its high>high of bar#3.
What else you need here? To detect HL of the rectangle? That is simple, is rules are clear. Let us assume they are: for LONG, up=Open of bar#2, down=low of that bar. Then,
Do you need to draw a rectangle? Ok but how would you decide what is the time to stop drawing? Let us assume N bars to the right is enough, and let us ignore weekends for now(a bit more complicated if keeping in mind weekends when the market is closed).
here is the main block, do not forget to add a new bar check, otherwise the tool would check for objects every tick which is waste of time. string prefix=""; //add some unique prefix for all your objects const int N_bars = 15; //15 bars in this example