如何在多个时间范围内搜索烛台形态
Posted
技术标签:
【中文标题】如何在多个时间范围内搜索烛台形态【英文标题】:How to search for a candlestick pattern on multiple timeframes 【发布时间】:2020-06-19 22:47:44 【问题描述】:我有一个专家顾问,它在特定定义的看跌 pinbar 上绘制矩形,然后是看涨蜡烛。请看下面的代码。它基本上在图表上显示的时间范围内显示矩形。
如何在 H1
烛台至 M2
的时间范围内搜索此烛台模式,以便我可以过滤所有时间范围内具有最长看跌 pinbar 的模式?
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[];
填入OnInit()
,然后循环遍历值:for(int i=ArraySize(tfs)-1;i>=0;i--)showPinbarRectOnDispTime(tfs[i]);
;
编辑showPinbarRectOnDispTime(ENUM_TIMEFRAMES tf)
函数:double barOpen = iOpen(_Symbol,tf,i + 1);
等;
想一想您是只需要绘制 pin bar 矩形,还是以某种方式在不绘制的情况下使用该数据。
【讨论】:
以上是关于如何在多个时间范围内搜索烛台形态的主要内容,如果未能解决你的问题,请参考以下文章