mt4怎么调用指数移动平均线

财经新闻 (286) 2年前

mt4怎么调用指数移动平均线_https://wap.78312.cn_财经新闻_第1张

MT4(MetaTrader 4)是一款流行的外汇交易平台,可以通过编程语言MQL4来自定义指标和交易策略。调用指数移动平均线(Exponential Moving Average,简称EMA)需要编写相应的MQL4代码。

以下是使用MQL4编写一个简单的指数移动平均线的示例:

1. 打开MT4软件并进入“Navigator”面板。

2. 在“Custom Indicators”文件夹中创建一个新的自定义指标。

3. 在指标的代码编辑器中,输入以下代码:

```mql4

#property indicator_chart_window

#property indicator_buffers 1

#property indicator_color1 Blue

extern int period = 14;

double emaBuffer[];

int init()

{

SetIndexStyle(0, DRAW_LINE);

SetIndexBuffer(0, emaBuffer);

SetIndexLabel(0, \"EMA\");

return 0;

}

int start()

{

int limit;

int counted_bars = IndicatorCounted();

if (counted_bars < 0)

return -1;

if (counted_bars > 0)

counted_bars--;

limit = Bars - counted_bars;

for (int i = limit; i >= 0; i--)

{

emaBuffer[i] = iMA(NULL, 0, period, 0, MODE_EMA, PRICE_CLOSE, i);

}

return 0;

}

```

4. 在代码中,我们定义了一个外部参数`period`,用于设置指数移动平均线的周期。

5. 在`init()`函数中,我们设置指标的样式和参数,并将指标缓冲区与`emaBuffer`数组关联起来。

6. 在`start()`函数中,我们首先检查指标的计数,然后从最新的未计算的柱(bar)开始,使用`iMA()`函数计算指数移动平均线的值,并将其存储在`emaBuffer`数组中。

7. 保存并编译指标,然后将其应用到MT4的图表上。

这样,你就可以在MT4图表上看到指数移动平均线的结果,而不会出现与政治、色情、赌博和暴力相关的内容。

请注意,在使用自定义指标或编写自定义代码之前,应该确保了解和理解相关的编程语言和金融市场指标的原理。同时,建议在实际交易之前进行充分的测试和验证。