一.MQL5初级语法(学过c++的简单看10分钟就可以)
input double lots=0.1;
int magicNum=170422;
void OnStart()
{
int aI=11234;
double bD = 1.23;
string cS = "字符串";
color dC=clrBlue;
datetime eT=D'2017.04.22 12:46:27';
int pI=_Digits;
int P2I=Digits();
int res=add(5,6);
int a = 5;
int b =6;
int res2=addReference(a,b);
string eS=StringFormat("nihao test %s:\n,age=%d,height=%.1f",_Symbol,20,176.5);
printf("nihao test %s:\n,age=%d,height=%.1f",_Symbol,20,176.5);
string soureS= "wang,li,zhang,san";
string findS ="san";
int fIndex=StringFind(soureS,findS,0);
string subS=StringSubstr(soureS,0,4);
string sArr[];
StringSplit(soureS,',',sArr);
}
int add(int x,int y)
{
return(x+y);
}
int addReference(int &x,int &y)
{
x = 2*x;
y = 2*y;
return(x+y);
}
二.MQL5中级语法
1.客户端全局变量(软件重启值也不会变)
#property copyright "Copyright 2017, MetaQuotes Software Corp."
#property link "https://www."
#property version "1.00"
int magic=170422;
string preClientVarName;
#define IsOpenBuy "isOpenBuy"
string isOpenBuyCV;
int OnInit()
{
preClientVarName=MQLInfoString(MQL_PROGRAM_NAME)+Symbol()+IntegerToString(magic);
isOpenBuyCV = preClientVarName+IsOpenBuy;
if(GlobalVariableCheck(isOpenBuyCV)==false)
{
GlobalVariableSet(isOpenBuyCV,0);
}
return(INIT_SUCCEEDED);
}
void OnDeinit(const int reason)
{
}
void OnTick()
{
if(GlobalVariableGet(isOpenBuyCV)==0)
{
GlobalVariableSet(isOpenBuyCV,1);
}
}
2.其他枚举,结构体,数组
#property copyright "Copyright 2017, MetaQuotes Software Corp."
#property link "https://www."
#property version "1.00"
enum openType
{
buy,
sell,
buyAndSell,
};
input openType oType=buy;
input ENUM_TIMEFRAMES timePeroid=PERIOD_H1;
struct kBar
{
double open;
double close;
double high;
double low;
datetime time;
int vol;
};
double b[10];
double a[];
int OnInit()
{
double tempD=b[0];
ArrayResize(a,2);
tempD=a[0];
int aArr[10];
ArrayInitialize(aArr,1);
ArrayFill(aArr,2,2,2);
return(INIT_SUCCEEDED);
}
void OnDeinit(const int reason)
{
}
void OnTick()
{
kBar kb;
kb.open=1.1;
kb.close=1.2;
kb.high = 1.3;
kb.low=1.0;
kb.time= TimeCurrent();
kb.vol = 100;
}
如果您发现本文对你有所帮助,如果您认为其他人也可能受益,请把它分享出去。