This Expert Advsior uses the MT4 Time Functions as Part of it’s Entry Logic
The entry logic of this system uses the High and Low values of the candle that is formed at 7:00. The High value is used as a signal to open a BUY trade and the Low value is used as the stoploss.
On the “OpenBuyTrade” drawing I use the MQL function Hour to get the current hour. The hour function returns a number between 0-23.
I also use a function that I added to the toolbox a while ago that determines if a new bar has just been created. This function is called “fnIsNewBar” and returns a value of true or false.
Then I create a Logic Element, named “isSeven”, that checks to see if a new bar has just been created AND if the hour is 8. If this is true, then the 7 o-clock candle has just finished forming, so we can get the final values for the High and Low of the candle.
I get the High and Low values using the MQL series functions High and Low. (The 1 signifies that we are getting the values from the last fully-formed candle). I store the high and low values in the variables “myHigh” and “myLow”, respectively.
So now we have the high and low price values from the 7 o’clock candle. These values will stay the same and will not be reset until the logic of “isSeven” is true . This won’t happen again until the next day:
Hour EQUAL_TO 7
“fnIsNewBar” EQUAL_TO true
Now for the Open Buy logic. We’ll open a buy order when the current Ask price is greater than “myHigh”.
Also, we’ll make sure it’s past 7 oclock. This is very important . It prevents us from opening a trade using an old value of “myHigh”.
So the logic of “IsOpenBuyTrue” is:
Hour GREATER_THAN 7
Bid GREATER_THAN “myHigh”
Finally, we want to set the stoploss to “myLow”. This is easy.
In the “fnOpenBuy” configuration window, for the stoploss parameter, check the radio button “Absolute value (price)” and use the “Choose” button to set the value to “myLow” (or just type myLow into the textbox).
That’s it. Just press the “Build” button and the Expert Advisor is complete!
A couple of noteworthy points:
This drawing has 2 links coming from the Start Element and uses the link-numbering feature to make sure the “isSeven” logic is executed before the “isOpenBuyTrue” logic is executed.
The variable element “myLow” does not connect to anything, not even an End Element. This prevents the execution from ending and allows the second link to execute the path connected to “isOpenBuyTrue”.
VTS System Zip File: BuyOnCandleHigh.zip