=============================================================
[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.