Page 1 of 1

Email Alert -- Lost Connectivity

Posted: 31 Jan 2012
by momentum
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

Re: Loss of Broker Connectivity Alert

Posted: 31 Jan 2012
by Henry MultiСharts
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.

Re: Loss of Broker Connectivity Alert

Posted: 04 Feb 2012
by JoshM
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.

Re: Loss of Broker Connectivity Alert

Posted: 04 Feb 2012
by JoshM
=============================================================

[moderator's update 20120419]

This post has been superseded.

From MC 8.0 onward, it's possible to code the Alert directly into the signal.

=============================================================



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. :)

Re: Loss of Broker Connectivity Alert

Posted: 04 Feb 2012
by TJ
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

Re: Loss of Broker Connectivity Alert

Posted: 04 Feb 2012
by JoshM
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. :)

Re: Loss of Broker Connectivity Alert

Posted: 04 Feb 2012
by TJ
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.

Re: Loss of Broker Connectivity Alert

Posted: 05 Feb 2012
by JoshM
Thanks TJ :), you almost me make blush with all those kinds words. ;)

Glad I could be of help.

Re: Loss of Broker Connectivity Alert

Posted: 18 Feb 2012
by NW27
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.

Re: Loss of Broker Connectivity Alert

Posted: 18 Feb 2012
by JoshM
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.

Re: Loss of Broker Connectivity Alert

Posted: 17 Jan 2014
by MAtricks
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.

Re: Loss of Broker Connectivity Alert

Posted: 29 Jan 2014
by Henry MultiСharts
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?

Re: Loss of Broker Connectivity Alert

Posted: 02 Feb 2014
by MAtricks
I use Rithmic for my live trading.

Re: Loss of Broker Connectivity Alert

Posted: 06 Feb 2014
by Henry MultiСharts
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.

Re: Loss of Broker Connectivity Alert

Posted: 06 Feb 2014
by MAtricks
It would be great if we had enough control to turn off autotrading completely from our code.

Re: Loss of Broker Connectivity Alert

Posted: 07 Feb 2014
by Henry MultiСharts
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.

Re: Loss of Broker Connectivity Alert

Posted: 15 Jun 2014
by Jad
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?

Re: Loss of Broker Connectivity Alert

Posted: 27 Aug 2014
by Henry MultiСharts
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?

Re: Loss of Broker Connectivity Alert

Posted: 27 Aug 2014
by Jad
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.

Re: Loss of Broker Connectivity Alert

Posted: 28 Aug 2014
by Henry MultiСharts
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.

Re: Getting MC to send an email alert

Posted: 01 Apr 2015
by JacoGreeff
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..??

Re: Getting MC to send an email alert

Posted: 09 Apr 2015
by trim
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?

Re: Email Alert -- Lost Connectivity

Posted: 28 Aug 2018
by pcrespo
I don't use my power of thread resurrection often, but this may be a good time for it.

The method proposed ITT to detect a disconnection doesn't work for me in 2018. I tested by manually disconnecting from IB API. No alert, because my signal still prints getappinfo(aistrategyauto)=1 after the disconnection. (The signal continues calculating because my broker is not my data provider.)

Are there any other ways for a signal to detect a disconnection from the broker?

Re: Email Alert -- Lost Connectivity

Posted: 28 Aug 2018
by TJ
pcrespo wrote:I don't use my power of thread resurrection often, but this may be a good time for it.

The method proposed ITT to detect a disconnection doesn't work for me in 2018. I tested by manually disconnecting from IB API. No alert, because my signal still prints getappinfo(aistrategyauto)=1 after the disconnection. (The signal continues calculating because my broker is not my data provider.)

Are there any other ways for a signal to detect a disconnection from the broker?



Open a chart with IB and put this indicator on it.

Re: Email Alert -- Lost Connectivity

Posted: 28 Aug 2018
by pcrespo
I don't have an IB data subscription. I can only open a chart with IQF symbols.

Edit: oh you probably mean in TWS not MC. I'll look into that.