1评论

0收藏

4、接第三贴

avatar 追星 | 396 人阅读 | 1 人评论 | 2024-04-23

读取数据
下面提供了通过指标句柄获取数据的一般函数,在关于将振荡指标连接到EA的文章中,已经对这些函数进行了回顾。所提供的函数可以在自定义程序中“按原样”使用:
//+------------------------------------------------------------------+//| Return the indicator data on the specified bar                   |//+------------------------------------------------------------------+double IndicatorValue(const int ind_handle,const int index,const int buffer_num)  {   double array[1]={0};   ResetLastError();   if(CopyBuffer(ind_handle,buffer_num,index,1,array)!=1)     {      PrintFormat("%s: CopyBuffer failed. Error %ld",__FUNCTION__,GetLastError());      return EMPTY_VALUE;     }   return array[0];  }//+------------------------------------------------------------------+//| Return the state of the indicator line                           |//+------------------------------------------------------------------+ENUM_LINE_STATE LineState(const int ind_handle,const int index,const int buffer_num)  {//--- Get the values of the indicator line with the shift (0,1,2) relative to the passed index   const double value0=IndicatorValue(ind_handle,index,  buffer_num);   const double value1=IndicatorValue(ind_handle,index+1,buffer_num);   const double value2=IndicatorValue(ind_handle,index+2,buffer_num);//--- If at least one of the values could not be obtained, return an undefined value    if(value0==EMPTY_VALUE || value1==EMPTY_VALUE || value2==EMPTY_VALUE)      return LINE_STATE_NONE;//--- Line upward reversal (value2>value1 && value0>value1)   if(NormalizeDouble(value2-value1,ind_digits)>0 && NormalizeDouble(value0-value1,ind_digits)>0)      return LINE_STATE_TURN_UP;//--- Line upward direction (value2<=value1 && value0>value1)   else if(NormalizeDouble(value2-value1,ind_digits)<=0 && NormalizeDouble(value0-value1,ind_digits)>0)      return LINE_STATE_UP;//--- Line upward stop (value2<=value1 && value0==value1)   else if(NormalizeDouble(value2-value1,ind_digits)<=0 && NormalizeDouble(value0-value1,ind_digits)==0)      return LINE_STATE_STOP_UP;//--- Line downward reversal (value2<value1 && value0<value1)   if(NormalizeDouble(value2-value1,ind_digits)<0 && NormalizeDouble(value0-value1,ind_digits)<0)      return LINE_STATE_TURN_DOWN;//--- Line downward direction (value2>=value1 && value0<value1)   else if(NormalizeDouble(value2-value1,ind_digits)>=0 && NormalizeDouble(value0-value1,ind_digits)<0)      return LINE_STATE_DOWN;//--- Line downward stop (value2>=value1 && value0==value1)   else if(NormalizeDouble(value2-value1,ind_digits)>=0 && NormalizeDouble(value0-value1,ind_digits)==0)      return LINE_STATE_STOP_DOWN;//--- Undefined state   return LINE_STATE_NONE;  }//+------------------------------------------------------------------+//| Return the state of the line relative to the specified level     |//+------------------------------------------------------------------+ENUM_LINE_STATE LineStateRelative(const int ind_handle,const int index,const int buffer_num,const double level0,const double level1=EMPTY_VALUE)  {//--- Get the values of the indicator line with the shift (0,1) relative to the passed index   const double value0=IndicatorValue(ind_handle,index,  buffer_num);   const double value1=IndicatorValue(ind_handle,index+1,buffer_num);//--- If at least one of the values could not be obtained, return an undefined value    if(value0==EMPTY_VALUE || value1==EMPTY_VALUE)      return LINE_STATE_NONE;//--- Define the second level to compare   double level=(level1==EMPTY_VALUE ? level0 : level1);//--- The line is below the level (value1<level && value0<level0)   if(NormalizeDouble(value1-level,ind_digits)<0 && NormalizeDouble(value0-level0,ind_digits)<0)      return LINE_STATE_UNDER;//--- The line is above the level (value1>level && value0>level0)   if(NormalizeDouble(value1-level,ind_digits)>0 && NormalizeDouble(value0-level0,ind_digits)>0)      return LINE_STATE_ABOVE;//--- The line crossed the level upwards (value1<=level && value0>level0)   if(NormalizeDouble(value1-level,ind_digits)<=0 && NormalizeDouble(value0-level0,ind_digits)>0)      return LINE_STATE_CROSS_UP;//--- The line crossed the level downwards (value1>=level && value0<level0)   if(NormalizeDouble(value1-level,ind_digits)>=0 && NormalizeDouble(value0-level0,ind_digits)<0)      return LINE_STATE_CROSS_DOWN;//--- The line touched the level from below (value1<level0 && value0==level0)   if(NormalizeDouble(value1-level,ind_digits)<0 && NormalizeDouble(value0-level0,ind_digits)==0)      return LINE_STATE_TOUCH_BELOW;//--- The line touched the level from above (value1>level0 && value0==level0)   if(NormalizeDouble(value1-level,ind_digits)>0 && NormalizeDouble(value0-level0,ind_digits)==0)      return LINE_STATE_TOUCH_BELOW;//--- Line is equal to the level value (value1==level0 && value0==level0)   if(NormalizeDouble(value1-level,ind_digits)==0 && NormalizeDouble(value0-level0,ind_digits)==0)      return LINE_STATE_EQUALS;//--- Undefined state   return LINE_STATE_NONE;  }//+------------------------------------------------------------------+//| Return the indicator line state description                      |//+------------------------------------------------------------------+string LineStateDescription(const ENUM_LINE_STATE state)  {   switch(state)     {      case LINE_STATE_UP         :  return "Up";      case LINE_STATE_STOP_UP    :  return "Stop Up";      case LINE_STATE_TURN_UP    :  return "Turn Up";      case LINE_STATE_DOWN       :  return "Down";      case LINE_STATE_STOP_DOWN  :  return "Stop Down";      case LINE_STATE_TURN_DOWN  :  return "Turn Down";      case LINE_STATE_ABOVE      :  return "Above level";      case LINE_STATE_UNDER      :  return "Under level";      case LINE_STATE_CROSS_UP   :  return "Crossing Up";      case LINE_STATE_CROSS_DOWN :  return "Crossing Down";      case LINE_STATE_TOUCH_BELOW:  return "Touch from Below";      case LINE_STATE_TOUCH_ABOVE:  return "Touch from Above";      case LINE_STATE_EQUALS     :  return "Equals";      default                    :  return "Unknown";     }  }
""
还没有人打赏,支持一下

评论|共 1 个

兔斯基_5912

发表于 2024-4-23 16:53:18 | 显示全部楼层

写得好

您需要登录后才可以回帖 登录 | 注册 微信登录

EA之家评论守则