找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
首页论坛EAHub 外汇论坛
查看: 44|回复: 0

不漂移无未来的指标

[复制链接]

4万

主题

54

回帖

4万

积分

管理员

积分
45954
发表于 2026-8-27 23:48:00 | 显示全部楼层 |阅读模式
这段代码创建了一个名为"NoDriftIndicator"的指标,它的计算方式是基于指定周期内收盘价的简单移动平均。在这个示例中,我们使用了默认的周期14,你可以根据自己的需要进行调整。


在init()函数中,我们设置了指标的样式、缓冲区和标签。在start()函数中,我们计算了每个周期的简单移动平均值,并将结果保存在buffer数组中。


请注意,这只是一个简单的示例代码,你可以根据自己的需求进行修改和扩展。同时,记得在MT4中编译和加载该指标,以便在图表上显示和使用。

#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 Blue

extern int period = 14;

double buffer[];

int init()
{
    SetIndexStyle(0, DRAW_LINE);
    SetIndexBuffer(0, buffer);
    SetIndexLabel(0, "NoDriftIndicator");
   
    return 0;
}

int start()
{
    int limit = MathMin(Bars - 1, IndicatorCounted());
   
    for (int i = limit; i >= 0; i--)
    {
        double sum = 0;
        
        for (int j = 0; j < period; j++)
        {
            sum += Close[i + j];
        }
        
        buffer = sum / period;
    }
   
    return 0;
}复制代码
这段代码创建了一个名为"NoDriftIndicator"的指标,它的计算方式仍然是基于指定周期内收盘价的简单移动平均。在这个示例中,我们使用了周期20,你可以根据需要进行调整。


在init()函数中,我们设置了指标的样式、缓冲区和标签。在start()函数中,我们计算了每个周期的简单移动平均值,并将结果保存在buffer数组中。


同样地,请记得在MT4中编译和加载该指标,以便在图表上显示和使用。这只是一个示例代码,你可以根据自己的需求进行修改和扩展。

#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 Red

extern int period = 20;

double buffer[];

int init()
{
    SetIndexStyle(0, DRAW_LINE);
    SetIndexBuffer(0, buffer);
    SetIndexLabel(0, "NoDriftIndicator");
   
    return 0;
}

int start()
{
    int limit = MathMin(Bars - 1, IndicatorCounted());
   
    for (int i = limit; i >= 0; i--)
    {
        double sum = 0;
        
        for (int j = 0; j < period; j++)
        {
            sum += Close[i + j];
        }
        
        buffer = sum / period;
    }
   
    return 0;
}复制代码
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|EAHub外汇论坛

GMT+8, 2026-10-9 14:51 , Processed in 0.101229 second(s), 19 queries .

Powered by Discuz! X3.5

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表