指标名称:交易动态指数
版本:MT4 ver. 1.08
交易动态指数(简称TDI)是一种综合性技术分析工具,广泛应用于市场趋势分析与交易决策。该指标结合了RSI(相对强弱指数)、移动平均线以及市场波动性,能够帮助交易者识别市场的超买、超卖状态、趋势反转点以及潜在的买卖信号。
主要功能:
- 趋势识别:通过动态计算的移动平均线(MA)与RSI的组合,TDI能够有效识别市场的趋势方向及其强度。
- 波动性分析:指标通过标准差(SD)计算出上下波动区间,结合RSI与MA线,提供了市场波动性的重要信息。
- 买卖信号:通过RSI与移动平均线的交叉情况,TDI生成潜在的买入和卖出信号。
使用方法
趋势确认:
- 当TDI的MA线(绿色线)位于上轨线(上方)时,市场处于上涨趋势中。
- 当MA线位于下轨线(下方)时,市场处于下跌趋势中。
- 当MA线穿越中轨线时,可能是趋势反转的信号。
买入信号:
- 当绿色MA线从下向上穿越红色信号线,且价格位于下轨线附近时,可能表示一个买入机会。
- RSI线从超卖区域(30以下)回升并突破中轨线时,也可视为买入信号。
卖出信号:
- 当绿色MA线从上向下穿越红色信号线,且价格位于上轨线附近时,可能表示一个卖出机会。
- RSI线从超买区域(70以上)回落并突破中轨线时,也可视为卖出信号。
超买/超卖区:
- RSI值大于70时,市场可能进入超买状态,警示价格过高,可能发生回调。
- RSI值小于30时,市场可能进入超卖状态,警示价格过低,可能发生反弹。
信号提醒:
- 红黄交叉警报:当信号线从下向上穿越中轨线时,产生买入信号;反之,当信号线从上向下穿越中轨线时,产生卖出信号。
- 钩形警报:当MA线突破上下轨线,并且两者的值位于高于或低于某一特定阈值时,系统会自动发出买入或卖出提醒。
参数:
部分代码展示:
//+——————————————————————+
//| 交易动态指数.mq4 |
//| 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 "1.08"
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 "显示趋势方向、强度和波动性。"
property description "绿色线 – RSI价格线。"
property description "红色线 – 交易信号线。"
property description "蓝色线 – 波动带。"
property description "黄色线 – 市场基础线。"
property indicator_separate_window // 指标显示在单独的窗口中
property indicator_buffers 6 // 定义使用6个缓冲区
property indicator_level1 32 // 第一条水平线,通常用于标识超卖区域
property indicator_level2 50 // 第二条水平线,表示中性线
property indicator_level3 68 // 第三条水平线,通常用于标识超买区域
property indicator_minimum 0 // 指标最小值
property indicator_maximum 100 // 指标最大值
property indicator_levelcolor clrDimGray // 水平线颜色:灰色
property indicator_levelstyle STYLE_DOT // 水平线样式:点线
property indicator_levelwidth 1 // 水平线宽度
property indicator_color1 clrNONE // 第一条线颜色:透明
property indicator_type1 DRAW_NONE // 第一条线类型:不绘制
property indicator_color2 clrMediumBlue // 第二条线颜色:中蓝色
property indicator_label2 "VB High" // 第二条线标签:VB高带
property indicator_type2 DRAW_LINE // 绘制线条
property indicator_color3 clrYellow // 第三条线颜色:黄色
property indicator_label3 "Market Base Line" // 第三条线标签:市场基础线
property indicator_type3 DRAW_LINE // 绘制线条
property indicator_width3 2 // 第三条线宽度
property indicator_color4 clrMediumBlue // 第四条线颜色:中蓝色
property indicator_label4 "VB Low" // 第四条线标签:VB低带
property indicator_type4 DRAW_LINE // 绘制线条
property indicator_color5 clrGreen // 第五条线颜色:绿色
property indicator_label5 "RSI Price Line" // 第五条线标签:RSI价格线
property indicator_type5 DRAW_LINE // 绘制线条
property indicator_width5 2 // 第五条线宽度
property indicator_color6 clrRed // 第六条线颜色:红色
property indicator_label6 "Trade Signal Line" // 第六条线标签:交易信号线
property indicator_type6 DRAW_LINE // 绘制线条
property indicator_width6 2 // 第六条线宽度
enum enum_arrow_type
{
Buy, // 买入信号
Sell // 卖出信号
};
enum enum_candle_to_check
{
Current, // 当前蜡烛
Previous // 前一个蜡烛
};
// 输入参数部分,以下是各个参数的说明:
input string Main = ""; // 主标题,通常用于注释或描述
input int RSI_Period = 13; // RSI周期:通常设置为8到25,表示RSI计算的天数
input ENUM_APPLIED_PRICE RSI_Price = PRICE_CLOSE; // RSI计算所应用的价格:使用收盘价
input int Volatility_Band = 34; // 波动性带宽:设置为20到40,表示计算波动性时的区间
input double StdDev = 1.6185; // 标准偏差:常用值为1到3,用于计算波动性带的宽度
input int RSI_Price_Line = 2; // RSI价格线周期,通常设置为2
input ENUM_MA_METHOD RSI_Price_Type = MODE_SMA; // RSI价格线的移动平均方法,通常使用简单移动平均(SMA)
input int Trade_Signal_Line = 7; // 交易信号线周期:通常设置为7,用于生成交易信号
input ENUM_MA_METHOD Trade_Signal_Type = MODE_SMA; // 交易信号线的移动平均方法,通常使用SMA
input ENUM_TIMEFRAMES UpperTimeframe = PERIOD_CURRENT; // 上层时间框架:如果高于当前时间框架,将显示来自该时间框架的值
input string Alerts = ""; // 提示框主标题,通常用于描述警报设置
input bool EnableNativeAlerts = false; // 启用原生警报:启用或禁用平台自带的警报
input bool EnableEmailAlerts = false; // 启用电子邮件警报:启用或禁用通过电子邮件发送警报
input bool EnablePushAlerts = false; // 启用推送警报:启用或禁用通过手机推送警报
input bool EnableArrowAlerts = false; // 启用箭头警报:启用或禁用箭头提示信号
input bool EnableRedYellowCrossAlert = true; // 启用红黄交叉警报:启用或禁用黄色和红色线条的交叉警报
input bool EnableHookAlert = false; // 启用钩形警报:启用或禁用绿色线的钩形警报
input bool EnableGreenRedCrossAlert = false; // 启用绿红交叉警报:启用或禁用绿色和红色线条的交叉警报
input bool EnableYellowGreenCrossAlert = false; // 启用黄绿交叉警报:启用或禁用黄色和绿色线条的交叉警报
input enum_candle_to_check TriggerCandle = Previous; // 触发信号的蜡烛:当前蜡烛或前一个蜡烛
input string ____Arrows = ""; // 箭头提示框标题,通常用于描述箭头设置
input color RedYellowCrossArrowBullishColor = clrGreen; // 红黄交叉箭头买入信号的颜色:绿色
input color RedYellowCrossArrowBearishColor = clrRed; // 红黄交叉箭头卖出信号的颜色:红色
input color HookArrowBullishColor = clrGreen; // 钩形箭头买入信号的颜色:绿色
input color HookArrowBearishColor = clrRed; // 钩形箭头卖出信号的颜色:红色
input color GreenRedCrossArrowBullishColor = clrGreen; // 绿红交叉箭头买入信号的颜色:绿色
input color GreenRedCrossArrowBearishColor = clrRed; // 绿红交叉箭头卖出信号的颜色:红色
input color YellowGreenCrossArrowBullishColor = clrGreen; // 黄绿交叉箭头买入信号的颜色:绿色
input color YellowGreenCrossArrowBearishColor = clrRed; // 黄绿交叉箭头卖出信号的颜色:红色
input uchar RedYellowCrossArrowBullishCode = 233; // 红黄交叉箭头买入信号的ASCII码:233
input uchar RedYellowCrossArrowBearishCode = 234; // 红黄交叉箭头卖出信号的ASCII码:234
input uchar HookArrowBullishCode = 71; // 钩形箭头买入信号的ASCII码:71
input uchar HookArrowBearishCode = 72; // 钩形箭头卖出信号的ASCII码:72
input uchar GreenRedCrossArrowBullishCode = 200; // 绿红交叉箭头买入信号的ASCII码:200
input uchar GreenRedCrossArrowBearishCode = 201; // 绿红交叉箭头卖出信号的ASCII码:201
input uchar YellowGreenCrossArrowBullishCode = 226; // 黄绿交叉箭头买入信号的ASCII码:226
input uchar YellowGreenCrossArrowBearishCode = 225; // 黄绿交叉箭头卖出信号的ASCII码:225
input int ArrowSize = 1; // 箭头大小:默认值为1
input string ArrowPrefix = "TDI-"; // 箭头前缀:默认值为"TDI-"
double RSIBuf[], UpZone[], MdZone[], DnZone[], MaBuf[], MbBuf[];
double _RSIBuf[], _UpZone[], _MdZone[], _DnZone[], _MaBuf[], _MbBuf[]; // For upper timeframe data.
datetime AlertPlayed = 0, HookAlertPlayed = 0, RedGreenAlertPlayed = 0, YellowGreenAlertPlayed = 0;
//+——————————————————————+
//| |
//+——————————————————————+
int OnInit()
{
if(PeriodSeconds(UpperTimeframe) < PeriodSeconds())
{
Print("Upper timeframe cannot be lower than the current timeframe.");
return INIT_PARAMETERS_INCORRECT;
}
IndicatorShortName("TDI (" + IntegerToString(RSI_Period) + ", " + IntegerToString(Volatility_Band) + ", " + IntegerToString(RSI_Price_Line) + ", " + IntegerToString(Trade_Signal_Line) + ")");
SetIndexBuffer(0, RSIBuf);
SetIndexBuffer(1, UpZone);
SetIndexBuffer(2, MdZone);
SetIndexBuffer(3, DnZone);
SetIndexBuffer(4, MaBuf);
SetIndexBuffer(5, MbBuf);
if(UpperTimeframe != Period())
{
IndicatorBuffers(12);
SetIndexBuffer(6, _RSIBuf);
SetIndexBuffer(7, _UpZone);
SetIndexBuffer(8, _MdZone);
SetIndexBuffer(9, _DnZone);
SetIndexBuffer(10, _MaBuf);
SetIndexBuffer(11, _MbBuf);
}
IndicatorDigits(1);
return INIT_SUCCEEDED;
}
//+——————————————————————+
//| |
//+——————————————————————+
void OnDeinit(const int reason)
{
ObjectsDeleteAll(ChartID(), ArrowPrefix, 0, OBJ_ARROW);
}
//+——————————————————————+
//| |
//+——————————————————————+