EA will not manage trade outside time filter - page 2

 
RaptorUK:

Thank you for editing your post.

A simple quick modification would be to set a bool variable to true or false depending on the result of the filter instead of using return,  then check this bool before placing a new trade . . . for example . . .

pieronetto:
Thanks i will work on it, let you know how i do

 

 That what i have so far, getting 0 error(s),0 warning(s) so far so good but not opening trades. need a hint here thanks

void start()  {
//+------------------------------------------------------------------+
//|               Day&Time Filter                                    |
//+------------------------------------------------------------------+
bool TimeFilterAllowTrading;
if(
   
   (TradeOnFriday==false&&DayOfWeek()==5)||
   (TradeOnFriday&&DayOfWeek()==5&&!Hour()>=FridayStartHour)||
   (TradeOnFriday&&DayOfWeek()==5&&!Hour()<=FridayEndHour-1)
  )
   TimeFilterAllowTrading = false;
   else 
   TimeFilterAllowTrading = true;
//+------------------------------------------------------------------+
//|  Opens Position                                                  |
//+------------------------------------------------------------------+
int OpenAtMarket(int mode,double lot) {
   int    res,tr,col;
   double openprice,sl,tp;
   bool TimeFilterAllowTrading;
   tries=0;
   while (res<=0 && tries<OrderTriesNumber) {
      tr=0; while (tr<5 && !IsTradeAllowed()) { tr++; Sleep(2000); }
      RefreshRates();
      if (mode==OP_SELL) {
         openprice=Bid; 
         sl=openprice+StopLoss*Point;
         tp=openprice-TakeProfit*Point;
         col=Red;
      } else {
         openprice=Ask;
         sl=openprice-StopLoss*Point;
         tp=openprice+TakeProfit*Point;
         col=Blue;
      }
      if(TimeFilterAllowTrading)
      res=OrderSend(Symbol(),mode,lot,openprice,slippage,sl,tp,EAName+"_"+expertId,expertId,0,col);
      tries++;
   }
   return(res);
}
 

pieronetto:

 That what i have so far, getting 0 error(s),0 warning(s) so far so good but not opening trades. need a hint here thanks 


You are using 2 different local variables,  the TimeFilterAllowTrading  in start() is not the same as the  TimeFilterAllowTrading   in  OpenAtMarket()   use a globally declared variable  ( above start() )  and get rid of the 2 local TimeFilterAllowTrading   variables.
  
 
RaptorUK:
You are using 2 different local variables,  the TimeFilterAllowTrading  in start() is not the same as the  TimeFilterAllowTrading   in  OpenAtMarket()   use a globally declared variable  ( above start() )  and get rid of the 2 local TimeFilterAllowTrading   variables.
  
bool TimeFilterAllowTrading;

void start()  {
//+------------------------------------------------------------------+
//|               Day&Time Filter                                    |
//+------------------------------------------------------------------+
if(
   (TradeOnFriday==false&&DayOfWeek()==5)||
   (TradeOnFriday&&DayOfWeek()==5&&!Hour()>=FridayStartHour)||
   (TradeOnFriday&&DayOfWeek()==5&&!Hour()<=FridayEndHour-1)
  )
   TimeFilterAllowTrading = false;
   else 
   TimeFilterAllowTrading = true;
//+------------------------------------------------------------------+
//|  Opens Position                                                  |
//+------------------------------------------------------------------+
int OpenAtMarket(int mode,double lot) {
   int    res,tr,col;
   double openprice,sl,tp;   
   tries=0;
   while (res<=0 && tries<OrderTriesNumber) {
      tr=0; while (tr<5 && !IsTradeAllowed()) { tr++; Sleep(2000); }
      RefreshRates();
      if (mode==OP_SELL) {
         openprice=Bid; 
         sl=openprice+StopLoss*Point;
         tp=openprice-TakeProfit*Point;
         col=Red;
      } else {
         openprice=Ask;
         sl=openprice-StopLoss*Point;
         tp=openprice+TakeProfit*Point;
         col=Blue;
      }
      if(TimeFilterAllowTrading)
      res=OrderSend(Symbol(),mode,lot,openprice,slippage,sl,tp,EAName+"_"+expertId,expertId,0,col);
      tries++;
   }
   return(res);
}

0 error(s)  0 warning(s) and opens trades at right time

 
RaptorUK:
You are using 2 different local variables,  the TimeFilterAllowTrading  in start() is not the same as the  TimeFilterAllowTrading   in  OpenAtMarket()   use a globally declared variable  ( above start() )  and get rid of the 2 local TimeFilterAllowTrading   variables.
  

everything works now thank you very much for you help, im sure i come back with other problems.

I wish you the best.

my regards untill then 

 
pieronetto:

everything works now thank you very much for you help, im sure i come back with other problems.


Glad to hear it  :-)
Reason: