1评论

0收藏

2、接第一帖

avatar 追星 | 45 人阅读 | 1 人评论 | 2024-04-23

初始化
设置指标的全局变量值并创建其句柄:
//+------------------------------------------------------------------+//| 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);  }

""
还没有人打赏,支持一下

评论|共 1 个

兔斯基_5912

发表于 2024-4-23 16:54:24 | 显示全部楼层

写的很好 加油继续

您需要登录后才可以回帖 登录 | 注册 微信登录

EA之家评论守则