small problem with time filter

 

I created this feature for the time filter and it works, but if I close the Metatrader or compile the code for some modification, the function will no longer work. Should I initialize some variable?


//Global scope
extern bool   TradeTimeFilter = true;          
extern string      TradeBegin = "20:00";       
extern string        TradeEnd = "21:00";

datetime time_now, time_begin, time_end;

//--Function for Filter Time
//--------------------------
bool tradeTime(){
  
   if(TradeTimeFilter) {
   
      time_now   = TimeCurrent();
      time_begin = StrToTime(TradeBegin);
      time_end   = StrToTime(TradeEnd);
      }
       else return(false);
  
      if(time_now<time_begin || time_now>time_end){ return(false); }
        
   else return(true); 
  }
//--------------------------

int OnCalculate (const int rates_total,
                 const int prev_calculated,
                 const datetime& time[],
                 const double& open[],
                 const double& high[],
                 const double& low[],
                 const double& close[],
                 const long& tick_volume[],
                 const long& volume[],
                 const int& spread[]){

if(TradeTimeFilter && tradeTime()){

   //myCondition...
   }


}
 
A little help please?
 
fly7680: I created this feature for the time filter and it works, but if I close the Metatrader or compile the code for some modification, the function will no longer work. Should I initialize some variable? A little help please?

Unfortunately your description and the code you posted is not sufficiently clear as to what you are trying to accomplish or what the exact problem is.

Also, using the Current time instead of using the Bar times, does not seem to make much sense in an Indicator.

 
Thanks anyway, I managed to solve it alone!
 
fly7680:
So what was it ?
Reason: