MT5指标编译通过 · EX5 11KB 25 18

EMA双均线金叉箭头指标

测试交易员·3 小时前发布

EMA20 金叉 EMA60 画箭头信号

EMA双均线金叉箭头指标
EMA_Cross_Arrow.mq5144
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#property copyright "XAUOF指标工坊"
#property version   "1.00"
#property strict
#property indicator_chart_window
#property indicator_buffers 4
#property indicator_plots   4

// 画线1:快速EMA

#property indicator_label1  "EMA快线"
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrDodgerBlue
#property indicator_width1  2

// 画线2:慢速EMA

#property indicator_label2  "EMA慢线"
#property indicator_type2   DRAW_LINE
#property indicator_color2  clrOrange
#property indicator_width2  2

// 画线3:上穿箭头

#property indicator_label3  "金叉"
#property indicator_type3   DRAW_ARROW
#property indicator_color3  clrLime
#property indicator_width3  3

// 画线4:下穿箭头

#property indicator_label4  "死叉"
#property indicator_type4   DRAW_ARROW
#property indicator_color4  clrRed
#property indicator_width4  3

//--- 可调参数

input int FastPeriod = 20;  // 快线周期(推荐 20)

input int SlowPeriod = 60;  // 慢线周期(推荐 60)


//--- 指标缓冲区

double FastBuffer[];   // 快线值

double SlowBuffer[];   // 慢线值

double UpArrow[];      // 上穿箭头

double DnArrow[];      // 下穿箭头


int fast_handle;       // 快线句柄

int slow_handle;       // 慢线句柄


//+------------------------------------------------------------------+

int OnInit()
{
   // 参数合法性检查

   if(FastPeriod <= 0 || SlowPeriod <= 0 || FastPeriod >= SlowPeriod)
   {
      Print("参数错误:快线周期必须小于慢线周期且均大于0");
      return(INIT_PARAMETERS_INCORRECT);
   }
   
   // 创建 EMA 句柄

   fast_handle = iMA(_Symbol, _Period, FastPeriod, 0, MODE_EMA, PRICE_CLOSE);
   slow_handle = iMA(_Symbol, _Period, SlowPeriod, 0, MODE_EMA, PRICE_CLOSE);
   
   if(fast_handle == INVALID_HANDLE || slow_handle == INVALID_HANDLE)
   {
      Print("创建均线句柄失败");
      return(INIT_FAILED);
   }
   
   // 绑定缓冲区

   SetIndexBuffer(0, FastBuffer, INDICATOR_DATA);
   SetIndexBuffer(1, SlowBuffer, INDICATOR_DATA);
   SetIndexBuffer(2, UpArrow, INDICATOR_DATA);
   SetIndexBuffer(3, DnArrow, INDICATOR_DATA);
   
   // 设置数组为时间序列(索引0为最新)

   ArraySetAsSeries(FastBuffer, true);
   ArraySetAsSeries(SlowBuffer, true);
   ArraySetAsSeries(UpArrow, true);
   ArraySetAsSeries(DnArrow, true);
   
   // 设置箭头符号(233=向上箭头,234=向下箭头)

   PlotIndexSetInteger(2, PLOT_ARROW, 233);
   PlotIndexSetInteger(3, PLOT_ARROW, 234);
   
   // 设置空值

   PlotIndexSetDouble(2, PLOT_EMPTY_VALUE, 0);
   PlotIndexSetDouble(3, PLOT_EMPTY_VALUE, 0);
   
   return(INIT_SUCCEEDED);
}

//+------------------------------------------------------------------+

void OnDeinit(const int reason)
{
   // 释放句柄

   if(fast_handle != INVALID_HANDLE) IndicatorRelease(fast_handle);
   if(slow_handle != INVALID_HANDLE) IndicatorRelease(slow_handle);
}

//+------------------------------------------------------------------+

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[])
{
   // 数据不足,不计算

   if(rates_total < SlowPeriod) return(0);
   
   // 设置价格数组为时间序列

   ArraySetAsSeries(high, true);
   ArraySetAsSeries(low, true);
   
   // 从指标句柄复制数据

   if(CopyBuffer(fast_handle, 0, 0, rates_total, FastBuffer) <= 0) return(0);
   if(CopyBuffer(slow_handle, 0, 0, rates_total, SlowBuffer) <= 0) return(0);
   
   // 确定计算起点

   int start = prev_calculated > 0 ? prev_calculated - 1 : SlowPeriod;
   if(start < 1) start = 1; // 至少从第1根开始(因为要判断前一根)

   
   // 逐根K线计算交叉信号

   for(int i = start; i < rates_total; i++)
   {
      // 清空箭头

      UpArrow[i] = 0;
      DnArrow[i] = 0;
      
      // 判断交叉:当前快线在慢线上方 且 前一根快线在慢线下方 = 上穿

      if(FastBuffer[i] > SlowBuffer[i] && FastBuffer[i-1] <= SlowBuffer[i-1])
      {
         UpArrow[i] = low[i] - 10 * _Point; // 画在K线下方

      }
      
      // 判断交叉:当前快线在慢线下方 且 前一根快线在慢线上方 = 下穿

      if(FastBuffer[i] < SlowBuffer[i] && FastBuffer[i-1] >= SlowBuffer[i-1])
      {
         DnArrow[i] = high[i] + 10 * _Point; // 画在K线上方

      }
   }
   
   return(rates_total);
}

作品说明

这是一个经典的双均线交叉指标。在主图上画出 EMA20(快线)和 EMA60(慢线),当快线上穿慢线时在 K 线下方标记绿色买入箭头,下穿时在 K 线上方标记红色卖出箭头。

使用说明

  1. 安装方法:将代码保存为 EMA_Cross_Arrow.mq5,放入 MT5 的 MQL5/Indicators 目录,在导航器中编译后拖到图表即可。
  1. 参数设置
  • 快线周期:默认 20,可根据交易风格调整(越小越灵敏)
  • 慢线周期:默认 60,通常是快线的 2-3 倍
  1. 信号解读
  • 绿色向上箭头:金叉信号(快线上穿慢线),看涨
  • 红色向下箭头:死叉信号(快线下穿慢线),看跌
  • 蓝色线:快速 EMA,反应灵敏
  • 橙色线:慢速 EMA,趋势参考
  1. 注意事项
  • 箭头只在交叉瞬间出现,不会重复画
  • 均线交叉有滞后性,建议结合其他指标确认
  • 震荡行情中会频繁交叉产生假信号,适合趋势行情使用

评论 (1)

后可以留言,比如反馈用着怎么样、想加什么功能。
测试交易员3 小时前

测试评论,指标很好用