瓦解li 发表于 2017-5-10 16:51:39

如何实现线段端点的方向分类

我从另外个指标中引入线段端点,现在需要对线段端点进行方向分类并将分类结果计入一个二维数组中。为了测试以下代码的有效性,我增加了两个buffer,用来测试端点是不是正常分类。但是这段代码载入之后,图像没有任何反应,没有正常显示经过分类的端点。但如果将引用的未分类线段端点直接进行箭头输出,可以正常显示。请问该如何进行修改?

#property indicator_chart_window
#property indicator_buffers 2   //指标运用到数据列表的个数
#property indicator_color1Red//指标显示颜色
#property indicator_color2Green
double ExtHighBuffer[];   //高点的临时变量数组
double ExtLowBuffer[];   //低点的临时变量数组
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
{
//--- indicator buffers mapping


IndicatorBuffers(2);
//    SetIndexStyle(0,DRAW_SECTION); //定义第0号数组将会在图标上显示划线
//---- indicator buffers
//   SetIndexBuffer(0,ExtZigzagBuffer); //为数组进行排序和定义
SetIndexStyle(0,DRAW_ARROW,0,2); //定义第0号数组将会在图标上显示箭头
SetIndexStyle(1,DRAW_ARROW,0,2); //定义第1号数组将会在图标上显示箭头
SetIndexBuffer(0,ExtHighBuffer);
SetIndexBuffer(1,ExtLowBuffer);
   SetIndexEmptyValue(0,0.0);
   IndicatorShortName("LIDuan");   
//---
   return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
{
//---
   double startpoint,Point1;//endpoint;thispoint;
   int i;
   int limit;   
   int counted_bars=prev_calculated;
   double TPoint[];
   int TotalStroke;
   if(counted_bars<0) return(-1);
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;
   
   
   
//建立线段端点数据库
ArrayResize(TPoint,0);
TotalStroke = 0;

for(i=limit-1; i>=0; i--){


    startpoint = iCustom(NULL,0,"BoundTheoryLine",0,i);
if(startpoint==0.0){
      ExtLowBuffer=0.0;
      ExtHighBuffer=0.0;
      continue;}
//--------------------
    if(startpoint>0.0){
    TotalStroke++;
    ArrayResize(TPoint,TotalStroke);
    // Save information
    TPoint = i;
    TPoint = startpoint;

//进行线段端点的方向判断
    if(TotalStroke<2){continue;}
   if(TotalStroke>=2 || TPoint > TPoint)
    {TPoint = 0;
    TPoint = 1;}
    else{
    TPoint = 1;
    TPoint = 0;}
    if(TPoint == 0)
    ExtHighBuffer=startpoint;
    if(TPoint == 1)
    ExtLowBuffer=startpoint;

            
            }

}
   return(rates_total);
}


瓦解li 发表于 2017-5-10 17:06:23

问题已解决,分享代码

#property indicator_chart_window
#property indicator_buffers 2   //指标运用到数据列表的个数
#property indicator_color1Red//指标显示颜色
#property indicator_color2Green
double ExtHighBuffer[];   //高点的临时变量数组
double ExtLowBuffer[];   //低点的临时变量数组
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
{
//--- indicator buffers mapping


IndicatorBuffers(2);
//    SetIndexStyle(0,DRAW_SECTION); //定义第0号数组将会在图标上显示划线
//---- indicator buffers
//   SetIndexBuffer(0,ExtZigzagBuffer); //为数组进行排序和定义
SetIndexStyle(0,DRAW_ARROW,0,2); //定义第0号数组将会在图标上显示箭头
SetIndexStyle(1,DRAW_ARROW,0,2); //定义第1号数组将会在图标上显示箭头
SetIndexBuffer(0,ExtHighBuffer);
SetIndexBuffer(1,ExtLowBuffer);
   SetIndexEmptyValue(0,0.0);
   IndicatorShortName("LIDuan");   
//---
   return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
{
//---
   double startpoint,Point1;//endpoint;thispoint;
   int i;
   int limit;   
   int counted_bars=prev_calculated;
   double TPoint[];
   int TotalStroke;
   if(counted_bars<0) return(-1);
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;
   
   
   
//建立线段端点数据库
ArrayResize(TPoint,0);
TotalStroke = 0;

for(i=limit-1; i>=0; i--){


    startpoint = iCustom(NULL,0,"BoundTheoryLine",0,i);
if(startpoint==0.0){
      ExtLowBuffer=0.0;
      ExtHighBuffer=0.0;
      continue;}
//--------------------
    if(startpoint>0.0){
    TotalStroke++;
    ArrayResize(TPoint,TotalStroke);
    // Save information
    TPoint = i;
    TPoint = startpoint;

//进行线段端点的方向判断
    if(TotalStroke<2){continue;}
   
   if( TPoint > TPoint)
    {TPoint = 0;
    TPoint = 1;}
    else{
    TPoint = 1;
    TPoint = 0;}
   
   
    if(TPoint == 0)
    ExtHighBuffer=startpoint;

    if(TPoint == 1)
    ExtLowBuffer=startpoint;

            
            }

}
   return(rates_total);
}
页: [1]
查看完整版本: 如何实现线段端点的方向分类