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;
}

}

 

What are you waiting for?

START LEARNING FOREX TODAY!

Tags:
share This:
Muhammad Awais

2 Responses to “Switch Operator – MQL4 for Complete Beginners Tutorial Part 11”

August 09, 2014 at 1:15 pm, Jonathan said:

Yes! Finally someone writes about 1.

Reply

November 07, 2016 at 1:53 pm, Gin Ichimaru said:

Break? that’s how we end our love story. T_T

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: