【问题标题】:MQL4 EA | Why are my string variables not included in my email body?MQL4 EA |为什么我的字符串变量不包含在我的电子邮件正文中?
【发布时间】:2021-03-22 17:49:36
【问题描述】:

好的,我有一封电子邮件,其中包含有关我的 EA 初始化状态的信息。

为什么我的字符串变量没有包含在我的电子邮件正文中,尽管声明了所有字符串变量?

int      hourOfDay = Hour();
int      startingHour = 12;
bool     BarTime;
string   eaName = WindowExpertName();
bool     InitOrders;
bool     InitTime;
string   symbol = OrderSymbol();

int OnInit()
{
   /*lastStamp = 0;
   GetMarketInfo_PerSymbol(Symbol(), true);
   fEvents(MODE_INIT);*/ /*Unrelated Code*/
   
   InitOrders = OrdersTotal();
   
   if(InitOrders == 0){
   
      InitOrders = true;
      Print("EA has been initialised to true");
   
   }else{
   
      InitOrders = false;
      Print("EA has been initialised to false");
   
   }
         
   InitTime = (hourOfDay >= startingHour && hourOfDay < 20);
   
   if(InitTime = true){
      Print("Trades will be placed");
      SendMail("Initialisation confirmation: "+(eaName),"Initialised by: User\n\nEA Name: "+(eaName)+"\n\nAsset: Forex CFD "+(symbol)+"\n\nDate of Initialisation "+TimeToString(TimeCurrent(),TIME_DATE | TIME_MINUTES)+" (This may differ from GMT)\n\nInitTime Status: Trades will be placed\n\nInitOrders: "+(InitOrders == True? "You have no open positions" : "You have an open position"));   
   
   }else{
   
      InitTime = false;
      Print("Trades will not be placed.");
      MessageBox("Trades will not be placed until "+IntegerToString(startingHour - 2,0)+"AM GMT\n\nIf you feel this is incorrect, please email us at xxx","| Important Notification",MB_OK|MB_ICONINFORMATION|MB_TOPMOST);
      SendMail("Initialisation confirmation: "+(eaName),"Initialised by: User\n\nEA Name: "+(eaName)+"\n\nAsset: Forex CFD "+(symbol)+"\n\nDate of Initialisation "+TimeToString(TimeCurrent(),TIME_DATE | TIME_MINUTES)+" (This may differ from GMT)\n\nInitTime Status: Trades will not be placed\n\nInitOrders: "+(InitOrders == True? "You have no open positions" : "You have an open position"));
   }
   
BarTime=Time[0];
   
return(INIT_SUCCEEDED);

}

【问题讨论】:

    标签: mql4


    【解决方案1】:

    您不应该在标头中分配变量,它应该在 init 块中正确执行(这是您初始化并可以正确分配变量的地方)。您还使用 OrderSymbol() 而不选择订单,因此这将始终为空。

    int      hourOfDay;
    int      startingHour;
    bool     BarTime;
    string   eaName;
    bool     InitOrders;
    bool     InitTime;
    string   symbol;
    
    int OnInit()
    {
       hourOfDay = Hour();
       startingHour = 12;
       eaName = WindowExpertName();
       symbol = Symbol();
    
       /*lastStamp = 0;
       GetMarketInfo_PerSymbol(Symbol(), true);
       fEvents(MODE_INIT);*/ /*Unrelated Code*/
       
       InitOrders = OrdersTotal();
       
       if(InitOrders == 0){
     
          InitOrders = true;
          Print("EA has been initialised to true");
     
       }else{
    
          InitOrders = false;
          Print("EA has been initialised to false");
    
       }
         
       InitTime = (hourOfDay >= startingHour && hourOfDay < 20);
    
       if(InitTime = true){
          Print("Trades will be placed");
          SendMail("Initialisation confirmation: "+(eaName),"Initialised by: User\n\nEA Name: "+(eaName)+"\n\nAsset: Forex CFD "+(symbol)+"\n\nDate of Initialisation "+TimeToString(TimeCurrent(),TIME_DATE | TIME_MINUTES)+" (This may differ from GMT)\n\nInitTime Status: Trades will be placed\n\nInitOrders: "+(InitOrders == True? "You have no open positions" : "You have an open position"));   
    
       }else{
    
          InitTime = false;
          Print("Trades will not be placed.");
          MessageBox("Trades will not be placed until "+IntegerToString(startingHour - 2,0)+"AM GMT\n\nIf you feel this is incorrect, please email us at xxx","| Important Notification",MB_OK|MB_ICONINFORMATION|MB_TOPMOST);
          SendMail("Initialisation confirmation: "+(eaName),"Initialised by: User\n\nEA Name:"+(eaName)+"\n\nAsset: Forex CFD "+(symbol)+"\n\nDate of Initialisation "+TimeToString(TimeCurrent(),TIME_DATE | TIME_MINUTES)+" (This may differ from GMT)\n\nInitTime Status: Trades will not be placed\n\nInitOrders: "+(InitOrders == True? "You have no open positions" : "You have an open position"));
       }
    
    BarTime=Time[0];
    
    return(INIT_SUCCEEDED);
    
    }
    

    【讨论】:

    • 强度!有效。公平对待你,我会将你的答案标记为正确。一切顺利,
    猜你喜欢
    • 2020-01-12
    • 1970-01-01
    • 2022-08-24
    • 2010-11-20
    • 2015-08-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多