When auto trading is turned off due rejected orders, is the "turning off" exactly the same as when when you make a chart setting change (for example).
Ie, is it detectable by the "broker loss of connection" alert:
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
Alert("atsOffWithOpenMP")
// ... else a lighter alert would be needed
else
Alert("atsOffWithOpenMP");
end;
PrevATSStatus = atsStatus;
PrevMP = mp;
RecalcLastBarAfter(RecalcAfter);
end; //: LastBarOnChart_s = True