这是我最近被问到的问题:如何从 iBearsPower 指示符?
在显示代码之前,我将从使用MQL5 EA河北体彩指标的要点开始:
步骤1:在全局程序级别,我们声明一个变量-iBearsPower指示器的句柄将存储在此变量中。
步骤2:在OnInit()中,我们创建iBearsPower指标并将句柄写入变量。注意:指标是在OnInit()中创建的。
步骤3:在OnTick()中,我们从指标中获取数据
代码中的CodeBase中有一个示例 我的系统 .
步骤1:
double ExtStopLoss=0.0; double ExtTakeProfit=0.0; int handle_iBullsPower; // variable for storing the handle of the iBullsPower indicator int handle_iBearsPower; // variable for storing the handle of the iBearsPower indicator double m_adjusted_point; // point value adjusted for 3 or 5 points //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit()
第2步:
} //--- create handle of the indicator iBearsPower handle_iBearsPower=iBearsPower(m_symbol.Name(),Period(),Inp_ma_period); //--- if the handle is not created if(handle_iBearsPower==INVALID_HANDLE) { //--- tell about the failure 和 output the error code PrintFormat("Failed to create handle of the iBearsPower indicator for the symbol %s/%s, error code %d", m_symbol.Name(), EnumToString(Period()), GetLastError()); //--- the indicator is stopped early return(INIT_FAILED); } //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason)
第三步:
double bulls[]; ArraySetAsSeries(bulls,true); double bears[]; ArraySetAsSeries(bears,true); if(!iBullsPowerGetArray(InpBarCurrent,2,bulls) || !iBearsPowerGetArray(InpBarCurrent,2,bears)) { PrevBars=0; return; }
功能 iBearsPowerGetArray: is used 复制缓冲区
//+------------------------------------------------------------------+ //| Get value of buffers for the iBearsPower in the array | //+------------------------------------------------------------------+ bool iBearsPowerGetArray(const int start_pos,const int count,double &arr_buffer[]) { //--- bool result=true; if(!ArrayIsDynamic(arr_buffer)) { Print("This a no dynamic array!"); return(false); } ArrayFree(arr_buffer); int buffer_num=0; // 指标缓冲区 number //--- reset error code ResetLastError(); //--- fill a part of the iBearsPower array with values from the 指标缓冲区 that has 0 index int copied=复制缓冲区(handle_iBearsPower,buffer_num,start_pos,count,arr_buffer); if(copied!=count) { //--- if the copying fails, tell the error code PrintFormat("Failed to copy data from the iBearsPower indicator, error code %d",GetLastError()); //--- quit with zero result - it means that the indicator is considered as not calculated return(false); } return(result); }
227209
该线程讨论MQL5代码示例。将会有一些示例,这些示例说明了如何从指标中获取数据,如何对顾问程序进行编程……通常,从初学者到MQL5语言的任何问题。
如果您刚刚开始熟悉MetaTrader 5终端,那么我可以推荐以下主题:
如何从Metatrader 5开始
我从哪里开始?
使用Freelance服务中的提示!