初始化//+------------------------------------------------------------------+//| Expert initialization function |//+------------------------------------------------------------------+int OnInit() {//--- create timer EventSetTimer(60);//--- Indicator//--- Set and adjust the calculation period and levels if necessary period=int(InpPeriod<1 ? 9 : InpPeriod); period_fast=int(InpPeriodFast<1 ? 2 : InpPeriodFast); period_slow=int(InpPeriodSlow<1 ? 30 : InpPeriodSlow);//--- Set the indicator name and the number of decimal places ind_title=StringFormat("AMA(%lu,%lu,%lu)",period,period_fast,period_slow); ind_digits=Digits()+1;//--- Create indicator handle ResetLastError(); handle=iAMA(Symbol(),PERIOD_CURRENT,period,period_fast,period_slow,InpShift,InpPrice); if(handle==INVALID_HANDLE) { PrintFormat("%s: Failed to create indicator handle %s. Error %ld",__FUNCTION__,ind_title,GetLastError()); return INIT_FAILED; }//--- Successful initialization return(INIT_SUCCEEDED); } 如果EA涉及使用仪表板,我们应该创建它: //+------------------------------------------------------------------+//| Expert initialization function |//+------------------------------------------------------------------+int OnInit() {//--- create timer EventSetTimer(60);//--- Indicator//--- Set and adjust the calculation period and levels if necessary period=int(InpPeriod<1 ? 9 : InpPeriod); period_fast=int(InpPeriodFast<1 ? 2 : InpPeriodFast); period_slow=int(InpPeriodSlow<1 ? 30 : InpPeriodSlow);//--- Set the indicator name and the number of decimal places ind_title=StringFormat("AMA(%lu,%lu,%lu)",period,period_fast,period_slow); ind_digits=Digits()+1;//--- Create indicator handle ResetLastError(); handle=iAMA(Symbol(),PERIOD_CURRENT,period,period_fast,period_slow,InpShift,InpPrice); if(handle==INVALID_HANDLE) { PrintFormat("%s: Failed to create indicator handle %s. Error %ld",__FUNCTION__,ind_title,GetLastError()); return INIT_FAILED; }//--- Dashboard//--- Create the panel panel=new CDashboard(1,20,20,197,225); if(panel==NULL) { Print("Error. Failed to create panel object"); return INIT_FAILED; }//--- Set font parameters panel.SetFontParams("Calibri",9);//--- Display the panel with the "Symbol, Timeframe description" header text panel.View(Symbol()+", "+StringSubstr(EnumToString(Period()),7));//--- Create a table with ID 0 to display bar data in it panel.CreateNewTable(0);//--- Draw a table with ID 0 on the panel background panel.DrawGrid(0,2,20,6,2,18,96);//--- Create a table with ID 1 to display indicator data in it panel.CreateNewTable(1);//--- Get the Y2 table coordinate with ID 0 and//--- set the Y1 coordinate for the table with ID 1 int y1=panel.TableY2(0)+22;//--- Draw a table with ID 1 on the panel background panel.DrawGrid(1,2,y1,3,2,18,96); //--- Display tabular data in the journal panel.GridPrint(0,2); panel.GridPrint(1,2);//--- Initialize the variable with the index of the mouse cursor bar mouse_bar_index=0;//--- Display the data of the current bar on the panel DrawData(mouse_bar_index,TimeCurrent());//--- Successful initialization return(INIT_SUCCEEDED); }
|