MQL4:如果 x 大于 y,则执行函数
MQL4: Execute function if x is more than y
使用 MQL4
,如何执行 BUY
订单(见下文)
如果一个变量 x
的值为 1
而另一个变量 y
的值为 3?
我需要它像这样工作:
变量x = 1
变量y = 3
所以如果x
是MORE THAN y
,执行这个脚本:
extern int TakeProfit = 10;
extern int StopLoss = 10;
void OnStart()
{
double TakeProfitLevel;
double StopLossLevel;
TakeProfitLevel = Bid + TakeProfit*Point;
StopLossLevel = Bid - StopLoss*Point;
Alert("TakeProfitLevel = ", TakeProfitLevel);
Alert("StopLossLevel = ", StopLossLevel);
OrderSend("USDCAD", OP_BUY, 1.0, Ask, 10, StopLossLevel, TakeProfitLevel, "first order");
}
如果 x
是 LESS THAN y
,执行这个 SELL
脚本:
extern int TakeProfit = 10;
extern int StopLoss = 10;
void OnStart()
{
double TakeProfitLevel;
double StopLossLevel;
TakeProfitLevel = Bid + TakeProfit*Point;
StopLossLevel = Bid - StopLoss*Point;
Alert("TakeProfitLevel = ", TakeProfitLevel);
Alert("StopLossLevel = ", StopLossLevel);
OrderSend("USDCAD", OP_SELL, 1.0, Ask, 10, StopLossLevel, TakeProfitLevel, "first order");
}
我正在努力寻找 MQL4
代码,该代码建立了可以相互比较的变量,例如x > y
反之亦然,如有任何帮助,我们将不胜感激。
因此,关于变量:
MQL4
曾经是编译型静态类型语言。
因此源代码包含所有先前的声明,以便允许编译器假设变量具有什么类型(和内部表示)。
int ii = 0;
double coeff = 1.23456789;
color anMQL_color = 0x224466; // could be stated as {int|hex|literals||colornames}
datetime aTimeNOW = D'2016.08.23';
string aLastMSG = "[ALARM] This TracePoint shall never be executed";
最近 MQL4
语言重新设计为 New-MQL4.56789
带来了一些新类型(即 struct
-s )
基本数据类型有:
·整数(char, short, int, long, uchar, ushort, uint, ulong
);
·合乎逻辑(bool
);
·文字 (ushort
);
·字符串(string
); (但是 struct
内部 (!!),所以在 DLL API 中要小心)
·浮点数(double, float
);
·颜色(color
);
·日期和时间(datetime
);
·枚举 (enum
).
复杂数据类型有:
·struct
;
·class
-es.
新语言还引入了类型转换,像这样:
int aFactoredNUMBER = EMPTY; // declaration + initial value assignment
aFactoredNUMBER = (int) ( coeff * 3.1412592653598 ); // operation with a resulting value type casting into (int)
那么 x > y
怎么样?
让我画几个 SLOC:
double x = 1,
y = 3;
...
..
.
if ( x > y ) { ... ;
OrderSend( , OP_BUY, ... );
return;
}
if ( x < y ) { ... ; // THIS
OrderSend( , OP_SELL, ... ); // COULD BE A CALL TO FUN( { OP_BUY | OP_SELL } )
return;
}
使用 MQL4
,如何执行 BUY
订单(见下文)
如果一个变量 x
的值为 1
而另一个变量 y
的值为 3?
我需要它像这样工作:
变量x = 1
变量y = 3
所以如果x
是MORE THAN y
,执行这个脚本:
extern int TakeProfit = 10;
extern int StopLoss = 10;
void OnStart()
{
double TakeProfitLevel;
double StopLossLevel;
TakeProfitLevel = Bid + TakeProfit*Point;
StopLossLevel = Bid - StopLoss*Point;
Alert("TakeProfitLevel = ", TakeProfitLevel);
Alert("StopLossLevel = ", StopLossLevel);
OrderSend("USDCAD", OP_BUY, 1.0, Ask, 10, StopLossLevel, TakeProfitLevel, "first order");
}
如果 x
是 LESS THAN y
,执行这个 SELL
脚本:
extern int TakeProfit = 10;
extern int StopLoss = 10;
void OnStart()
{
double TakeProfitLevel;
double StopLossLevel;
TakeProfitLevel = Bid + TakeProfit*Point;
StopLossLevel = Bid - StopLoss*Point;
Alert("TakeProfitLevel = ", TakeProfitLevel);
Alert("StopLossLevel = ", StopLossLevel);
OrderSend("USDCAD", OP_SELL, 1.0, Ask, 10, StopLossLevel, TakeProfitLevel, "first order");
}
我正在努力寻找 MQL4
代码,该代码建立了可以相互比较的变量,例如x > y
反之亦然,如有任何帮助,我们将不胜感激。
因此,关于变量:
MQL4
曾经是编译型静态类型语言。
因此源代码包含所有先前的声明,以便允许编译器假设变量具有什么类型(和内部表示)。
int ii = 0;
double coeff = 1.23456789;
color anMQL_color = 0x224466; // could be stated as {int|hex|literals||colornames}
datetime aTimeNOW = D'2016.08.23';
string aLastMSG = "[ALARM] This TracePoint shall never be executed";
最近 MQL4
语言重新设计为 New-MQL4.56789
带来了一些新类型(即 struct
-s )
基本数据类型有:
·整数(char, short, int, long, uchar, ushort, uint, ulong
);
·合乎逻辑(bool
);
·文字 (ushort
);
·字符串(string
); (但是 struct
内部 (!!),所以在 DLL API 中要小心)
·浮点数(double, float
);
·颜色(color
);
·日期和时间(datetime
);
·枚举 (enum
).
复杂数据类型有:
·struct
;
·class
-es.
新语言还引入了类型转换,像这样:
int aFactoredNUMBER = EMPTY; // declaration + initial value assignment
aFactoredNUMBER = (int) ( coeff * 3.1412592653598 ); // operation with a resulting value type casting into (int)
那么 x > y
怎么样?
让我画几个 SLOC:
double x = 1,
y = 3;
...
..
.
if ( x > y ) { ... ;
OrderSend( , OP_BUY, ... );
return;
}
if ( x < y ) { ... ; // THIS
OrderSend( , OP_SELL, ... ); // COULD BE A CALL TO FUN( { OP_BUY | OP_SELL } )
return;
}