如何解决使用 iCustom
我刚刚从 mql4 移动到 mql5,现在我正在尝试从指标读取缓冲区值,但它只显示 0 而不是实际缓冲区值
这是我的代码:
#property version "1.00"
int handle1 = 0;
double valu1,valu2,valu3,valu4;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- create timer
EventSetTimer(60);
handle1 = iCustom(NULL,NULL,"LTD by KDMfx");
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//--- destroy timer
EventKillTimer();
IndicatorRelease(handle1);
}
//+------------------------------------------------------------------+
//| Get indicator value |
//+------------------------------------------------------------------+
double GetIndicator(int handle,int buffer_num,int index)
{
double arr[];
if(copyBuffer(handle,buffer_num,index+1,arr) <= 0)
{
Sleep(200);
for(int i=0; i<100; i++)
{
if(BarsCalculated(handle) > 0)
break;
Sleep(50);
}
int copied = copyBuffer(handle,arr);
if(copied <= 0)
{
Print("copyBuffer Failed. Maybe history has not download yet? Error = ",GetLastError());
return -1;
}
else
return (arr[index]);
}
return 0;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void OnTick()
{
//---
valu1 = GetIndicator(handle1,4);
valu2 = GetIndicator(handle1,1,4);
valu3 = GetIndicator(handle1,2,4);
valu4 = GetIndicator(handle1,3,4);
Comment("b1: ",valu1,"\nb2: ","\nb3: ","\nb4: ",valu4
);
}
我在这里做错了什么? 该指标不会出现在当前或最后一根关闭的蜡烛上,而是出现在当前+4 根蜡烛上,即过去的第 5 根蜡烛上。所以我使用“4”作为蜡烛 ID,但仍然没有用,无论我尝试什么我都可以让它工作
解决方法
尝试稍微简化一下。我没有您要阅读的指标的副本,但以下代码应该可以使用
#property version "1.10"
#property strict
int handle;
//+------------------------------------------------------------------+
//| Initialization function of the expert |
//+------------------------------------------------------------------+
int OnInit()
{
handle=iCustom(_Symbol,"LTD by KDMfx");
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Deinitialization function of the expert |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
IndicatorRelease(handle);
}
//+------------------------------------------------------------------+
//| "Tick" event handler function |
//+------------------------------------------------------------------+
void OnTick()
{
double LTDindicator[];
ArraySetAsSeries(LTDindicator,true);
CopyBuffer(handle,25,LTDindicator);
Comment(LTDindicator[0]);
return;
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。