I am having trouble getting my EA to place a trades when the trading hour conditions which I have set are met.
If the EA is activated during the 14th hour ie before the conditions are met it does not place the order when the time rolls over to the 15 hour.
If the EA is activated when the conditions have already been met then it opens orders fine.
It works fine if I test it with TimeMinute() instead of TimeHour() I have also tried using Hour() but no success.
Strangely enough if I use the same conditions to delete pending orders if the condition is NOT true it deletes orders when it rolls over to the next hour.
I have tried so many things now I am desperate and any help will be much appreciated.
The EA is attached to a M1 graph
PHP Code:
//+------------------------------------------------------------------+
//| CHECK FOR BUY CONDITIONS |
//+------------------------------------------------------------------+
if( (TimeHour(CurTime())>=15 && TimeHour(CurTime())<=16))
{
if(BuyStopOrder==0 && longconditions == true)
{
if ( OrderSend ( Symbol(), OP_BUYSTOP, Lots, longprice+spread,
3, longprice-(StopLoss*Point), longprice+(TakeProfit*Point), "",
_MagicNumber,expiration,Green ) < 0 )
{
Alert( "OrderSend Error #", GetLastError() );
return(-1);
}
}
//+------------------------------------------------------------------+
//| CHECK FOR SHORT CONDITIONS |
//+------------------------------------------------------------------+
if(SellStopOrder==0 && shortconditions == true)
{
if ( OrderSend ( Symbol(), OP_SELLSTOP, Lots, shortprice,
3, shortprice+spread+(StopLoss*Point),shortprice+spread-(TakeProfit*Point), "",
_MagicNumber,expiration,Green ) < 0 )
{
Alert( "OrderSend Error #", GetLastError() );
return(-1);
}
}
return(0);
}