如何在多个时间范围内搜索烛形图 [英] How to search for a candlestick pattern on multiple timeframes

查看:71
本文介绍了如何在多个时间范围内搜索烛形图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个专家顾问,他在一个特别定义的看跌Pinbar上绘制矩形,然后看涨蜡烛.请参见下面的代码.它基本上在图表上显示的时间范围内显示矩形.

I have an expert advisor that draws rectangle on a specifically defined bearish pinbar followed by a bullish candle. Please see the code below. It basically shows the rectangle on the timeframe displayed on the chart.

如何在H1烛台直至M2内的时间范围内搜索该烛形模式,以便可以从所有时间帧中筛选出具有最长看跌针形的模式?

How can I search for this candlestick pattern on timeframes within an H1 candlestick down to M2 in such a way that I can filter the pattern that has the longest bearish pinbar from all timeframes?

string prefix="PBar";
int magicnumber = 12345;

bool drawBearPinbarRectangle(int candleInt,const double top,const double bottom, ENUM_TIMEFRAMES cDuration, color rectColor)
{ 
     bool checkBarCount = true;
     int useCurrDuration = PeriodSeconds(cDuration)/PeriodSeconds();   

    const datetime starts = iTime(_Symbol,_Period,candleInt);

    const datetime ends = starts + useCurrDuration*PeriodSeconds();
    const string name=prefix+"_"+"_"+TimeToString(starts)+TimeToString(ends);
    if(!ObjectCreate(0,name,OBJ_RECTANGLE,0,starts ,top, ends, bottom))
    {
        return false;
    }


   ObjectSetInteger(0,name,OBJPROP_COLOR, rectColor);

   ObjectSetInteger(0,name,OBJPROP_STYLE, STYLE_DASHDOT);

   ObjectSetInteger(0,name,OBJPROP_WIDTH,1);

   ObjectSetInteger(0,name,OBJPROP_FILL, true);

    return true;
}

bool isBearPinBarType(int candleInt, ENUM_TIMEFRAMES cDuration, double maxLowerWickSize, double maxBodySize)  {

   if (iOpen(  _Symbol, cDuration, candleInt ) > iClose( _Symbol, cDuration, candleInt )) {

   double upperWick = iHigh(  _Symbol, cDuration, candleInt ) - iOpen( _Symbol, cDuration, candleInt );
   double body = iOpen(  _Symbol, cDuration, candleInt ) - iClose( _Symbol, cDuration, candleInt );
   double lowerWick = iClose(  _Symbol, cDuration, candleInt ) - iLow( _Symbol, cDuration, candleInt );

   double totalCandle = upperWick + body + lowerWick;

   if (((lowerWick > 0.0) && (lowerWick <= totalCandle*maxLowerWickSize)) && ((body > 0.0) && (body <= totalCandle*maxBodySize)))
      return true;

   return false; 

   }

   else
      return false;
}


bool isBullPinBarType(int candleInt, ENUM_TIMEFRAMES cDuration, double maxLowerWickSize, double maxBodySize)  {

   if ((iHigh(  _Symbol, cDuration, candleInt ) - iClose( _Symbol, cDuration, candleInt )) > 0) {

   double upperWick = iHigh(  _Symbol, cDuration, candleInt ) - iOpen( _Symbol, cDuration, candleInt );
   double body = iOpen(  _Symbol, cDuration, candleInt ) - iClose( _Symbol, cDuration, candleInt );
   double lowerWick = iClose(  _Symbol, cDuration, candleInt ) - iLow( _Symbol, cDuration, candleInt );

   double totalCandle = upperWick + body + lowerWick;

   if (((lowerWick > 0.0) && (lowerWick <= totalCandle*maxLowerWickSize)) && ((body > 0.0) && (body <= totalCandle*maxBodySize)))
      return true;

   return false; 

   }

   else
      return false;
}

void showPinbarRectOnDispTime() {


    for (int i=NumOfDisplayBars;i>=1;i--)   {

      double barOpen = iOpen(_Symbol,0,i + 1);
       double barHigh = iHigh(_Symbol,0,i + 1);


     if (isBearPinBarType(i + 2, 0, 0.15, 0.3)
      && 
    (iOpen(_Symbol,0,i + 1) < iClose(_Symbol,0,i + 1))) {

      drawBearPinbarRectangle(i +2,iHigh(_Symbol,0,i + 2),iLow(_Symbol,0,i + 2), 0, clrCyan);


      }
   }

}

bool isBearPinBarWithOpenAndClose(int numCandle, ENUM_TIMEFRAMES cDuration, double maxLowerWickSize, double maxBodySize,
double candleOpen, double candleHigh)  {



   if ((NormalizeDouble((iOpen(  _Symbol, cDuration, numCandle)), 2) == NormalizeDouble(candleOpen, 2)) && 
   (NormalizeDouble((iHigh(  _Symbol, cDuration, numCandle)), 2) == NormalizeDouble(candleHigh, 2)) && 
   ((iHigh(  _Symbol, cDuration, numCandle ) - iClose( _Symbol, cDuration, numCandle )) > 0)) {

   double upperWick = iHigh(  _Symbol, cDuration, numCandle ) - iOpen( _Symbol, cDuration, numCandle );
   double body = iOpen(  _Symbol, cDuration, numCandle ) - iClose( _Symbol, cDuration, numCandle );
   double lowerWick = iClose(  _Symbol, cDuration, numCandle ) - iLow( _Symbol, cDuration, numCandle );

   double totalCandle = upperWick + body + lowerWick;

   if (((lowerWick > 0.0) && (lowerWick <= totalCandle*maxLowerWickSize)) && ((body > 0.0) && (body <= totalCandle*maxBodySize)))
      return true;

   return false; 

   }

   else
      return false;


}

void OnDeinit(const int reason){ObjectsDeleteAll(0,prefix);}


void OnTick()
{



     showPinbarRectOnDispTime();

}

推荐答案

  1. 声明所有必要的时间范围ENUM_TIMEFRAMES tfs[];
  2. 将其填充到OnInit()中,然后遍历值:for(int i=ArraySize(tfs)-1;i>=0;i--){showPinbarRectOnDispTime(tfs[i]);};
  3. 编辑showPinbarRectOnDispTime(ENUM_TIMEFRAMES tf)函数:double barOpen = iOpen(_Symbol,tf,i + 1);,依此类推;
  4. 考虑是否只需要绘制针形矩形或以某种方式消耗该数据而无需绘制.
  1. declare all the necessary timeframes ENUM_TIMEFRAMES tfs[];
  2. fill it in OnInit() then loop over values: for(int i=ArraySize(tfs)-1;i>=0;i--){showPinbarRectOnDispTime(tfs[i]);};
  3. edit the showPinbarRectOnDispTime(ENUM_TIMEFRAMES tf) function: double barOpen = iOpen(_Symbol,tf,i + 1); and so on;
  4. think whether you need just to draw the pin bar rectangles or somehow consume that data without drawing.

这篇关于如何在多个时间范围内搜索烛形图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