如何使用 metatrader 4 预定义变量
how to use metatrader 4 predefine variable
如何使用 Open[]、Close[]、High[]、low[] 等预定义变量?我无法让我的代码工作,当我在 EA 测试器中 运行 它时,好像变量中没有数据。对不起大家,我不是编程出身,但我懂基本的编程。
void OnTick()
{
if (OrdersTotal()==0)//if we have no open orders
double ma20 = iMA(NULL,0,20,0,MODE_EMA,PRICE_CLOSE,0);
double ma200 = iMA(NULL,0,200,0,MODE_EMA,PRICE_CLOSE,0);
double rsi = iRSI(NULL,0,12,PRICE_OPEN,0);
if (ma20>ma200 && rsi<65 && Close[1]<Open[1] && High[1]>Open[1] && High[0]>High[1])
//send a buy order
int buyticket = OrderSend
(
Symbol(), //Currency pair on the chart
OP_BUY, //Buy/sell Command
0.01, //Lot Size
Ask, //Price for the command
3, //Slippage usually 3
Ask-100*_Point, //Stoploss
Ask+100*_Point, //Take Profit
NULL, //Commend
0, //Magic No
0, //Expiry
Green //Arrow colour
);
}
您的代码工作正常,但是您没有正确使用括号来让您的 if 语句正确运行。
if (OrdersTotal()==0)//if we have no open orders
{
double ma20 = iMA(NULL,0,20,0,MODE_EMA,PRICE_CLOSE,0);
double ma200 = iMA(NULL,0,200,0,MODE_EMA,PRICE_CLOSE,0);
double rsi = iRSI(NULL,0,12,PRICE_OPEN,0);
if (ma20>ma200 && rsi<65 && Close[1]<Open[1] && High[1]>Open[1] && High[0]>High[1])
{
//send a buy order
int buyticket = OrderSend
(
Symbol(), //Currency pair on the chart
OP_BUY, //Buy/sell Command
0.01, //Lot Size
Ask, //Price for the command
3, //Slippage usually 3
Ask-100*_Point, //Stoploss
Ask+100*_Point, //Take Profit
NULL, //Commend
0, //Magic No
0, //Expiry
Green //Arrow colour
);
}
}
如何使用 Open[]、Close[]、High[]、low[] 等预定义变量?我无法让我的代码工作,当我在 EA 测试器中 运行 它时,好像变量中没有数据。对不起大家,我不是编程出身,但我懂基本的编程。
void OnTick() {
if (OrdersTotal()==0)//if we have no open orders
double ma20 = iMA(NULL,0,20,0,MODE_EMA,PRICE_CLOSE,0);
double ma200 = iMA(NULL,0,200,0,MODE_EMA,PRICE_CLOSE,0);
double rsi = iRSI(NULL,0,12,PRICE_OPEN,0);
if (ma20>ma200 && rsi<65 && Close[1]<Open[1] && High[1]>Open[1] && High[0]>High[1])
//send a buy order
int buyticket = OrderSend
(
Symbol(), //Currency pair on the chart
OP_BUY, //Buy/sell Command
0.01, //Lot Size
Ask, //Price for the command
3, //Slippage usually 3
Ask-100*_Point, //Stoploss
Ask+100*_Point, //Take Profit
NULL, //Commend
0, //Magic No
0, //Expiry
Green //Arrow colour
);
}
您的代码工作正常,但是您没有正确使用括号来让您的 if 语句正确运行。
if (OrdersTotal()==0)//if we have no open orders
{
double ma20 = iMA(NULL,0,20,0,MODE_EMA,PRICE_CLOSE,0);
double ma200 = iMA(NULL,0,200,0,MODE_EMA,PRICE_CLOSE,0);
double rsi = iRSI(NULL,0,12,PRICE_OPEN,0);
if (ma20>ma200 && rsi<65 && Close[1]<Open[1] && High[1]>Open[1] && High[0]>High[1])
{
//send a buy order
int buyticket = OrderSend
(
Symbol(), //Currency pair on the chart
OP_BUY, //Buy/sell Command
0.01, //Lot Size
Ask, //Price for the command
3, //Slippage usually 3
Ask-100*_Point, //Stoploss
Ask+100*_Point, //Take Profit
NULL, //Commend
0, //Magic No
0, //Expiry
Green //Arrow colour
);
}
}