Email Alert -- Lost Connectivity

Studies that have been contributed to the community by other users. If you’ve got something useful to share, that’s great!
momentum
Posts: 315
Joined: 23 Nov 2005
Has thanked: 8 times
Been thanked: 14 times

Email Alert -- Lost Connectivity

Postby momentum » 31 Jan 2012

Couldn't find anything using search. Is there a way of getting MC to send an email when it loses connectivity with the broker when running autotraded algos.?





[moderator's note]
another useful read on setting up email alert:

viewtopic.php?f=1&t=9906

see post #13
[FAQ]
viewtopic.php?f=16&t=6845

User avatar
Henry MultiСharts
Posts: 8503
Joined: 25 Aug 2011
Has thanked: 1213 times
Been thanked: 2731 times

Re: Loss of Broker Connectivity Alert

Postby Henry MultiСharts » 31 Jan 2012

momentum wrote:Couldn't find anything using search. Is there a way of getting MC to send an email when it loses connectivity with the broker when running autotraded algos.?



Hello Momentum,

Unfortunately there is no way to detect broker / market data disconnection from EasyLanguage script, so that is not possible to make an alert on this condition.

Once the broker connection is lost->the auto trading turns off.
You can use “getappinfo” code word to check the auto trading status and then send an alert.
aiStrategyAuto - specifies return of a numerical value, indicating whether the calling application is using Automated Trade Execution GetAppInfo will return a value of 1 only if the calling application is using Automated Trade Execution, and a value of 0 in all other cases.

User avatar
JoshM
Posts: 2089
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1525 times
Been thanked: 1485 times
Contact:

Re: Loss of Broker Connectivity Alert

Postby JoshM » 04 Feb 2012

TJ wrote:Any volunteer to code this detection?

For such a helpful forum member, the answer can only be: "always". :)

That it would be something I'm myself am also interested in, is of course a nice bonus ;). Will report back later this weekend.

User avatar
JoshM
Posts: 2089
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1525 times
Been thanked: 1485 times
Contact:

Re: Loss of Broker Connectivity Alert

Postby JoshM » 04 Feb 2012

It's a shame that it isn't possible to trigger an Alert() in a Signal, since the GetAppInfo(aiStrategyAuto) doesn't work in indicators (only gives zeros). So, it's not possible to monitor the automated strategy "on" / "off" and generate a popup signal.

We'll probably need this PM for that: MC-319 - Allow Alert in Signals.

However, it's still possible to generate a sound alert or to write to a log or do something else. The first solution, using a sound alert, is the approach I've used in the code below. The sound alert tells you "ats turned off with no position" or tells "ats turned off with a open position":

Code: Select all

{
   ATS Status Monitor; monitors if the Autotrading strategy is turned off, and if yes, gives a sound alert
      depending the strategy was turned off with an open position or not.
}

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), mp(0);

if (LastBarOnChart_s = True) then begin

   atsStatus    = GetAppInfo(aiStrategyAuto);
   mp            = MarketPosition(0) * CurrentContracts;
   
{   If your broker (IB, ZF, Pats) supports it, you might want to replace the line above 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)
   mp            = MarketPosition_at_Broker;
}
   
   // 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
   
      // If there was a MarketPosition on the previous update, we need to raise a big alarm
      if (PrevMP <> 0) then       
         PlaySound("C:\Temp\atsOffWithOpenMP.wav")
      
      // ... else a lighter alert would be needed
      else       
         PlaySound("C:\Temp\atsOffNoMP.wav");
         
   end;

   PrevATSStatus    = atsStatus;
   PrevMP         = mp;

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


Note: This is a Signal and not an indicator.

In the attached .zip file, there is the PowerLanguage file plus the two audio files that gets referenced in the code.

(PS: You'll need to manually change the directory where you place these sound files in the code)

Any feedback/suggestions more than welcomed. :)
Attachments
atsStatusMonitor.zip
(254.8 KiB) Downloaded 546 times

User avatar
TJ
Posts: 6580
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 970 times
Been thanked: 1907 times

Re: Loss of Broker Connectivity Alert

Postby TJ » 04 Feb 2012

JoshM wrote:It's a shame that it isn't possible to trigger an Alert() in a Signal, ...
:)

Nice work, and fast too!

Just a thought, can we use GV to bridge to an indicator?










