0% found this document useful (0 votes)
31 views

Lesson 3

Lesson 3

Uploaded by

Joe Syah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views

Lesson 3

Lesson 3

Uploaded by

Joe Syah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

MQL4 COURSE

By Coders g u ru
w w w . f orex -t sd. c om

-3DATA TYPES
--------------------

Welcome to my

thi rd lesson i n my M Q L 4 cou rse.

I hop e y ou enj oy ed the SY N T A X lesson, w hi ch tri ed to g i ve y ou the a nsw ers f or:


W ha t f orma t y ou ca n u se to w ri te M Q L 4 cod e?
H ow to ma k e the w orld better by commenti ng y ou r cod e?
W ha t the Id enti f i ers a re, a nd w ha t a re the ru les of choosi ng them?
W ha t a re the M Q L 4 R eserved w ord s?
If y ou d i d n t rea d the SY N T A X lesson p lea se d ow nloa d i t f rom here:
http :/ / f orex -tsd .com/ a tta chment.p hp ? a tta chmenti d = 39 9
A nd y ou ca n d ow nloa d the W elcome lesson f rom here:
http :/ / f orex -tsd .com/ a tta chment.p hp ? a tta chmenti d = 37 2
Dont f or g e t to l og i n f i r s t.
N ow , let s enjoy the D A T A T Y P E S.
W h a t s t h e D a t a t yp e m ea n?
A ny p rog ra mmi ng la ng u a g e ha s a set of na mes of the memory rep resenta ti on of the d a ta .
F or ex a mp le i f the memory hold s nu mbers betw een -214 7 4 8 36 4 8 to 214 7 4 8 36 4 7 , the
most of the p rog ra mmi ng la ng u a g es w i ll na me thi s d a ta a s I nt eg er d a ta ty p e.
V a r i a b l es ?
V a ri a bles a re the na mes tha t ref er to secti ons of memory i nto w hi ch d a ta ca n be stored .
T o help y ou thi nk of thi s a s a p i ctu re, i ma g i ne tha t memory i s a seri es of d i f f erent si z e
box es. T he box si z e i s memory stora g e a rea req u i red i n by tes.

In ord er to u se a box to store d a ta , the box mu st be g i ven a na me; thi s p rocess i s


k now n a s d ec l a r a t i on.
In the d ecla ra ti on p rocess y ou u se a w ord tell the comp u ter w ha t s the k i nd a nd
si z e of the box y ou w a nt to u se, thi s w ord k now n a s k eyw or d .

It help s i f y ou g i ve a box a mea ni ng f u l na me tha t rela tes to the ty p e of


i nf orma ti on w hi ch ma k e i t ea si er to f i nd the d a ta , thi s na me i s the v a r i a b l e
c ons t a nt .
D a ta i s p la ced i nto a box by a s s i g ni ng the d a ta to the box .
W hen w e set the va lu e of the box y ou ha ve crea ted i n the sa me li ne y ou d ecla red
the va ri a ble; thi s p rocess i s k now n a s i ni t i a l i z a t i on.

W hen w e crea te a va ri a ble w e a re telli ng the comp u ter tha t w e w a nt hi m to a ssi g n a


sp eci f i ed memory leng th (i n by tes) to ou r va ri a ble, si nce stori ng a si mp le nu mber, a letter
or a la rg e nu mber i s not g oi ng to occu p y the sa me sp a ce i n memory , so the comp u ter w i ll
a sk u s w ha t s the k i nd of d a ta a nd how mu ch the leng th of the d a ta ? T ha t i s the D a ta ty p e
f or.
F or ex a mp le i f w e sa i d thi s li ne of cod e to the comp u ter:
i nt M y V a ra i ble= 0 ;
T ha t s mea n w e a re a sk i ng the comp u ter to set a block of 4 by tes leng th to ou r va ri a ble
na med M y V a ra i a ble .
In the p revi ou s ex a mp le w e ha ve u sed :
i nt  Key w ord
i nt  Integ er d a ta ty p e.
i nt  D ecla ra ti on
M yV a r a i b l e  V a ri a ble s consta nt.
= 0  Ini ti a li z a ti on
W e w i ll k now more a bou t va ri a bles i n a comi ng lesson.
In M Q L 4 , these a re the k i nd s of D a ta ty p es:

Integ er (i nt)
B oolea n (bool)
C ha ra cter (cha r)
Stri ng (stri ng )
F loa ti ng -p oi nt nu mber (d ou ble)
C olor (color)
D a teti me (d a teti me)

1- I n t e g e r
A n i nteg er, i s a nu mber tha t ca n sta rt w i th a + or a - si g n a nd i s ma d e of d i g i ts. A nd
i ts ra ng e va lu e i s betw een -214 7 4 8 36 4 8 to 214 7 4 8 36 4 7 .
M Q L 4 p resents the i nteg er i n d eci ma l or hex a d eci ma l f orma t.

F or ex a mp le the nex t nu mbers a re Integ ers:


12, 3, 2134 , 0 , -230
0 x 0 A , 0 x 12, 0 X 12, 0 x 2f , 0 x A 3, 0 X a 3, 0 X 7 C 7
W e u se the k ey w ord i nt to crea te a n i nteg er va ri a ble.
F or ex a mp le:
i nt i ntInteg er = 0 ;
i nt i ntA notherIntg er = -10 0 ;
i nt i ntH ex Intg er= 0 x 12;
De c i m a l a nd H e x a d e c i m a l :
De c i m a l
3 , 4 , 5 , 6
d e c im a l
s y m b ol s

nota ti on i s
, 7 , 8 a nd 9
p oi nt w h i c h
+ ( p l u s ) or

th e w r i ti ng of nu
) to r e p r e s e nt nu
i nd i c a te s th e s ta
( m i nu s ) to i nd

m b e r s i n th e b a s e of 1 0, a nd u s e s d i g i ts ( 0, 1 , 2 ,
m b e r s . T h e s e d i g i ts a r e f r e q u e ntl y u s e d w i th a
r t of a f r a c ti ona l p a r t, a nd w i th one of th e s i g n
i c a te s i g n.

H e x a d e c i m a l i s a nu m e r a l s y s te m w i th a b a s e of 1 6 u s u a l l y w r i tte n u s i ng th e s y m b ol s
09 a nd A F or a f .
F or e x a m p l e , th e d e c i m a l nu m e r a l 7 9 c a n b e w r i tte n a s 4 F i n h e x a d e c i m a l .

2- B o o l e a n
B oolea n va ri a ble i s a d a ta ty p e w hi ch ca n hold only tw o va lu es, tru e a nd f a lse (or
thei r nu meri c rep resenta ti on, 0 a nd 1). A nd i t occu p i es 1 bi t of the memory .
In M Q L 4 , f a lse,F A L SE ,F a lse,tru e,T R U E a nd T ru e a re eq u a ls.
B ool e a n na m e d l i k e th i s i n th e h onor of th e g r e a t m a th e m a ti c i a n B ool e G e or g e .
W e u se the k ey w ord b ool to crea te a boolea n va ri a ble.
F or ex a mp le:
bool I = tru e;
bool bF la g = 1;
bool bB ool= F A L SE ;

3- Ch a r a c t e r
M Q L 4 na m e s th i s Da ta ty p e L i te r a l .
A cha ra cter i s one of 256 d ef i ned a lp ha beti c, nu meri c, a nd sp eci a l k ey elements
d ef i ned i n the A SC II (A meri ca n Sta nd a rd C od e f or Inf orma ti on Intercha ng e) set.
C ha ra cters ha ve i nteg er va lu es corresp ond i ng to loca ti on i n the A SC II set.
Y ou w ri te the cha ra cter consta nt by u si ng si ng le q u otes (') su rrou nd i ng the cha ra cter.
F or ex a mp le:
'a ' , '$ ' , 'Z '
W e u se the k ey w ord i nt to crea te a cha ra cter va ri a ble.
F or ex a mp le:
i nt chrA = 'A ';
i nt chrB = '$ ';
Some cha ra cters ca lled Sp eci a l C ha ra cters ca n t p resent d i rectly i nsi d e the si ng le
q u otes beca u se they ha ve a reserved mea ni ng s i n M Q L 4 la ng u a g e.
H ere w e u se somethi ng ca lled E s c a p e S eq u enc e to p resent those sp eci a l cha ra cters,
A nd tha t by p ref i x i ng the cha ra cter w i th the ba ck sla sh cha ra cter (\).
F or ex a mp le:
i nt chrA = '\\';
i nt chrB = '\n';

/ / sla sh cha ra cter


/ / new li ne

T hi s i s the li st of E sca p e Seq u ence cha ra cters u sed i n M Q L 4 .


ca rri a g e retu rn
new li ne
hori z onta l ta b
reverse sla sh
si ng le q u ote
d ou ble q u ote
hex a d eci ma l A SC II-cod e

\r
\n
\t
\\
\'
\"
\x hh

ASCI I t a b l e
Char Dec Oct Hex | Char Dec Oct Hex | Char Dec Oct Hex | Char Dec Oct
Hex
------------------------------------------------------------------------------------(nul)
0 0000 0x00 | (sp)
32 0040 0x20 | @
64 0100 0x40 | `
96 0140 0x60
(soh)
1 0001 0x01 | !
33 0041 0x21 | A
65 0101 0x41 | a
97 0141 0x61
(stx)
2 0002 0x02 | "
34 0042 0x22 | B
66 0102 0x42 | b
98 0142 0x62
(etx)
3 0003 0x03 | #
35 0043 0x23 | C
67 0103 0x43 | c
99 0143 0x63
(eot)
4 0004 0x04 | $
36 0044 0x24 | D
68 0104 0x44 | d
100 0144 0x64
(enq)
5 0005 0x05 | %
37 0045 0x25 | E
69 0105 0x45 | e
101 0145 0x65
(ack)
6 0006 0x06 | &
38 0046 0x26 | F
70 0106 0x46 | f
102 0146 0x66
(bel)
7 0007 0x07 | '
39 0047 0x27 | G
71 0107 0x47 | g
103 0147 0x67
(bs)
8 0010 0x08 | (
40 0050 0x28 | H
72 0110 0x48 | h
104 0150 0x68
(ht)
9 0011 0x09 | )
41 0051 0x29 | I
73 0111 0x49 | i
105 0151 0x69
(nl)
10 0012 0x0a | *
42 0052 0x2a | J
74 0112 0x4a | j
106 0152 0x6a
(vt)
11 0013 0x0b | +
43 0053 0x2b | K
75 0113 0x4b | k
107 0153 0x6b
(np)
12 0014 0x0c | ,
44 0054 0x2c | L
76 0114 0x4c | l
108 0154 0x6c
(cr)
13 0015 0x0d | 45 0055 0x2d | M
77 0115 0x4d | m
109 0155 0x6d
(so)
14 0016 0x0e | .
46 0056 0x2e | N
78 0116 0x4e | n
110 0156 0x6e
(si)
15 0017 0x0f | /
47 0057 0x2f | O
79 0117 0x4f | o
111 0157 0x6f
(dle) 16 0020 0x10 | 0
48 0060 0x30 | P
80 0120 0x50 | p
112 0160 0x70
(dc1) 17 0021 0x11 | 1
49 0061 0x31 | Q
81 0121 0x51 | q
113 0161 0x71
(dc2) 18 0022 0x12 | 2
50 0062 0x32 | R
82 0122 0x52 | r
114 0162 0x72
(dc3) 19 0023 0x13 | 3
51 0063 0x33 | S
83 0123 0x53 | s
115 0163 0x73
(dc4) 20 0024 0x14 | 4
52 0064 0x34 | T
84 0124 0x54 | t
116 0164 0x74
(nak) 21 0025 0x15 | 5
53 0065 0x35 | U
85 0125 0x55 | u
117 0165 0x75
(syn) 22 0026 0x16 | 6
54 0066 0x36 | V
86 0126 0x56 | v
118 0166 0x76
(etb) 23 0027 0x17 | 7
55 0067 0x37 | W
87 0127 0x57 | w
119 0167 0x77
(can) 24 0030 0x18 | 8
56 0070 0x38 | X
88 0130 0x58 | x
120 0170 0x78
(em)
25 0031 0x19 | 9
57 0071 0x39 | Y
89 0131 0x59 | y
121 0171 0x79
(sub) 26 0032 0x1a | :
58 0072 0x3a | Z
90 0132 0x5a | z
122 0172 0x7a
(esc) 27 0033 0x1b | ;
59 0073 0x3b | [
91 0133 0x5b | {
123 0173 0x7b
(fs)
28 0034 0x1c | <
60 0074 0x3c | \
92 0134 0x5c | |
124 0174 0x7c
(gs)
29 0035 0x1d | =
61 0075 0x3d | ]
93 0135 0x5d | }
125 0175 0x7d
(rs)
30 0036 0x1e | >
62 0076 0x3e | ^
94 0136 0x5e | ~
126 0176 0x7e
(us)
31 0037 0x1f | ?
63 0077 0x3f | _
95 0137 0x5f | (del) 127 0177 0x7f

4- St r i n g
T he stri ng d a ta ty p e i s a n a rra y of cha ra cters enclosed i n d ou ble q u ote (").
T he a rra y of cha ra cters i s a n a rra y w hi ch hold s one cha ra cter a f ter a nother, sta rti ng a t
i nd ex 0 . A f ter the la st cha ra cter of d a ta , a N U L L cha ra cter i s p la ced i n the nex t a rra y
loca ti on. It d oes not ma tter i f there a re u nu sed a rra y loca ti ons a f ter tha t.
A N U L L cha ra cter i s a sp eci a l cha ra cter (rep resented by the A SC II cod e 0 ) u sed to
ma rk the end of thi s ty p e of stri ng .
See f i g u re 1 f or a si mp le rep resenta ti on of the stri ng consta nt hello i n the cha ra cters
a rra y .

F i g u r e 1 Ch a r a c t e r s a r r a y
M Q L 4 li mi ts the si z e of the stri ng va ri a ble to 255 cha ra cters a nd a ny cha ra cter a bove
255 cha ra cters w i ll g enera te thi s error: (too l ong s tr i ng ( 2 5 5 c h a r a c te r s m a x i m u m ) ).
Y ou ca n u se a ny sp eci a l cha ra cter -menti oned a bove- i n y ou r stri ng consta nt by
p ref i x i ng i t w i th the ba ck sla sh (\).
W e u se the k ey w ord s t r i ng to crea te a stri ng va ri a ble.
F or ex a mp le:
stri ng str1 = "H ello w orld 1, w i th y ou cod ers g u ru ;
stri ng str2 = "C op y ri g ht 20 0 5, \"F orex -tsd f oru m\"."; / / N oti ce the u se of (") cha ra cter.
stri ng str3 = "1234 56 7 8 9 0 ";

5- F l o a t i n g -p o i n t n u m b e r ( d o u b l e )
F loa ti ng p oi nt nu mber i s the R ea l N u mber (tha t i s, a nu mber tha t ca n conta i n a
f ra cti ona l p a rt besi d e the i nteg er p a rt sep a ra ted w i th (.) d ot).E x : 3.0 ,-115.5, 15 a nd
0 .0 0 0 1.
A nd i ts ra ng e va lu e i s betw een 2.2e-30 8 to 1.8 e30 8 .
W e u se the k ey w ord d ou b l e to crea te a f loa ti ng -p oi nt va ri a ble.
F or ex a mp le:
d ou ble d blN u mber1 = 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ;
d ou ble d blN u mber3 = 1/ 4 ;
d ou ble d blN u mber3 = 5.7 5;

6- Co l o r
C olor d a ta ty p e i s a sp eci a l M Q L 4 d a ta ty p e, w hi ch hold s a color a p p ea rs on the
M eta T ra d er cha rt w hen y ou crea te y ou r ow n E x p ert A d vi sor or C u stom Ind i ctor a nd
the u ser ca n cha ng e i t f rom the p rop erty ta b of y ou r E x p ert A d vi sor or C u stom
Ind i ctor.
Y ou ca n set the C olor va ri a ble consta nt i n three w a y s:
1- B y t h e c ol or na m e: F or the w ell k now colors (ca lled W eb C olors Set) y ou ca n
a ssi g n the na me of the color to the color va ri a ble, see the li st of the W eb C olors Set.
2- B y C h a r a c t er r ep r es ent a t i on (M Q L 4 na med i t thi s na me): In thi s method y ou u se
the k ey w ord (C ) f ollow ed by tw o si g na l q u ota ti ons ('). B etw een the tw o si g na l
q u ota ti ons y ou set the va lu e of the red , g reen a nd blu e (k now a s R G B va lu e of the
color). T hese va lu es ha ve to be betw een: 0 to 255. A nd y ou ca n w ri te these va lu es i n
d eci ma l or hex a d eci ma l f orma t.
3- B y t h e i nt eg er v a l u e: E very color i n the W eb C olors Set ha s i ts i nteg er va lu e
w hi ch y ou ca n w ri te i t i n d eci ma l or hex a d eci ma l f orma t. A nd y ou ca n a ssi g n the
Integ er va lu e of the color to the color va ri a ble. T he hex a d eci ma l color f orma t look s
li k e thi s: 0 x B B G G R R w here B B i s the blu e va lu e, G G i s g reen va lu e a nd R R i s the
red va lu e.
F or ex a mp le:
/ / sy mbol consta nts
C '128 ,128 ,128 ' / / g ra y
C '0 x 0 0 ,0 x 0 0 ,0 x F F ' / / blu e
/ / na med color
R ed
Y ellow
B la ck
/ / i nteg er-va lu ed rep resenta ti on
0 x F F F F F F
/ / w hi te
16 7 7 7 215
/ / w hi te
0 x 0 0 8 0 0 0
/ / g reen
327 6 8
/ / g reen
W e u se the k ey w ord c ol or to crea te a color va ri a ble.
F or ex a mp le:
color clr1= R ed ;
color clr1= C '128 ,128 ,128 ' ;

color clr1= 327 6 8 ;

W e b Co l o r s Se t
Black

D ar kG r e e n

D ar kS lat e G r ay

S e aG r e e n

D ar kG o ld e n r o d

D ar kS lat e Blu e

G o ld e n r o d

M e d iu m S p r in g G r e e n

L aw n G r e e n

M ar o o n

I n d ig o

L i g h t S e aG r e e n
D ar kO r an g e

D ar kV i o le t
O r an g e

D e e p S ky Blu e

L i g h t S lat e G r ay

Blu e

K h aki

P ale G r e e n

M e d i u m S e aG r e e n

C h o co lat e

G o ld

Y e llo w

C h ar t r e u s e

M ag e n t a

G r e e n Y e llo w
H o t P in k

L ig h t G r e e n

P o w d e r Blu e

Be i g e

A n t iq u e W h it e

M i n t C r e am

S n o w

L ig h t P in k

L av e n d e r

M is t y R o s e

L av e n d e r Blu s h

M e d i u m V i o le t R e d

T h i s t le

M o ccas i n

L e m o n C h if f o n

F i r e Br i ck

C o r al

Bu r ly W o o d

P lu m

S ad d le Br o w n

P ale V i o le t R e d

D ar kS alm o n

T e al

D ar kO li v e G r e e n

M e d iu m T u r q u o is e

M e d i u m O r ch i d

G re e n

D ar kBlu e

D e e p P in k

I n d i an R e d

M e d i u m P u r p le

O li v e

M i d n i g h t Blu e

G ai n s b o r o
O ld L ace

S ie n n a

C ad e t Blu e
R e d

D o d g e r Blu e

M e d i u m Blu e
D ar kO r ch i d

P ap ay aW h i p

W h i t e S m o ke
W h it e

L im e G r e e n

O r an g e R e d

S lat e Blu e

D ar kK h aki

D ar kG r ay

S an d y Br o w n

M e d i u m S lat e Blu e

T an

S i lv e r

L i g h t S ky Blu e

L i g h t S t e e lBlu e

P in k

Bi s q u e

L i g h t G o ld e n R o d

Blan ch e d A lm o n d

Iv o r y

H o n e y d e w

A li ce Blu e

P ale T u r q u o i s e
C o r n s i lk

S e as h e ll

S lat e G r ay
T o m at o

L i g h t C o r al
L ig h t G r e y

L i g h t Y e llo w

P e r u

R o s y Br o w n

' / / N ew Y ea r
:27 '
:27 '
/ / eq u a l to D '19 8 0 .0 7 .19 12:0 0 :0 0 '
/ / eq u a l to D '0 1.0 1.20 0 4 0 0 :0 0 :0 0 '

W e u se the k ey w ord d a t et i m e to crea te a d a teti me va ri a ble.

Blu e V i o le t
O r ch i d

L i g h t S alm o n

W h e at

N av aj o W h i t e

L i g h t C y an

D a teti me d a ta ty p e i s a sp eci a l M Q L 4 d a ta ty p e, w hi ch hold s a d a te a nd ti me d a ta .


Y ou set the D a teti me va ri a ble by u si ng the k ey w ord (D ) f ollow ed by tw o si g na l
q u ota ti ons ('). B etw een the tw o si g na l q u ota ti ons y ou w ri te a cha ra cter li ne consi sti ng
of 6 p a rts f or va lu e of y ea r, month, d a te, hou r, mi nu tes, a nd second s. D a teti me
consta nt ca n va ry f rom J a n 1, 19 7 0 to D ec 31, 20 37 .
F or ex a mp le:

A q u a

S ky Blu e

7- Da t e t i m e

D '20 0 4 .0 1.0 1 0 0 :0 0
D '19 8 0 .0 7 .19 12:30
D '19 .0 7 .19 8 0 12:30
D '19 .0 7 .19 8 0 12'
D '0 1.0 1.20 0 4 '

D i m G r ay

R o y alBlu e

G r ay

V i o le t

P e ach P u f f

S t e e lBlu e

T u r q u o is e

S alm o n

P ale G o ld e n r o d

C r im s o n

D ar kT u r q u o i s e

S p r in g G r e e n

D ar kS e aG r e e n

A q u am ar i n e

Y e llo w G r e e n

P u r p le

O li v e D r ab

L im e

M e d i u m A q u am ar i n e
C o r n f lo w e r Blu e

Br o w n

N av y

F o re s tG re e n

L i g h t Blu e

L in e n

F or ex a mp le:
d a teti me d tM y B i rthD a y = D '19 7 2.10 .19 12:0 0 :0 0 ';
d a teti me d t1= D '20 0 5.10 .22 0 4 :30 :0 0 ';

I hop e y ou enj oy ed the lesson.


T he nex t lesson w i ll be a bou t the O p era ti ons &

E x p ressi ons .

I w elcome very mu ch the q u esti ons a nd the su g g esti ons.

See y ou
C od er s G u r u
22-10 -20 0 5

You might also like