下面是一个简单的移动平均线指标的Mq4代码:

#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 Lime

extern int MA_Period = 20;

double MA_Buffer[];

void init()
{
    SetIndexStyle(0, DRAW_LINE);
    SetIndexBuffer(0, MA_Buffer);
}

void start()
{
    int limit;
    double ma;

    limit = Bars - MA_Period;

    for (int i = 0; i < limit; i++)
    {
        ma = iMA(NULL, 0, MA_Period, 0, MODE_SMA, PRICE_CLOSE, i);
        MA_Buffer[i] = ma;
    }
}

这个指标使用了一个外部参数MA_Period来定义移动平均线的周期。在init()函数中,我们设置了指标的样式和缓冲区。在start()函数中,我们使用iMA()函数来计算移动平均线的值,并将其存储在缓冲区中。最后,我们将指标的颜色设置为绿色

用Mq4语言编写移动平均线指标

原文地址: https://www.cveoy.top/t/topic/c1jH 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录