快捷导航
查看: 13|回复: 0

[技术指标] 不漂移无未来的指标 (MT4)

[复制链接]

284

主题

6

回帖

1060

积分

管理员

积分
1060
发表于 昨天 11:27 | 显示全部楼层 |阅读模式
这段代码创建了一个名为"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|手机版|小黑屋|量化魔方 ( 陕ICP备2025062059号-3 )|网站地图

GMT+8, 2026-9-18 01:22 , Processed in 0.119096 second(s), 5 queries , Redis On.

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