[moderator's update 20120419]

From JoshM:

With MC 8.0 beta 2, it's also possible to code the Alert directly into the signal, so that the additional indicator isn't necessary any more:


Alerts in Signals (Strategies)

There are now alerts available for signals (strategies). You can use sounds, visual or email alerts to get notified about orders and position changes. More info here -https://www.multicharts.com/pm/viewissue.php?issue_no=MC-319.


Source: MC Blog

User avatar
JoshM
Posts: 2089
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1525 times
Been thanked: 1485 times
Contact:

Re: Loss of Broker Connectivity Alert

Postby JoshM » 04 Feb 2012

TJ wrote:Just a thought, can we use GV to bridge to an indicator?

Not a bad idea, since that does indeed work.

By adding two lines in the signal (the GVSetNamedInt lines):

Code: Select all

{
   ATS Status Monitor; monitors if the Autotrading strategy is turned off,
   and if yes, gives a sound alert depending the strategy was turned off
   with an open position or not.
}

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), mp(0);

if (LastBarOnChart_s = True) then begin

   atsStatus    = GetAppInfo(aiStrategyAuto);
   mp            = MarketPosition(0) * CurrentContracts;
   
{
   If your broker (IB, ZF, Pats) supports it,
   you might want to replace the line above 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)
   mp = MarketPosition_at_Broker;
}
   
   // 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
   
      // If there was a MarketPosition on the previous update, we need to raise a big alarm
      if (PrevMP <> 0) then begin      
         PlaySound("C:\Temp\atsOffWithOpenMP.wav");
         value1 = GVSetNamedInt("atsStatusMonitor", 2);
      // ... else a lighter alert would be needed
      end else begin       
         PlaySound("C:\Temp\atsOffNoMP.wav");
         value1 = GVSetNamedInt("atsStatusMonitor", 1);
      end;
         
   end;

   PrevATSStatus    = atsStatus;
   PrevMP         = mp;

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


.. and adding this indicator to the chart:

Code: Select all

{
   ATS Status Monitor Alerts indicator;
   gives an alert if the ATS is turned off,
   as detected by the ATS Status Monitor signal.
}

Inputs:
   RecalcAfter(10);

Variables:
   gvValue(0);   
   
if (CheckAlert = True) then begin

   gvValue = GVGetNamedInt("atsStatusMonitor", 0);
   
   if (gvValue <> 0) then begin
   
      if (gvValue = 1) then
         Alert("ATS Status Monitor: ATS has been turned OFF, no position.");
         
      if (gvValue = 2) then
         Alert("ATS Status Monitor: ATS has been turned OFF with OPEN position.");
   
      value1 = GVSetNamedInt("atsStatusMonitor", 0);
   end;

   RecalcLastBarAfter(RecalcAfter);
end;   


..we'll get these types of alerts when the ATS is turned off:

Image

Nice. :)
Attachments
scr.04-02-2012 17.49.03.png
scr.04-02-2012 17.49.03.png (4.79 KiB) Viewed 4596 times

User avatar
TJ
Posts: 6580
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 970 times
Been thanked: 1907 times

Re: Loss of Broker Connectivity Alert

Postby TJ » 04 Feb 2012

Bravo !

Amazing work Josh. I clicked "Thanks" 10 times!

Many thanks for your expertise in coding, your generosity in sharing, and your expediency in delivery!

Well done.

User avatar
JoshM
Posts: 2089
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1525 times
Been thanked: 1485 times
Contact:

Re: Loss of Broker Connectivity Alert

Postby JoshM » 05 Feb 2012

Thanks TJ :), you almost me make blush with all those kinds words. ;)

Glad I could be of help.

NW27
Posts: 177
Joined: 25 Dec 2010
Has thanked: 40 times
Been thanked: 83 times

Re: Loss of Broker Connectivity Alert

Postby NW27 » 18 Feb 2012

Hi Josh,

Given that MC easylanguage is one big loop that gets iterated on each incoming tick, does the alerts work, given that the broker is disconnected, so no incoming ticks, so no loops so no alerts?

Neil.

P.S. It's the weekend so no incoming ticks for me to test on.

User avatar
JoshM
Posts: 2089
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1525 times
Been thanked: 1485 times
Contact:

Re: Loss of Broker Connectivity Alert

Postby JoshM » 18 Feb 2012

NW27 wrote:Hi Josh,

