简体   繁体   English

ATR 指标是否包括当前柱

[英]Does ATR indicator include the current bar

I understand from the MQL4 documentation on the ATR indicator , that it can return the the value of the indicator for the current bar if 0 is used for the shift argument.我从关于ATR 指标的 MQL4 文档了解到,如果shift参数使用 0,它可以返回当前柱的指标值。 However, when looking at the MQL5 documentation for the indicator, I notice that there doesn't appear to be any way to determine this.但是,在查看指标的MQL5 文档时,我注意到似乎没有任何方法可以确定这一点。 Possibly, this is because the indicator is intended to be used in conjunction with CopyBuffer like so:这可能是因为该指标旨在与CopyBuffer结合使用,如下所示:

// Note that error handling has been omitted in this code
double values[];
int handle = iATR(Symbol(), PERIOD_D1, 10);
CopyBuffer(handle, 0, 0, 1, values);

In this example, I'm retrieving the daily ATR for a period of 10 days and copying the first value of this buffer into an array.在此示例中,我将检索 10 天期间的每日 ATR,并将此缓冲区的第一个值复制到一个数组中。 So, is values[0] the ATR value for the current day, or the ATR value for the previous day?那么, values[0]是当天的ATR值,还是前一天的ATR值?

According to @PaulB, index 0 always represents the current bar.根据@PaulB,索引 0 始终代表当前柱。 Ergo, this code:因此,这段代码:

double values[];
int handle = iATR(Symbol(), PERIOD_D1, 10);
CopyBuffer(handle, 0, 0, 1, values);

was retrieving the Daily ATR for the current day, which includes the current bar.正在检索当天的每日 ATR,其中包括当前柱线。 In order to fix this, I simply had to change the shift from 0 to 1, like so:为了解决这个问题,我只需要将移位从 0 更改为 1,如下所示:

double values[];
int handle = iATR(Symbol(), PERIOD_D1, 10);
CopyBuffer(handle, 0, 1, 1, values);

which retrieves the daily ATR for the previous day.它检索前一天的每日 ATR。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM