MQL4 EA | Why are my string variables not included in my email body?
MQL4 EA | Why are my string variables not included in my email body?
Loading saved threads...
user14476920 · External communityPost link
External question — Stack Overflow Stack Exchange
Author: user14476920
Original post: https://stackoverflow.com/questions/66751306
License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/
Adaptation: HTML converted to plain text; contact email addresses removed.
Right, I have an email send ontaining information as to the initialisation status of my EA.
Why are my string variables not being included in my email body, despite declaring all string variables?
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);
}
Quote
Report
PaulB · External communityPost link
External answer — Stack Overflow Stack Exchange
Author: PaulB
Original post: https://stackoverflow.com/a/66760010
License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/
Adaptation: HTML converted to plain text; contact email addresses removed.
You should not allocate variables in the header, it should properly be carried out in the init block (this is where you initialise and can properly allocate variables). You are also using OrderSymbol() without selecting an order so this will always be empty.
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);
}
Quote
Report
Post Reply
Quoted from Forex.com.bd-Editorial External question — Stack Overflow Stack Exchange Author: user14476920 Source score (net votes, not local likes): 0 Original post: https://stackoverflow.com/questions/66751306 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. Right, I have an email send ontaining information as to the initialisation status of my EA. Why are my string variables not being included in my email body, despite declaring all string variables? 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); }
Checking account access…