Given that MC easylanguage is one big loop that gets iterated on each incoming tick, does the alerts work, given that the broker is disconnected, so no incoming ticks, so no loops so no alerts?

Neil.

P.S. It's the weekend so no incoming ticks for me to test on.

Yes Neil, both the indicator and the signal use RecalcLastBarAfter() for that.

If you can connect to your broker during the weekend (i.e. login into the order server), you can test it by connecting to the broker, turn automated trading on, and then turn it off. Even if the chart doesn't update (or isn't even a recent chart), after the specified 'RecalcAfter' seconds you should get the alert notifying that automated trading has been turned off.

User avatar
MAtricks
Posts: 789
Joined: 09 Apr 2012
Has thanked: 286 times
Been thanked: 279 times

Re: Loss of Broker Connectivity Alert

Postby MAtricks » 17 Jan 2014

Great work and great idea! Joshm you really are an asset here!

I'm curious if this is still the best way to notify us when there's a disconnect from our broker or data feed? The MC developers update the software so quickly that I'd like to keep on board with the current ways of doing things.

The reason why I'm posting this is because our server went down today (cyber attack) and when it came back up, Multicharts charts loaded up and signals were fired off as soon as this happened. So...

Issue:
1) I'd like to know when the server goes down
Answer:
1) We ping our server from an unrelated server constantly and send us an alert when our server isn't reached

Issue:
2) We have positions trading and the server goes down
Answer:
2) We log into our accounts on our local machines and monitor positions

Issue:
3) I'd like Multicharts to know when we have no connectivity and for it to shutoff SA/AA automatically
Answer:
??? I need some help with this one...

Thanks in advance for any light we can shed on this issue.

User avatar
Henry MultiСharts
Posts: 8503
Joined: 25 Aug 2011
Has thanked: 1213 times
Been thanked: 2731 times

Re: Loss of Broker Connectivity Alert

Postby Henry MultiСharts » 29 Jan 2014

MAtricks wrote:Issue:
3) I'd like Multicharts to know when we have no connectivity and for it to shutoff SA/AA automatically
Answer:
??? I need some help with this one...

Thanks in advance for any light we can shed on this issue.

MAtricks, which broker profile do you use for auto trading?

User avatar
MAtricks
Posts: 789
Joined: 09 Apr 2012
Has thanked: 286 times
Been thanked: 279 times

Re: Loss of Broker Connectivity Alert

Postby MAtricks » 02 Feb 2014

I use Rithmic for my live trading.

User avatar
Henry MultiСharts
Posts: 8503
Joined: 25 Aug 2011
Has thanked: 1213 times
Been thanked: 2731 times

Re: Loss of Broker Connectivity Alert

Postby Henry MultiСharts » 06 Feb 2014

MAtricks wrote:I use Rithmic for my live trading.

There are no particular "broker/data connection is lost" events/reserved words in PowerLanguage at the moment. The "broker profile is disconnected" event can be received only by checking the auto trading status, as for some brokers AT is turned off if the broker connection was lost and was not restored.
When Rithmic broker profile looses the connection - MultiCharts automatically tries to reconnect to it infinitely. It means Rithmic broker profile is never turned into “Disconnected” state and the auto trading is never turned off.

User avatar
MAtricks
Posts: 789
Joined: 09 Apr 2012
Has thanked: 286 times
Been thanked: 279 times

Re: Loss of Broker Connectivity Alert

Postby MAtricks » 06 Feb 2014

It would be great if we had enough control to turn off autotrading completely from our code.

User avatar
Henry MultiСharts
Posts: 8503
Joined: 25 Aug 2011
Has thanked: 1213 times
Been thanked: 2731 times

Re: Loss of Broker Connectivity Alert

Postby Henry MultiСharts » 07 Feb 2014

MAtricks wrote:It would be great if we had enough control to turn off autotrading completely from our code.

AT can be turned off from the code with the help of ".at_toggle" command.

Jad
Posts: 68
Joined: 15 Jun 2014
Has thanked: 6 times
Been thanked: 12 times

Re: Loss of Broker Connectivity Alert

Postby Jad » 15 Jun 2014

Henry MultiСharts wrote:
MAtricks wrote:It would be great if we had enough control to turn off autotrading completely from our code.

AT can be turned off from the code with the help of .... ".at_toggle" command[/url].


