ForexBoat Trading Academy

Switch Operator – MQL4 for Complete Beginners Tutorial Part 11

The Switch Operator is a handy tool for implementing lengthy conditional statements. However, from the previous three tutorials we already know a very simple tool for doing the same thing – multiple “if”, “else if”, and “else” statements. Now this alternative may not be as elegant as using the Switch operator, but it is simpler. Having that in mind, consider this tutorial optional. Do watch it if you would like to learn some extra information, otherwise feel free to skip straight to the next one! After all, you can always revisit any of the videos at a later stage.

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

Code For This Tutorial

Tutorial11.mq4:
//+------------------------------------------------------------------+
//| Tutorial11.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
//+------------------------------------------------------------------+
//| Script program start function |
//+------------------------------------------------------------------+
void OnStart()
{
int today = DayOfWeek(); //0 - Sunday, 1,2,3,4,5,6

switch(today)
{
case 1:
Alert("Today is Monday -> BUY");
break;
case 2:
Alert("Today is Tuesday -> SELL");
break;
default:
Alert("Other day, do not create orders");
break;
}

}