iCustom() 缓冲区 - 如何从 MT4 中的自定义指标缓冲区获取值?
iCustom() buffer - how to get values from Custom Indicator buffers in MT4?
我正在尝试编写一个 EA,当自定义指标显示箭头 { 卖出或买入 } 时,该 EA 将下单。我正在使用 iCustom()
来执行此操作,但我正在努力比较值。
这是我的代码:
void OnTick()
{
//---
double sell=iCustom(NULL,0,"fx30",0,0);
double buy=iCustom(NULL,0,"fx30",1,0);
if(sell>0)//sell
{
//check if buy trade is running
//close a buy trade
//open a sell trade on success
if(buyTicket>0)
{
bool ret=OrderClose(buyTicket, lot, Bid, slipage,clrBlue);
if(ret==true)
{
printf("the sell number is: "+sell);
sellTicket=OrderSend(Symbol(),OP_SELL,lot,Bid,slipage,NULL,NULL,"MATHUNYA SELL",magic,0,clrRed);
}
}
else
{
//we dont have a buy trade open
//place a sell trade
//only one trade should be open
if(sellTicket>0)
{
printf("sell order already running");
}
else
{
printf("the sell number is: "+sell);
sellTicket=OrderSend(Symbol(),OP_SELL,lot,Bid,slipage,NULL,NULL,"MATHUNYA SELL",magic,0,clrRed);
}
}
}
else{
Print("buy: "+buy+", sell: "+sell+" Time: "+TimeToStr(Time[1]));
printf("awaiting sell order..");
}
if(buy>0)//buy
{
//check if sell trade is running
//close a sell trade
//open a buy trade on success
if(sellTicket>0)
{
bool ret=OrderClose(sellTicket, lot, Ask, slipage,clrYellow);
if(ret==true)
{
printf("the buy number is: "+buy);
buyTicket=OrderSend(Symbol(),OP_BUY,lot,Ask,slipage,NULL,NULL,"MATHUNYA BUY",magic,0,clrGreen);
}
}
else
{
//we dont have a sell trade open
//place a buy trade
//only one trade should be open
if(buyTicket>0)
{
printf("buy order already running");
}
else
{
printf("the buy number is: "+buy);
buyTicket=OrderSend(Symbol(),OP_BUY,lot,Ask,slipage,NULL,NULL,"MATHUNYA BUY",magic,0,clrGreen);
}
}
}else
{
Print("buy: "+buy+", sell: "+sell+" Time: "+TimeToStr(Time[1]));
printf("awaiting buy order..");
}
}
//+------------------------------------------------------------------+
// global variables
int buyTicket = 0;
int sellTicket = 0;
double lot = 0.01;
int slipage = 3;
int magic = 321;
比较值是什么意思?如我所见,您只比较 sell>0
和 buy>0
。我的建议:在比较添加行
的正下方
Print(__LINE__," indicator value = "+DoubleToStr(sell,Digits));
与 buy
相同。很可能,但当然我们这里没有 crystal 球,您的指标 returns 值(例如 100 或 1.16000)在一个缓冲区上,而 EMPTY_VALUE
在另一个缓冲区上。 EMPTY_VALUE 在 mql4 中是 2^31-1,所以它大于零。
如果您将看到指标值为 2147483648.00000 或类似的值,- 您需要将 sell > 0
替换为 sell != EMPTY_VALUE
或合并。
我正在尝试编写一个 EA,当自定义指标显示箭头 { 卖出或买入 } 时,该 EA 将下单。我正在使用 iCustom()
来执行此操作,但我正在努力比较值。
这是我的代码:
void OnTick()
{
//---
double sell=iCustom(NULL,0,"fx30",0,0);
double buy=iCustom(NULL,0,"fx30",1,0);
if(sell>0)//sell
{
//check if buy trade is running
//close a buy trade
//open a sell trade on success
if(buyTicket>0)
{
bool ret=OrderClose(buyTicket, lot, Bid, slipage,clrBlue);
if(ret==true)
{
printf("the sell number is: "+sell);
sellTicket=OrderSend(Symbol(),OP_SELL,lot,Bid,slipage,NULL,NULL,"MATHUNYA SELL",magic,0,clrRed);
}
}
else
{
//we dont have a buy trade open
//place a sell trade
//only one trade should be open
if(sellTicket>0)
{
printf("sell order already running");
}
else
{
printf("the sell number is: "+sell);
sellTicket=OrderSend(Symbol(),OP_SELL,lot,Bid,slipage,NULL,NULL,"MATHUNYA SELL",magic,0,clrRed);
}
}
}
else{
Print("buy: "+buy+", sell: "+sell+" Time: "+TimeToStr(Time[1]));
printf("awaiting sell order..");
}
if(buy>0)//buy
{
//check if sell trade is running
//close a sell trade
//open a buy trade on success
if(sellTicket>0)
{
bool ret=OrderClose(sellTicket, lot, Ask, slipage,clrYellow);
if(ret==true)
{
printf("the buy number is: "+buy);
buyTicket=OrderSend(Symbol(),OP_BUY,lot,Ask,slipage,NULL,NULL,"MATHUNYA BUY",magic,0,clrGreen);
}
}
else
{
//we dont have a sell trade open
//place a buy trade
//only one trade should be open
if(buyTicket>0)
{
printf("buy order already running");
}
else
{
printf("the buy number is: "+buy);
buyTicket=OrderSend(Symbol(),OP_BUY,lot,Ask,slipage,NULL,NULL,"MATHUNYA BUY",magic,0,clrGreen);
}
}
}else
{
Print("buy: "+buy+", sell: "+sell+" Time: "+TimeToStr(Time[1]));
printf("awaiting buy order..");
}
}
//+------------------------------------------------------------------+
// global variables
int buyTicket = 0;
int sellTicket = 0;
double lot = 0.01;
int slipage = 3;
int magic = 321;
比较值是什么意思?如我所见,您只比较 sell>0
和 buy>0
。我的建议:在比较添加行
的正下方
Print(__LINE__," indicator value = "+DoubleToStr(sell,Digits));
与 buy
相同。很可能,但当然我们这里没有 crystal 球,您的指标 returns 值(例如 100 或 1.16000)在一个缓冲区上,而 EMPTY_VALUE
在另一个缓冲区上。 EMPTY_VALUE 在 mql4 中是 2^31-1,所以它大于零。
如果您将看到指标值为 2147483648.00000 或类似的值,- 您需要将 sell > 0
替换为 sell != EMPTY_VALUE
或合并。