不漂移无未来的指标 (MT4)
这段代码创建了一个名为"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;
[*] }
[*]
[*] 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;
[*] }
[*]
[*] buffer = sum / period;
[*] }
[*]
[*] return 0;
[*]}
页:
[1]