我正在尝试将指标从 MQL4(Metatrader 语言)转换为 Matlab。布林带代码如下:
for(int i=Bars;i>=0;i--)
{
BANDS=iBands(Symbol(),0,20,2,1,0,1,i+1);
}
iBands() documentation将 8 个输入列为:
symbol
timeframe
period
deviation
bands_shift
applied_price
mode
shift
除了 bands_shift
和 shift
我都明白。问题:如果 i = Bars
是数据的整个范围,为什么 i+1
不会产生超出范围的错误?据我所知,这是 20 个周期、2 个标准差布林带的代码。对于给定的时间间隔,相关的布林带值是否是为前一个时间间隔计算的值(因此是第四个逗号后的 1
)? i+1
做了什么?鉴于此代码,我将如何在 matlab 中实现?我的尝试,使用 this移动标准偏差和 this移动平均线:
moving_average = movemean(EURUSD_closes(1:end-1),20); %end-1 in order to shift by 1
moving_average = [NaN; moving_average]; %adding NaN to make BANDS the length of price
moving_std = movestd(EURUSD_closes(1:end-1),20,'backward');
moving_std = [NaN; moving_std1];
BANDS = moving_average + 2*moving_std;
我认为这不会提供与 MQL4 代码相同的输出。任何提示都将不胜感激!
最佳答案
根据我对布林带的了解,您似乎遇到了实现问题。您是否尝试过 Bollinger 的输出? MATLAB 中的函数?
对于窗口大小小于 20 的边缘情况,布林带的实现可能有所不同。您可能需要联系 MQL4 作者以检查所使用的公式。当我在 Python 中实现时,我注意到了一个差异,并且在 Google 财务中看到了指标。不过,如果您正确实现了窗口大小为 20 的值,您将看到相同的值。
关于matlab - 将 MQL4 ibands() 转换为 Matlab,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21562281/