-
– 支持三种平滑处理方法:简单、指数或TEMA(三重指数移动平均线)。
-
– 支持跨时间周期(MTF)操作。
-
– 提供基于两种信号类型的提醒功能。
-
– 时段(默认 = 14):旋涡指标的计算周期。
-
– 平滑(默认 = 0):平滑处理的时段长度,0 表示无平滑。
-
– TypeSmoothing(默认 = 简单):平滑类型,可选简单、指数或TEMA。
-
– 时间周期(默认 = 当前):用于显示旋涡线的时间周期。
-
– 提醒类型(默认 = 两种信号都发送提醒):选择交叉提醒或逆转提醒。
-
– 提醒蜡烛图(默认 = 前一个):发出提醒的蜡烛图。
-
– 显示提醒(默认 = false)、发送邮件(默认 = false)、发送通知(默认 = false):MetaTrader平台的提醒设置。
-
//| Vortex Ultimate |
//| Copyright © 2009-2024, http://www.QChaos.com |
//| https://www.qchaos.com/ |
//+——————————————————————+
#property copyright “Copyright © 量化混沌, http://www.qchaos.com”
#property link “https://www.qchaos.com”
#property version “2.00”
#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 “A classic Vortex indicator with extra features:”
#property description ” * MTF support (higher timeframe data on a lower timeframe)”
#property description ” * Smoothing (simple, exponential, TEMA)”
#property description ” * Alert system (cross, reversal)”
#property indicator_separate_window
#property indicator_buffers 11 // Two actual output buffers, two buffers for smoothing, six additional buffers for TEMA smoothing, one buffer for MTF optimization.
#property indicator_color1 clrBlue
#property indicator_type1 DRAW_LINE
#property indicator_width1 2
#property indicator_label1 “VI+”
#property indicator_color2 clrRed
#property indicator_type2 DRAW_LINE
#property indicator_width2 2
#property indicator_label2 “VI-”
#property indicator_type3 DRAW_NONE
#property indicator_type4 DRAW_NONE
#property indicator_type5 DRAW_NONE
#property indicator_type6 DRAW_NONE
#property indicator_type7 DRAW_NONE
#property indicator_type8 DRAW_NONE
#property indicator_type9 DRAW_NONE
#property indicator_type10 DRAW_NONE
#property indicator_type11 DRAW_NONE
// Enumeration for alert candle:
enum ENUM_ALERT_CANDLE
{
ALERT_PREVIOUS_CANDLE, // Previous
ALERT_CURRENT_CANDLE // Current
};
// Enumeration for smoothing types:
enum ENUM_SMOOTHING_TYPE
{
SMOOTHING_SIMPLE, // Simple
SMOOTHING_EXPONENTIAL, // Exponential
SMOOTHING_TEMA // Triple exponential (slowest)
};
// Enumeration for alert types:
enum ENUM_ALERT_TYPE
{
ALERT_TYPE_CROSS, // Alert when VI+ crosses VI-
ALERT_TYPE_REVERSAL, // Alert when VI+ and VI- reverse
ALERT_TYPE_BOTH // Alert on both signals
};
// For reversal alerts. Can be either widening, neutral, or tightening.
enum ENUM_REVERSAL_STATE
{
REVERSAL_STATE_NEUTRAL, // Neutral
REVERSAL_STATE_WIDENING, // Widening
REVERSAL_STATE_TIGHTENING // Tightening
};
input int IndPeriod = 14; // Period
input int Smoothing = 0;
input ENUM_SMOOTHING_TYPE TypeSmoothing = SMOOTHING_SIMPLE;
input ENUM_TIMEFRAMES InpTimeframe = PERIOD_CURRENT; // Timeframe
input ENUM_ALERT_TYPE AlertType = ALERT_TYPE_BOTH; // Alert Type
input ENUM_ALERT_CANDLE AlertCandle = ALERT_PREVIOUS_CANDLE; // Alert Candle
input bool IsShowAlert = false; // Show Alert
input bool IsSendEmail = false; // Send Email
input bool IsSendNotification = false; // Send Notification
// Buffers:
double PlusVI[]; // VI+: Vortex Indicator+
double MinusVI[]; // VI-: Vortex Indicator-
double prePlusVI[]; // Pre-Smoothed Vortex Indicator+ when smoothing is enabled.
double preMinusVI[]; // Pre-Smoothed Vortex Indicator- when smoothing is enabled.
double TEMA_1_PlusVI[]; // First pass of exponentiation for TEMA smoothing for VI+.
double TEMA_1_MinusVI[]; // First pass of exponentiation for TEMA smoothing for VI-.
double TEMA_2_PlusVI[]; // Second pass of exponentiation for TEMA smoothing for VI+.
double TEMA_2_MinusVI[]; // Second pass of exponentiation for TEMA smoothing for VI-.
double TEMA_3_PlusVI[]; // Third pass of exponentiation for TEMA smoothing for VI+.
double TEMA_3_MinusVI[]; // Third pass of exponentiation for TEMA smoothing for VI-.
double UpperTFShift[]; // Buffer to store upper timeframe bar numbers for quick access.
ENUM_TIMEFRAMES Timeframe; // Timeframe of operation.
int deltaHighTF; // Difference in candles count from the higher timeframe.
// Global variables:
int RatesTotal;
int PrevCalculated;
int UpperTimeframeCalculated;
bool IsBullishCrossing;
bool IsBearishCrossing;
bool IsBullishReversal;
bool IsBearishReversal;
string BullishCrossingAlertMessage;
string BearishCrossingAlertMessage;
string BullishReversalAlertMessage;
string BearishReversalAlertMessage;
string AlertPrefix;
double alpha;
ENUM_REVERSAL_STATE CurrentState = REVERSAL_STATE_NEUTRAL; // ‘Neutral’ is used for initialization only. Normally ‘Neutral’ state isn’t stored.
void OnInit()
{
IndicatorSetInteger(INDICATOR_DIGITS, 6);
string name = “Vortex Ultimate (” + IntegerToString(IndPeriod) + “) “;
if (Smoothing > 0)
{
string s_type = “”;
if (TypeSmoothing == SMOOTHING_SIMPLE)
{
s_type = “Simple”;
}
else
{
if (TypeSmoothing == SMOOTHING_EXPONENTIAL) s_type = “Exponential”;
else if (TypeSmoothing == SMOOTHING_TEMA) s_type = “TEMA”;
alpha = 2.0 / (Smoothing + 1.0);
}
name += “Smoothed (” + s_type + “, ” + IntegerToString(Smoothing) + “) “;
}
SetIndexBuffer(0, PlusVI, INDICATOR_DATA);
SetIndexBuffer(1, MinusVI, INDICATOR_DATA);
SetIndexBuffer(2, prePlusVI, INDICATOR_DATA);
SetIndexBuffer(3, preMinusVI, INDICATOR_DATA);
SetIndexBuffer(4, TEMA_1_PlusVI, INDICATOR_DATA);
SetIndexBuffer(5, TEMA_1_MinusVI, INDICATOR_DATA);
SetIndexBuffer(6, TEMA_2_PlusVI, INDICATOR_DATA);
SetIndexBuffer(7, TEMA_2_MinusVI, INDICATOR_DATA);
SetIndexBuffer(8, TEMA_3_PlusVI, INDICATOR_DATA);
SetIndexBuffer(9, TEMA_3_MinusVI, INDICATOR_DATA);
SetIndexBuffer(10, UpperTFShift, INDICATOR_DATA);
PlotIndexSetInteger(0, PLOT_DRAW_BEGIN, IndPeriod + Smoothing);
PlotIndexSetDouble(0, PLOT_EMPTY_VALUE, EMPTY_VALUE);
PlotIndexSetInteger(1, PLOT_DRAW_BEGIN, IndPeriod + Smoothing);
PlotIndexSetDouble(1, PLOT_EMPTY_VALUE, EMPTY_VALUE);
ArraySetAsSeries(PlusVI, false);
ArraySetAsSeries(MinusVI, false);
ArraySetAsSeries(prePlusVI, false);
ArraySetAsSeries(preMinusVI, false);
ArraySetAsSeries(TEMA_1_PlusVI, false);
ArraySetAsSeries(TEMA_1_MinusVI, false);
ArraySetAsSeries(TEMA_2_PlusVI, false);
ArraySetAsSeries(TEMA_2_MinusVI, false);
ArraySetAsSeries(TEMA_3_PlusVI, false);
ArraySetAsSeries(TEMA_3_MinusVI, false);
ArraySetAsSeries(UpperTFShift, false);
// Initializing global variables:
IsBullishCrossing = false;
IsBearishCrossing = false;
IsBearishReversal = false;
IsBearishCrossing = false;
BullishCrossingAlertMessage = ” Bullish Crossing”;
BearishCrossingAlertMessage = ” Bearish Crossing”;
BullishReversalAlertMessage = ” Bullish Reversal”;
BearishReversalAlertMessage = ” Bearish Reversal”;
RatesTotal = 0;
PrevCalculated = 0;
UpperTimeframeCalculated = 0;
// Setting values for the higher timeframe:
Timeframe = InpTimeframe;
if (InpTimeframe < Period())
{
Timeframe = (ENUM_TIMEFRAMES)Period();
}
else if (InpTimeframe > Period())
{
name += ” @ ” + EnumToString(Timeframe);
StringReplace(name, “PERIOD_”, “”);
}
IndicatorSetString(INDICATOR_SHORTNAME, name);
AlertPrefix = _Symbol + ” @ ” + EnumToString((ENUM_TIMEFRAMES)_Period);
if (Timeframe != Period()) AlertPrefix += ” (” + EnumToString(Timeframe) + “) “;
StringReplace(AlertPrefix, “PERIOD_”, “”);
deltaHighTF = 0;
if (Timeframe > Period())
{
deltaHighTF = Timeframe / Period();
}
}