Help on simple Breakout strategy

 

Hi,

I'm building as exercise a simple EA that open a long or short trade at the breakout of the 7am candle. I've written the below code but, as my idea was to set the "entry point" only at the 7am hourly candle, the IF i've inserted for checking the hour is not let passing the variables of entry price to the following rows of code.

I'm not very expert, as you can see, could you please address me on how to solve this issue?

Thanks

double lotSize = 0.1;
input int stopLossPips = 5;
input int startTime = 8;
input int endTime = 9;
input int endTimetrd = 22;
bool timecalc;
bool timetrd;
int tradecheck = 0;
datetime currentDateTime;  // Dichiarazione globale
//+------------------------------------------------------------------+
//| Funzione di inizializzazione dell'Esperto                        |
//+------------------------------------------------------------------+
int OnInit()


{
   //---
   return(INIT_SUCCEEDED);
}

//+------------------------------------------------------------------+
//| Funzione eseguita all'arrivo di ogni tick                        |
//+------------------------------------------------------------------+
void OnTick()
//void OnTime()
{
        double entryPriceLong;
        double stopLossPriceLong;
        double TargetPriceLong;
        double entryPriceShort;
        double stopLossPriceShort; 
        double TargetPriceShort;    

datetime tm=TimeCurrent(); //gets current time in datetime data type
   string str=TimeToString(tm,TIME_MINUTES); 
   string current = StringSubstr(str, 0, 2); 
   int currentTimeInt = StringToInteger(current); 


   if(currentTimeInt>=startTime && endTimetrd>currentTimeInt) {
      timetrd = true;
   }
   else {
      timetrd = false;
   }

   if(currentTimeInt>=startTime && endTime>currentTimeInt) {
      timecalc = true;
   }
   else {
      timecalc = false;
   }
   
if (timecalc==true)
{
        // Calcola il massimo e il minimo dell'ultima candela oraria
        double highestHigh = iHigh(NULL, PERIOD_H1, 0);
        double lowestLow = iLow(NULL, PERIOD_H1, 0);
        
        // Calcola i livelli di entrata, stop loss e take profit
        double entryPriceLong = highestHigh + Point();
        double stopLossPriceLong = lowestLow - stopLossPips * Point();
        double TargetPriceLong = highestHigh + ((highestHigh-stopLossPriceLong)*2);
        double entryPriceShort = lowestLow + Point();
        double stopLossPriceShort = highestHigh  + stopLossPips * Point(); 
        double TargetPriceShort = lowestLow - ((highestHigh-stopLossPriceShort)*2);;    
}
double Ask = SymbolInfoDouble(Symbol(),SYMBOL_ASK);
double Bid = SymbolInfoDouble(Symbol(),SYMBOL_BID);



if (timetrd==true)
{

if( Ask>entryPriceLong && tradecheck == 0){
trade.Buy(lotSize,Symbol(),0,stopLossPriceLong,TargetPriceLong,NULL);
tradecheck = 1;}


if(Bid < entryPriceShort && tradecheck == 0){

trade.Sell(lotSize,Symbol(),0,stopLossPriceShort,TargetPriceShort,NULL);
tradecheck = 1;
}
}
   
  
}
Reason: