Notifications.SendEmail doesn't work in Backtest; cTrader Test email tool does
Notifications.SendEmail doesn't work in Backtest; cTrader Test email tool does
04 Apr 2019, 07:26
Hey everyone:
I've configured my email account in cTrader. I know it's correct because the cTrader Test Tool from clickAlgo works perfectly. See image below. However, when running my bot in BackTest mode, I receive no emails.
Here is the code that never sends an email. I have run it in Visual Studio both with debugging on and off. Here is the code:
if (SendEmailWhenPositionOpenedClosed) //Yes, this is true. I know the code enters this IF block because the Print statement is executed. { string emailMessage = String.Format("Opened Position \"{0} {1}\".\n" + "Position comment: {2}\n\n", position.Id, position.Label, position.Comment); Notifications.SendEmail(EmailFrom, EmailTo, "Opened: " + position.Label, emailMessage); if (DebugLogMode) Print("Opened: Emailed {0} Opened: {1} {2}", EmailTo, position.Id, position.Label); }
To eliminate all other possibilities, I even modified the code to have it in the OnStart() method as follows:
protected override void OnStart() { Print("OnStart: Starting SuperProfit Bot"); //my real email is replaced in the code below just for posting to the forum purposes Notifications.SendEmail("postingpurposesonly@yahoo.com","postingpurposesonly@yahoo.com", "Starting CBOT", "This is the message saying your cBot has started."); Print("OnStart: Email should have been sent!"); // Put your initialization logic here
Both Print statements output to the "Log" tab. However, no emails are received.
Does the Notification.SendEmail not run when backtesting? Or what else could it be?
Thank you.
Replies
firemyst
04 Apr 2019, 17:19
RE:
Panagiotis Charalampous said:
Hi FireMyst,
This is by design. Notifications are not sent during backtesting.
Best Regards,
Panagiotis
Thank you for the information. That's great to know.
But, would you mind updating the API documentation with that information? We've been trying for days to get it to work, and nowhere can we find on the website API does it say it doesn't work in backtesting mode:
https://ctrader.com/api/reference/internals/inotifications/sendemail
And previous threads didn't have this information either.
It would be great if there was a section in the documentation somewhere that listed all the functionality that's disabled for backtesting. Or if there is, could you point me to it please?
Thank you! :-)
@firemyst
PanagiotisCharalampous
04 Apr 2019, 17:55
Hi FireMyst,
Sure we will add a notice.
Best Regards,
Panagiotis
@PanagiotisCharalampous
PanagiotisCharalampous
04 Apr 2019, 14:08
Hi FireMyst,
This is by design. Notifications are not sent during backtesting.
Best Regards,
Panagiotis
@PanagiotisCharalampous