参照以下的MT5软件中的EA交易代码的框架:#property copyright Created by ChatGPT#property link httpswwwexamplecom#property version 1000---#include TradePositionInfomqh#include TradeTrademqh#include TradeSymbolInfo
完善后的代码如下:
// 定义指标变量
double DIFF, DEA, MACD, AH, AL, trendline, K, D, J;
// 计算DIFF、DEA、MACD指标
DIFF = iMA(NULL, 0, 12, 0, MODE_EMA, PRICE_CLOSE) - iMA(NULL, 0, 26, 0, MODE_EMA, PRICE_CLOSE);
DEA = iMA(NULL, 0, 9, 0, MODE_EMA, DIFF);
MACD = 2 * (DIFF - DEA / 2);
// 计算AH、AL指标
AH = iHighest(NULL, 0, MODE_MAIN, 13, 1);
AL = iLowest(NULL, 0, MODE_MAIN, 13, 0.3);
// 绘制MACD指标柱状图
PlotIndexSetInteger(0, PLOT_DRAW_BEGIN, Bars-1);
PlotIndexSetString(0, PLOT_ARROW, "Arrow");
PlotIndexSetInteger(0, PLOT_ARROW_SHIFT, 0);
// 绘制趋势线
trendline = iMA(NULL, 0, 34, 1, MODE_EMA, MACD);
PlotIndexSetInteger(1, PLOT_LINE_VALUE, int(trendline));
PlotIndexSetInteger(1, PLOT_LINE_BEGIN, Bars-1);
PlotIndexSetString(1, PLOT_ARROW, "Arrow");
PlotIndexSetInteger(1, PLOT_ARROW_SHIFT, 0);
PlotIndexSetString(1, PLOT_LABEL, "Trend Line");
// 计算K、D、J指标
K = iMA(NULL, 0, 2, 1, MODE_SMA, MACD);
D = iMA(NULL, 0, 2, 1, MODE_SMA, K);
J = iMA(NULL, 0, 2, 1, MODE_SMA, D);
// 绘制K、D、J指标柱状图
PlotIndexSetInteger(2, PLOT_LINE_VALUE, int(K));
PlotIndexSetInteger(2, PLOT_LINE_BEGIN, Bars-1);
PlotIndexSetString(2, PLOT_ARROW, "Arrow");
PlotIndexSetInteger(2, PLOT_ARROW_SHIFT, 0);
PlotIndexSetString(2, PLOT_LABEL, "K");
PlotIndexSetInteger(3, PLOT_LINE_VALUE, int(D));
PlotIndexSetInteger(3, PLOT_LINE_BEGIN, Bars-1);
PlotIndexSetString(3, PLOT_ARROW, "Arrow");
PlotIndexSetInteger(3, PLOT_ARROW_SHIFT, 0);
PlotIndexSetString(3, PLOT_LABEL, "D");
PlotIndexSetInteger(4, PLOT_LINE_VALUE, int(J));
PlotIndexSetInteger(4, PLOT_LINE_BEGIN, Bars-
原文地址: http://www.cveoy.top/t/topic/iqdw 著作权归作者所有。请勿转载和采集!