0

使用,如果一个变量的值为 1而另一个变量的值为 3 MQL4,我如何执行BUY订单(见下文) ?
x
y

我需要它像这样工作:

多变的x = 1

多变的y = 3

所以如果xMORE 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");

 }

如果xLESS 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,反之亦然,所以任何帮助将不胜感激。

4

1 回答 1

1

所以,关于变量:

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语言重新设计成的-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;
                }
于 2016-08-23T15:20:37.990 回答