Am I right in saying that turning off AT (either manually or automatically from within the script) results in...

1. The strategy recalculating against all of the data currently loaded on the chart when AT is turned back on before it can place any further trades? Depending on the amount of Data and Studies, that could take a significant amount of time.

2. If turned off from the Status Bar, ALL strategies placed on that chart will be turned off?

If so, is there a way to keep the strategy 'on' but have the code bypassed on each tick based on a user-configurable toggle or button - either manually or via the script?

User avatar
Henry MultiСharts
Posts: 8503
Joined: 25 Aug 2011
Has thanked: 1213 times
Been thanked: 2731 times

Re: Loss of Broker Connectivity Alert

Postby Henry MultiСharts » 27 Aug 2014

Jad wrote:Am I right in saying that turning off AT (either manually or automatically from within the script) results in...
1. The strategy recalculating against all of the data currently loaded on the chart when AT is turned back on before it can place any further trades? Depending on the amount of Data and Studies, that could take a significant amount of time.
That is correct. When a strategy/signal script is recalculated

Jad wrote:2. If turned off from the Status Bar, ALL strategies placed on that chart will be turned off?
All signals applied to a chart = one strategy. Auto trading is turned on/off for the complete strategy, not for individual signals. Individual signals can be turned off to be excluded from the strategy prior to turning on the auto trading.

Jad wrote:If so, is there a way to keep the strategy 'on' but have the code bypassed on each tick based on a user-configurable toggle or button - either manually or via the script?
What is your final goal?

Jad
Posts: 68
Joined: 15 Jun 2014
Has thanked: 6 times
Been thanked: 12 times

Re: Loss of Broker Connectivity Alert

Postby Jad » 27 Aug 2014

Henry MultiСharts wrote: What is your final goal?


Currently, there is only one Automate Trading Switch on a chart. This switch affects all the signals for that chart.

Ideally, it would be possible to assign signals/strategies to their own on/off button on a toolbar or dashboard. That would enable signals to be turned on or off without having to select 'Format Signals' - then change the Status of the signals - before being able to press the Automate Trading Switch whenever you wanted to change the signal(s) to execute.

As far as I can determine, the only way to achieve this now is to assign each signal to its own chart which unnecessarily requires duplicated Instruments and Indicators.

User avatar
Henry MultiСharts
Posts: 8503
Joined: 25 Aug 2011
Has thanked: 1213 times
Been thanked: 2731 times

Re: Loss of Broker Connectivity Alert

Postby Henry MultiСharts » 28 Aug 2014

Jad wrote:Currently, there is only one Automate Trading Switch on a chart. This switch affects all the signals for that chart.

Ideally, it would be possible to assign signals/strategies to their own on/off button on a toolbar or dashboard. That would enable signals to be turned on or off without having to select 'Format Signals' - then change the Status of the signals - before being able to press the Automate Trading Switch whenever you wanted to change the signal(s) to execute.
At the moment there is no way to do that.

JacoGreeff
Posts: 4
Joined: 03 Mar 2015

Re: Getting MC to send an email alert

Postby JacoGreeff » 01 Apr 2015

Have anyone gotten the built in Email alert system to work as there is a way via Bulksms.com to convert an email sent to a specific mailbox with a certain code in the subject header into an sms to a predefined cell nr..this could be very handy indeed??

Is their any way in MC to create an basic email alert where one can specify the subject matter and the address etc, just very basic and then make use of the SMTP settings in the alert window..??

trim
Posts: 78
Joined: 22 May 2013
Has thanked: 19 times
Been thanked: 2 times

Re: Getting MC to send an email alert

Postby trim » 09 Apr 2015

Hi

Not sure what you are looking for however this is the subject line (see below) of the email alert I can get from MC using the MC (PowerLanguage) code that I have built into one of my indicators.. ,there is limited editing of the alert message to reduce the length of the subject line but it is limited.

MultiCharts64 Alert: RenkoSys2_GV_V1 generated 'DA6M15:0.00030 From C To B' at 0.7675 on DA6M15 (3 Tick Bars)

This alert tells me what chart and what indicator is sending the alert, and what Instrument, plus the reason for the alert to go off (e.g. "from C to B") and the last price of the instrument.
I get this sent to my mobile as an email. Is this what you are looking for?


Return to “User Contributed Studies and Indicator Library”