Send email when error occurs  [SOLVED]

Questions about MultiCharts and user contributed studies.
firemag
Posts: 43
Joined: 15 Sep 2017
Has thanked: 9 times
Been thanked: 2 times

Send email when error occurs

Postby firemag » 08 May 2018

I set up email alerts for a strategy thinking that it will send an email when an alert or error occurs. But it does not seem to be working for errors. For example, GAIN Capital rejected a stop order this morning that was automatically entered by the strategy. An error appeared in the logs tab of the Orders & Positions Tracker window. But no email was generated for the error.

Is there a way to have MC send an email when errors like this occur?

wilkinsw
Posts: 662
Joined: 21 Apr 2013
Has thanked: 154 times
Been thanked: 104 times

Re: Send email when error occurs  [SOLVED]

Postby wilkinsw » 09 May 2018

1) Add this signal to your chart:

viewtopic.php?f=5&t=9890&p=102098&hilit ... ert#p47327

2) Have auto trading turn off if any orders are rejected:
rejected alert.PNG
(41.97 KiB) Downloaded 601 times
Last edited by wilkinsw on 09 May 2018, edited 1 time in total.

wilkinsw
Posts: 662
Joined: 21 Apr 2013
Has thanked: 154 times
Been thanked: 104 times

Re: Send email when error occurs

Postby wilkinsw » 09 May 2018

In terms of email alerts i have 99.9% success of being notified if i have any problems.

The only issue that slips through the net for me is when a popup appears saying something like "Multicharts has stopped working.... check online....close"

It is very rare (maybe 4 times a year).

Anyone have ideas how one detects that? Or what the event id would be in the event logs in windows?

wilkinsw
Posts: 662
Joined: 21 Apr 2013
Has thanked: 154 times
Been thanked: 104 times

Re: Send email when error occurs

Postby wilkinsw » 09 May 2018

To answer my own question:

I already have pulseway monitoring any event 1000 that may occur (app error). For some reason, when this error last occured for me, eventhough the above generated a 1000 event in event viewer, pulseway didn't capture it.

Have contacted them and will revert.

In the meantime does anyone use an alternative to pulseway that they can recommend?

firemag
Posts: 43
Joined: 15 Sep 2017
Has thanked: 9 times
Been thanked: 2 times

Re: Send email when error occurs

Postby firemag » 09 May 2018

In terms of email alerts i have 99.9% success of being notified if i have any problems.

The only issue that slips through the net for me is when a popup appears saying something like "Multicharts has stopped working.... check online....close"
Thank you, this is awesome! It is working perfectly. Solves two problems in one -- errors occurring *and* automated strategies being turned off! Fortunately I have not had MC crash, so have not had to cross that bridge. However, a pulse/heartbeat monitor also sounds like a good idea.

I adapted the auto-trading monitor code to work with Alerts and also display a message on the chart if alerts are disabled. I needed the reminder/confirmation in case I forget to turn them on. :)

Code: Select all

{
ATS Status Monitor; monitors if the Autotrading strategy is turned off, and if yes, issue alert.

Adapated from forum post here: https://www.multicharts.com/discussion/viewtopic.php?f=5&t=9890&p=102098&hilit=broker+loss+alert#p47327

Will also display warning on the chart if alerts are disabled. Enable using Format Signals > Properties > Alerts. On option
"Alert Conditions Check", click "Every Tick" or "Once Per Bar".
}

Inputs:
RecalcAfter(15);

Variables:
IntraBarPersist PrevATSStatus(0), // Holds the status of the ATS at the previous update
IntraBarPersist PrevMP(0), // Holds the previous MarketPosition
atsStatus(0);

if (LastBarOnChart_s = True) then
begin
if ( AlertEnabled = False ) then
begin
Value99 = Text_New(Date, Time, Close, "Warning: Alerts are disabled. See Format Signals > Properties > Alerts");
end;

atsStatus = GetAppInfo(aiStrategyAuto);

// If the current ATS Status differences from the previous, and the previous status was ON, give an alert

if (atsStatus <> PrevATSStatus) and (PrevATSStatus = 1) then begin
Alert(Text("Warning: AutoTrading has been turned off for strategy on account " + GetAccountID));
end;

{ If your broker (IB, ZF, Pats) supports it, you might want to replace MarketPosition with the
line below. However, keep in mind that:
"If Automated Trading was manually turned off by the user, the value returned
by the keyword stops changing, and may remain unequal to '0'." (Source: Helpfile)
PrevMP = MarketPosition_at_Broker;
}

PrevATSStatus = atsStatus;
PrevMP = MarketPosition;

RecalcLastBarAfter(RecalcAfter);
end; //: LastBarOnChart_s = True


Return to “MultiCharts”