[英]How to pull +DI and -DI values from an iADX() indicator in MQL4 / MQL5?
I'm a noob at MQL4
and I am writing my first EA. 我是
MQL4
,我正在写第一个EA。
My goal is to get the variables of the +DI
and -DI
of the ADX Indicator. 我的目标是获得ADX指标的
+DI
和-DI
的变量。
I used the iADX()
function as shown here: 我使用了
iADX()
函数,如下所示:
double a;
int OnInit() {
a = iADX( NULL, 0, 0, PRICE_CLOSE, MODE_PLUSDI, 0 );
Alert( a );
}
But it keeps printing 0.0 但它保持打印0.0
Did I enter the parameters wrong on the iADX()
function? 我是否在
iADX()
函数中输入了错误的参数?
I'd just like to pull the values of +DI
and -DI
so I can use them in my code. 我只想拉出
+DI
和-DI
的值,这样我就可以在我的代码中使用它们了。
double iADX( string symbol, // BEST AS: _Symbol
int timeframe, // BEST AS: one of {}-ENUMs ~ PERIOD_CURRENT
int period, // averaging period
int applied_price, // BEST AS: one of {}-ENUMs ~ PRICE_CLOSE
int mode, // BEST AS: one of {}-ENUMs ~ MODE_PLUSDI
int shift // shift
);
0.0
? 0.0
? Once we read into the calling interface, requirement to average the selected sequence of PRICE_CLOSE
records, kept for the current Symbol()
( NULL
) seems fair, but just notice, that doing that for zero-consecutive bars instructs to do nothing, instead of taking some reasonable calculus of SUM( Close[i..j] )/period
to allow for any meaningful processing. 一旦我们读入调用接口,要求平均所选的
PRICE_CLOSE
记录序列,保留当前的Symbol()
( NULL
)似乎是公平的,但只需注意,对于零连续条执行操作指示什么也不做,而不是采用一些合理的SUM( Close[i..j] )/period
来进行任何有意义的处理。
Experiment with non-zero periods and you are back on the rails, aiming towards your goals. 尝试非零时段,您将重新走上正轨,瞄准您的目标。
double DI_plus,
DI_minus;
int ADX_PERIOD = 8;
int OnInit() {
ObjectCreate( ChartID(), "GUI-SHOW+DI", ... ); // LABEL for +DI
ObjectCreate( ChartID(), "GUI-SHOW-DI", ... ); // LABEL for -DI
}
int OnTick() {
DI_plus = iADX( _Symbol,
PERIOD_CURRENT,
ADX_PERIOD,
PRICE_CLOSE,
MODE_PLUSDI,
0
);
DI_minus = iADX( _Symbol,
PERIOD_CURRENT,
ADX_PERIOD,
PRICE_CLOSE,
MODE_MINUSDI,
0
);
ObjectSetString( Chart_ID(),
"GUI-SHOW+DI",
OBJPROP_TEXT,
StringFormat("+DI %12.6f", DI_plus )
);
ObjectSetString( Chart_ID(),
"GUI-SHOW-DI",
OBJPROP_TEXT,
StringFormat("-DI %12.6f", DI_minus )
);
}
ADX has one parameter - its period. ADX有一个参数 - 它的周期。 and you use indicator with period = 0, in such case it returns zeros...
并且你使用周期= 0的指标,在这种情况下它返回零...
double a;
int period = 14;
int OnInit() {
a = iADX( NULL, 0, period, PRICE_CLOSE, MODE_PLUSDI, 0 );
Alert( a );
}
Also I am not sure it is a good idea to call indicator in OnInit()
- sometimes you do not have bars already loaded and sometimes you have, maybe it is fixed but I remember several months ago my client had such problem especially when changing timeframes. 另外我不确定在
OnInit()
调用指示器是一个好主意 - 有时候你没有已经加载的条形图,有时你也有,也许它已经修复但我记得几个月前我的客户端有这样的问题,特别是在更改时间范围时。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.