ZigZagOnParabolic 是一款适用于 MetaTrader 4 和 MetaTrader 5 的指标,结合了 ZigZag 和抛物线转向指标(Parabolic SAR),旨在改进传统 ZigZag 指标,通过更精确的图表极值标记和减少延迟来提升性能。传统 ZigZag 通过监测价格相对前一个极值的偏差百分比来识别新极值,而新版本的 ZigZagOnParabolic 则结合了抛物线转向指标的优势,使极值的捕捉更加可靠。该指标在 MetaTrader 平台上绘制 ZigZag 和抛物线转向线,方便用户识别关键价格点。
输入参数
- -步长 (默认 = 0.02):抛物线转向指标的标准参数之一。
- -最大值 (默认 = 0.2):抛物线转向指标的另一参数。
- – ExtremumsShift (默认 = 图表时间):控制极值显示的位置。如果设为图表时间,极值会显示在价格达到的实际位置;若设为检测时间,极值会显示在被检测到的时间点,可以用于观察检测延迟。
- -历史 (默认 = 0):用于计算的 K 线数量。如果性能出现问题,可设为非零值来减少计算量;0 表示所有 K 线都会用于计算。
- -EnableNativeAlerts (默认 = false):如设为 true,当检测到新的极值时会弹出 MetaTrader 提醒。
- -EnableEmailAlerts (默认 = false):如设为 true,当检测到新的极值时会发送邮件通知(需在 MetaTrader 中正确配置邮件设置)。
- -EnablePushAlerts (默认 = false):如设为 true,当检测到新的极值时会发送推送通知(需在 MetaTrader 中正确配置通知设置)。
图表中的 ZigZagOnParabolic 示例展示了 ExtremumsShift 参数设为图表时间的情况,极值与实际高低点一致。虽然 ZigZag 指标通常不用于生成直接交易信号,但它可以作为最大值和最小值的参考点来开仓。同时,它在构建通道、支撑位、阻力位等方面有重要用途,还能为其他图表形态提供参考。
下图例图中,ExtremumsShift 参数设为检测时间,这导致极值标记稍有延迟,与抛物线转向指标的反转保持一致。这样可以更好地反映指标识别信号的时间特性。
部分代码展示
//+------------------------------------------------------------------+
//| ZigZag on Parabolic |
//| Copyright © 2009-2022, www.QChaos.com |
//| https://www.qchaos.com/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2009-2024, www.qchaos.com"
#property link "https://www.qchaos.com"
#property version "1.03"
#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 indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 clrAqua
#property indicator_type1 DRAW_ZIGZAG
#property indicator_label1 "Peak"
#property indicator_color2 clrAqua
#property indicator_type2 DRAW_ZIGZAG
#property indicator_label2 "Trough"
#property indicator_color3 clrBlue
#property indicator_type3 DRAW_ARROW
#property indicator_label3 "SAR"
enum enum_extremum_position
{
DetectionTime, // Detection time
ChartTime // Chart time
};
input double Step = 0.02;
input double Maximum = 0.2;
input enum_extremum_position ExtremumsShift = ChartTime;
input int History = 0; // History: number of bars to look at. 0 - all.
input bool EnableNativeAlerts = false;
input bool EnableEmailAlerts = false;
input bool EnablePushAlerts = false;
double ZigUp[],
ZigDn[],
SAR[];
void OnInit()
{
SetIndexBuffer(0, ZigUp);
SetIndexEmptyValue(0, 0);
SetIndexBuffer(1, ZigDn);
SetIndexEmptyValue(1, 0);
SetIndexBuffer(2, SAR);
SetIndexArrow(2, 159);
SetIndexEmptyValue(2, 0);
}
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[])
{
static int j = 0; // Counter for the shift between the extremum detection and it's position.
static bool dir = false; // Direction: false - down, true - up.
static double h = -DBL_MAX, l = DBL_MAX; // Current extremums.
if (prev_calculated == 0) // Recalculating everything from the beginning.
{
j = 0;
dir = false;
h = -DBL_MAX;
l = DBL_MAX;
}
int counted_bars = IndicatorCounted();
int limit = Bars - counted_bars;
if (limit == Bars) limit -= 2; // Need a previous value too.
if ((History != 0) && (limit > History)) limit = History - 1; // Normalizing with the History input parameter./