以下是一个简单的移动平均线指标代码,使用Mq4语言编写:

#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 Red

extern int ma_period = 10;

double ma_buffer[];

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

int start()
{
    int limit = Bars - ma_period;
    for(int i = 0; i < limit; i++)
    {
        double sum = 0;
        for(int j = 0; j < ma_period; j++)
        {
            sum += Close[i+j];
        }
        ma_buffer[i] = sum / ma_period;
    }
    return(0);
}

这个指标使用外部参数ma_period来设置移动平均线的周期。在init()函数中,我们设置了指标的样式和缓冲区。在start()函数中,我们计算了每个周期的移动平均线,并将结果存储在缓冲区中。最后,我们返回0以表示指标计算成功

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

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

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