WRB Hidden Gap MetaTrader 指标用于检测和标记宽范围的柱体(非常长的柱体)或宽范围的烛身(具有非常长实体的阴阳烛)。此指标可以识别WRB中的隐藏跳空,并区分显示已填补和未填补的隐藏跳空,方便用户一眼识别当前市场状态。当价格首次进入未填补的隐藏跳空或出现新的WRB或隐藏跳空时,用户可选择启用提醒功能。此指标适用于MT4和MT5平台。
输入参数说明:
- Timeframe(默认为 PERIOD_CURRENT): 计算宽幅区间K线(WRB)和隐藏跳空(HG)的时间周期,不能低于当前周期。
- UseWholeBars(默认为 false): 若设置为true,则指标寻找宽范围的柱体而非烛身。
- WRB_LookBackBarCount(默认为 3): 在比较WRB时考虑的历史柱体数量。
- WRB_WingDingsSymbol(默认为 115): 标记WRB的符号,默认为小钻石。
- HGcolor:设置各类型隐藏跳空的颜色,包括看涨看跌、已突破和未突破的状态。
- HGstyle(默认为 STYLE_SOLID): 隐藏跳空矩形的线型。
- StartCalculationFromBar(默认为 100): 回顾期内标记宽范围烛身和隐藏跳空的柱体数量。
- HollowBoxes(默认为 false): 若为true,则标记的隐藏跳空矩形为未填充的。
- AlertBreachesFromBelow(默认为 true)、AlertBreachesFromAbove(默认为 true)、AlertHG(默认为 false)、AlertWRB(默认为 false)、AlertHGFill(默认为 false): 各类型提醒的启用设置。
- EnableNativeAlerts(默认为 false)、EnableEmailAlerts(默认为 false)、EnablePushAlerts(默认为 false): 提醒的发送方式,需要在MetaTrader设置邮件和通知。
- ObjectPrefix(默认为 "HG_"): 图表对象的前缀,以便与其他指标兼容。
示例:在EUR/USD日线图表上使用默认设置标记的隐藏跳空。宽范围烛身的WRB条形图内绘制红色菱形框,不同颜色的矩形用于绘制隐藏跳空。未填充的缺口以跨至图表右边缘的矩形显示。此指标不生成交易信号,仅提供价格行为信息,辅助交易者利用其他策略生成的进场和离场信号。隐藏跳空也可作为支撑/阻力区域或价格缺口使用。
部分代码展示
//+------------------------------------------------------------------+
//| WRB-Hidden-Gap.mq4 |
//| Copyright © 2009-2024, www.QChaos.com |
//| https://www.qchaos.com/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 量化混沌, www.qchaos.com"
#property link "https://www.qchaos.com"
#property version "1.05"
#property strict
#property description "---------------------------------------------"
#property description "EA、指标公式分享"
#property description "EA、指标编写业务承接"
#property description "---------------------------------------------"
#property description "更多资源,关注公众号:量化程序"
#property description "微 信:QChaos001"
#property description "手机号:134-8068-5281"
#property description "---------------------------------------------"
#property description "Identifies Wide Range Bars and Hidden Gaps. Supports MTF."
#property description "WRB and HG definitions are taken from the WRB Analysis Tutorial-1"
#property description "by M.A.Perry from TheStrategyLab.com."
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 clrRed
#property indicator_type1 DRAW_ARROW
#property indicator_label1 "WRB"
#property indicator_width1 3
input ENUM_TIMEFRAMES Timeframe = PERIOD_CURRENT;
input bool UseWholeBars = false;
input int WRB_LookBackBarCount = 3;
input int WRB_WingDingsSymbol = 115;
input color HGcolorNormalBullishUnbreached = clrDodgerBlue;
input color HGcolorIntersectionBullishUnbreached = clrBlue;
input color HGcolorNormalBearishUnbreached = clrIndianRed;
input color HGcolorIntersectionBearishUnbreached = clrRed;
input color HGcolorNormalBullishBreached = clrPowderBlue;
input color HGcolorIntersectionBullishBreached = clrSlateBlue;
input color HGcolorNormalBearishBreached = clrLightCoral;
input color HGcolorIntersectionBearishBreached = clrSalmon;
input ENUM_LINE_STYLE HGstyle = STYLE_SOLID;
input int StartCalculationFromBar = 100;
input bool HollowBoxes = false;
input bool AlertBreachesFromBelow = true;
input bool AlertBreachesFromAbove = true;
input bool AlertHG = false;
input bool AlertWRB = false;
input bool AlertHGFill = false;
input bool EnableNativeAlerts = false;
input bool EnableEmailAlerts = false;
input bool EnablePushAlerts = false;
input string ObjectPrefix = "HG_";
double WRB[];
int totalBarCount = -1;
bool DoAlerts = false;
datetime AlertTimeWRB = 0, AlertTimeHG = 0;
string UnfilledPrefix, FilledPrefix;
int OnInit()
{
if (PeriodSeconds(Timeframe) < PeriodSeconds())
{
Alert("The Timeframe input parameter should be higher or equal to the current timeframe. Switching to current timeframe.");
}
IndicatorShortName("WRB+HG");
SetIndexArrow(0, WRB_WingDingsSymbol);
SetIndexBuffer(0, WRB);
UnfilledPrefix = ObjectPrefix + "UNFILLED_";
FilledPrefix = ObjectPrefix + "FILLED_";
if ((EnableNativeAlerts) || (EnableEmailAlerts) || (EnablePushAlerts)) DoAlerts = true;
return INIT_SUCCEEDED;
}
//+------------------------------------------------------------------+
//| Intersect: Checks whether two bars intersect or not. |
//| Return codes are unused. 0 - no intersection. |
//+------------------------------------------------------------------+
int intersect(double H1, double L1, double H2, double L2)
{
if ((L1 > H2) || (H1 < L2)) return 0;
if ((H1 >= H2) && (L1 >= L2)) return 1;
if ((H1 <= H2) && (L1 <= L2)) return 2;
if ((H1 >= H2) && (L1 <= L2)) return 3;
if ((H1 <= H2) && (L1 >= L2)) return 4;
return 0;
}
//+------------------------------------------------------------------+
//| checkHGFilled: Checks if the hidden gap is filled or not. |
//+------------------------------------------------------------------+
void checkHGFilled(int barNumber)
{
string Prefix = UnfilledPrefix;
int L = StringLen(Prefix);
int obj_total = ObjectsTotal(ChartID(), 0, OBJ_RECTANGLE);
// Loop over all unfilled boxes.
for (int i = 0; i < obj_total; i++)
{
string ObjName = ObjectName(0, i, 0, OBJ_RECTANGLE);
if (StringSubstr(ObjName, 0, L) != Prefix) continue;
// Get HG high and low values.
double box_H = ObjectGet(ObjName, OBJPROP_PRICE1);
double box_L = ObjectGet(ObjName, OBJPROP_PRICE2);
color objectColor = (color)ObjectGet(ObjName, OBJPROP_COLOR);
datetime startTime = (datetime)ObjectGet(ObjName, OBJPROP_TIME1);
double HGFillPA_H = High[barNumber];
double HGFillPA_L = Low[barNumber];
if ((HGFillPA_H > box_L) && (HGFillPA_L < box_H)) // Breach, but not necessarily filling.
{
// Only color should be updated.
if (objectColor == HGcolorNormalBullishUnbreached) objectColor = HGcolorNormalBullishBreached;
else if (objectColor == HGcolorIntersectionBullishUnbreached) objectColor = HGcolorIntersectionBullishBreached;
else if (objectColor == HGcolorNormalBearishUnbreached) objectColor = HGcolorNormalBearishBreached;
else if (objectColor == HGcolorIntersectionBearishUnbreached) objectColor = HGcolorIntersectionBearishBreached;
ObjectSetInteger(ChartID(), ObjName, OBJPROP_COLOR, objectColor);
}
int j = 0;
while ((intersect(High[barNumber + j], Low[barNumber + j], box_H, box_L) != 0) && (barNumber + j < Bars) && (startTime < Time[barNumber + j]))
{
if (High[barNumber + j] > HGFillPA_H) HGFillPA_H = High[barNumber + j];
if (Low[barNumber + j] < HGFillPA_L) HGFillPA_L = Low[barNumber + j];
if ((HGFillPA_H > box_H) && (HGFillPA_L < box_L))
{
ObjectDelete(ObjName);
string ObjectText = FilledPrefix + TimeToString(startTime, TIME_DATE | TIME_MINUTES); // Recreate as a filled box.
ObjectCreate(ObjectText, OBJ_RECTANGLE, 0, startTime, box_H, Time[barNumber], box_L);
ObjectSetInteger(ChartID(), ObjectText, OBJPROP_STYLE, HGstyle);
// Filled HG is necessarilly a breached one.
if (objectColor == HGcolorNormalBullishUnbreached) objectColor = HGcolorNormalBullishBreached;
else if (objectColor == HGcolorIntersectionBullishUnbreached) objectColor = HGcolorIntersectionBullishBreached;
else if (objectColor == HGcolorNormalBearishUnbreached) objectColor = HGcolorNormalBearishBreached;
else if (objectColor == HGcolorIntersectionBearishUnbreached) objectColor = HGcolorIntersectionBearishBreached;
ObjectSetInteger(ChartID(), ObjectText, OBJPROP_COLOR, objectColor);
ObjectSetInteger(ChartID(), ObjectText, OBJPROP_BACK, !HollowBoxes);
if ((AlertHGFill) && (IndicatorCounted() > 0)) // Don't alert on old fillings.
{
string Text = "WRB Hidden Gap: " + Symbol() + " - " + StringSubstr(EnumToString((ENUM_TIMEFRAMES)Period()), 7) + " - HG " + TimeToString(startTime, TIME_DATE | TIME_MINUTES) + " Filled.";
if (EnableNativeAlerts) Alert(Text);
if (EnableEmailAlerts) SendMail("WRB HG Alert", Text);
if (EnablePushAlerts) SendNotification(Text);
}
break;
}
j++;
}
}
}