Coding Time Of Day Controls – MQL4 for Complete Beginners Tutorial Part 25

The preparation stage is complete and today we will finally start programming our FOREX Robot in MQL4. We will start by completing the blue section of the trading strategy design template, which is responsible for time of day controls. If you recall we want our expert advisor to send buy and sell orders only once at a certain hour of every day. That is exactly what we will implement today.

Enrol in the full course here: https://www.forexboat.com/learn-mql4


//+------------------------------------------------------------------+
//| SimpleSystem.mq4 |
//| Copyright 2014, ForexBoat |
//| http://www.forexboat.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2014, ForexBoat"
#property link "http://www.forexboat.com"
#property version "1.00"
#property strict

extern int StartHour = 9;

void OnTick()
{
static bool IsFirstTick = true;

if(Hour() == StartHour)
{
if(IsFirstTick == true)
{
IsFirstTick = false;

//CORE OF THE ALGORITHMIC TRADING SYSTEM

Alert("First tick of hour");
}

}
else
{
IsFirstTick = true;
}

}

 

What are you waiting for?

START LEARNING FOREX TODAY!

share This:
Muhammad Awais

3 Responses to “Coding Time Of Day Controls – MQL4 for Complete Beginners Tutorial Part 25”

June 11, 2016 at 1:28 am, Cao said:

Hi Kirill, I am copying the codes as I go and it appears that I am getting an error (refer to pic). Please let me know what I am doing wrong as it is driving me crazy!

Reply

June 11, 2016 at 1:35 am, Cao said:

Never mind, I figured it out. It was because the semicolon wasn’t added after the “9”. Gosh… one simple thing such as not including a semicolon can create 16 errors and ruin the entire system up. Even reading the description of the error doesn’t help much. It could’ve mentioned something like “add a semicolon after the 9”, but rather 16 error messages come up which makes it more confusing =

Reply

June 13, 2016 at 8:00 am, Kirill said:

Hi Cao,

Glad you figured it out! I know – errors can be very annoying in coding!

Good luck going forward.

Kirill

Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

What are you waiting for?

START LEARNING FOREX TODAY!

as seen on: