Professional Documents
Culture Documents
By Coders g u ru
w w w . f orex -t sd. c om
-8Variables
--------------------
Welcome to my
M Q L 4 v a ri a b les .
a s k u s w h a t s th e k i n d of d a ta a n d h ow mu ch th e len g th of th e d a ta ? T h a t i s th e D a ta ty p e
f or.
F or ex a mp le i f w e s a i d th i s li n e of cod e to th e comp u ter:
i n t M y V a ra i b le= 0 ;
T h a t s mea n w e a re a s k i n g th e comp u ter to s et a b lock of 4 b y tes len g th to ou r v a ri a b le
n a med M y V a ra i a b le .
In th e p rev i ou s ex a mp le w e h a v e u s ed :
i nt Key w ord
i nt In teg er d a ta ty p e.
i nt D ecla ra ti on
M yV ar ai bl e V a ri a b le s con s ta n t.
= 0 In i ti a li z a ti on
W e w i ll k n ow more a b ou t v a ri a b les i n a comi n g les s on .
In M Q L 4 , th es e a re th e k i n d s of D a ta ty p es :
In teg er ( i n t)
B oolea n ( b ool)
C h a ra cter ( ch a r)
S tri n g ( s tri n g )
F loa ti n g -p oi n t n u mb er ( d ou b le)
C olor ( color)
D a teti me ( d a teti me)
D ec larat io n :
D ecla ri n g a v a ri a b le mea n s to i n trod u ce i t to th e w orld a n d s p eci f y i ts ty p e. B y u s i n g th e
k eyw or ds y ou h a v e lea rn ed i n th e D A T A T YP E S les s on ( i n t, d ou b le, ch a r, b ool, s tri n g ,
color a n d d a teti me) w i th th e n a me y ou ch os e to th e v a ri a b le.
F or ex a mp le:
i n t M y V a ra i b le;
a v
ca
L 4
-v
I n it ializ at io n :
In i ti a li z i n g th e v a ri a b le mea n s to a s s i g n a v a lu e to i t, f or ex a mp le M yV ar ai bl e= 0 ;
You ca n i n i ti a li z e th e v a ri a b le a t th e s a me li n e of th e d ecla ra ti on li k e th e ex a mp le:
i nt M yV ar ai bl e= 0 ;
A n d y ou ca n d ecla re th e v a ri a b le i n on e p la ce a n d i n i ti a li z e i t i n a n oth er p la ce li k e th i s :
i n t M y V a ra i b le;
M y V a ra i b le= 5 ;
B u t k eep i n y ou r mi n d th i s f a ct: t h e decl ar at i on m u s t be bef or e t h e i ni t i al i z at i on.
S c o p es o f v ariables:
T h ere a re tw o s cop es of th e v a ri a b les , L oca l a n d G lob a l.
S cop e mea n s , w h i ch p a rt of cod e w i ll k n ow a b ou t th e v a ri a b le a n d ca n u s e i t.
L ocal v ar i abl e mea n s th ey a re n ot s een to ou ts i d e w orld w h ere th ey h a d d ecla red . F or
ex a mp le th e v a ri a b les d ecla red i n s i d e f u n cti on a re loca l to th e f u n cti on b lock of cod e, a n d
th e v a ri a b les d ecla red i n s i d e th e loop or d eci s i on s b lock of cod e a re loca l to th os e b lock s
a n d ca n b e s een or u s ed ou ts i d e th em.
F or ex a mp le:
d ou b le my _ f u n c ( d ou b le a , d ou b le b , d ou b le c)
{
in td ;
retu rn ( a * b + c) ;
}
In th e a b ov e ex a mp le th e v a ri a b les a,b,c a n d d a re loca l v a ri a b les , w h i ch ca n b e u s ed
on ly i n s i d e th e f u n cti on b lock of cod e ( a n y th i n g b es i d e th e b ra ces ) a n d ca n t b e u s ed b y
ou ts i d e cod e. S o w e ca n t w ri te a li n e a f ter th e f u n cti on a b ov e s a y i n g f or ex a mp le: d= 1 0 ;
b eca u s e d i s n ot s een to th e n ex t li n e of th e f u n cti on b eca u s e i t s ou ts i d e i t.
E x t ern v ariables:
T h e k ey w ord ex t er n u s ed to d ecla re a s p eci a l k i n d of v a ri a b les ; th os e k i n d s of
v a ri a b les a re u s ed to d ef i n e i n p u t d a te of th e p rog ra m, w h i ch y ou ca n s et th em f orm th e
p rop erty of y ou r E x p ert a d v i s or or C u s tom i n d i ca tor.
F or ex a mp le:
ex tern color In d i ca tor_ color = C ' 0 x 0 0 ,0 x 0 0 ,0 x F F ' ; / / b lu e
i n t i n i t( )
{
...
}
H ere th e v a ri a b le I ndi cat or _ col or h a d d ef i n ed a s a n ex t er n v a ri a b le w h i ch y ou w i ll s ee
i t th e f i rs t ti me y ou a tta ch y ou r i n d i ca tor ( or E A ) to th e M eta T ra d er ch a rt a n d w h i ch y ou
ca n ch a n g e i t f rom th e p rop erti es s h eet w i n d ow s . L ook a t F i g u re 1 .