So here is the function that I have been using in a few of my EA's to disable trading before and after an announcement. . . it seemed to be working fine but now for some reason it always seems to return NewsTime == true. Can anyone take a look and tell me what is wrong.... Feel free to use it in your EA's as well. When it works right it really helps eliminate huge losses. it also allows you to change your strategy to one that works for the announcements.
Thanks
Also is this the best way to kill the open orders ?
PHP Code
// ===================================== NEWS TIME =============================================================
bool NewsTime(){
int MinUntil_EURUSD = iCustom("EURUSD", 0, "FFCal_v05", true, true, false, true, true, 1, 0);
int MinSINCE_EURUSD = iCustom("EURUSD", 0, "FFCal_v05", true, true, false, true, true, 1, 1);
int MinUntil_USDJPY = iCustom("USDJPY", 0, "FFCal_v05", true, true, false, true, true, 1, 0);
int MinSINCE_USDJPY = iCustom("USDJPY", 0, "FFCal_v05", true, true, false, true, true, 1, 1);
int MinUntil_GBPUSD = iCustom("GBPUSD", 0, "FFCal_v05", true, true, false, true, true, 1, 0);
int MinSINCE_GBPUSD = iCustom("GBPUSD", 0, "FFCal_v05", true, true, false, true, true, 1, 1);
int MinUntil_USDCHF = iCustom("USDCHF", 0, "FFCal_v05", true, true, false, true, true, 1, 0);
int MinSINCE_USDCHF = iCustom("USDCHF", 0, "FFCal_v05", true, true, false, true, true, 1, 1);
int MinUntil_AUDUSD = iCustom("AUDUSD", 0, "FFCal_v05", true, true, false, true, true, 1, 0);
int MinSINCE_AUDUSD = iCustom("AUDUSD", 0, "FFCal_v05", true, true, false, true, true, 1, 1);
int MinUntil_USDCAD = iCustom("USDCAD", 0, "FFCal_v05", true, true, false, true, true, 1, 0);
int MinSINCE_USDCAD = iCustom("USDCAD", 0, "FFCal_v05", true, true, false, true, true, 1, 1);
if ((MinUntil_EURUSD||MinUntil_USDJPY||MinUntil_GBPUSD||MinUntil_USDCHF||MinUntil_AUDUSD||MinUntil_USDCAD) < 30){
DisableTrading = true;
Print(".....We have Less than 30 Minutes until the next news announcement, Trading is disabled");
return(true);
}
if ((MinUntil_EURUSD||MinUntil_USDJPY||MinUntil_GBPUSD||MinUntil_USDCHF||MinUntil_AUDUSD||MinUntil_USDCAD) < 10){
Print(".....Closing our orders because its almost newstime");
DisableTrading = true;
KillLongs();
KillShorts();
}
if ((MinSINCE_EURUSD||MinSINCE_USDJPY||MinSINCE_GBPUSD||MinSINCE_USDCHF||MinSINCE_AUDUSD||MinSINCE_USDCAD) < 30){
DisableTrading = true;
Print(".....It has been less than 30 minutes since the last News announcement, Trading is disabled");
return(true);
}
else{
Print(".....is NOT news time, returning FALSE");
return(false);
}
}
Also is this the best way to kill the open orders ?
PHP Code
void KillLongs(){
for (int i=OrdersTotal()-1;i>=0;i--){
OrderSelect(i,SELECT_BY_POS);{
if (OrderSymbol() == Symbol() && OrderMagicNumber() == (LongOneMagic||LongTwoMagic||LongThreeMagic||LongFourMagic)){
OrderClose(OrderTicket(),OrderLots(),Bid,SLIPPAGE,White);
Print ("Kill Longs");
}
}
}
}
void KillShorts(){
for (int i=OrdersTotal()-1;i>=0;i--) {
OrderSelect(i,SELECT_BY_POS);{
if (OrderSymbol() == Symbol() && OrderMagicNumber() == (ShortOneMagic||ShortTwoMagic||ShortThreeMagic||ShortFourMagic)){
OrderClose(OrderTicket(),OrderLots(),Ask,SLIPPAGE,White);
Print ("Kill Shorts");
}
}
}
}
Keep it simple stoopid....