iHigh and iLow not working consistently

 
extern int setdayofweek = 0;
extern int sethour = 12;
extern int lookback_hour = 1;
extern double buy_points_buffer = 7.0;
extern double sell_points_buffer = 10.0;
extern double lots = .3; 
extern double take_profit_points = 10.0;
 
 


 
int ticket = 0;
int buy_enable_trade = 1;
int sell_enable_trade = 1;
int set_buy_modify = 0;
int set_sell_modify = 0;
int order_type = 3;
int timedayofweek = 0;
int timehour = 0;
int enable_stops = 1;
int activate_sound = 0;
int adjust_time = 1;
int adjusted_hour = 0;
 
 
double order_profit = 0.0;
double sell_stop_loss_points = 0.0;
double sell_stop_price = 0.0;
double buy_stop_price = 0.0;
double high = 0.0;
double low = 0.0;
double range = 0.0;

bool res_buy = 0;
bool res_sell = 0;

 

int init()
  {
 
   return(0);
  }
 
int deinit()
  {
 
   return(0);
  }
 
int start()
  {
 
  timedayofweek = DayOfWeek();
  timehour = Hour();
 
  
  if(adjust_time == 1)
   {
   
   
    adjusted_hour = sethour;
    adjust_time = 0;
   
   
   }
    
  
  
  
   
  if((timedayofweek == setdayofweek) && (timehour == adjusted_hour) && (enable_stops == 1))
  {
  
  PlaySound("eagle");  




'THIS IS WHERE THE PROGRAM IS SUPPOSE TO DETERMINE THE HIGH AND LOW OF THE 11TH HOUR CANDLE.

    
  high = iHigh(Symbol(),PERIOD_H1,lookback_hour);
  low = iLow(Symbol(),PERIOD_H1,lookback_hour);  
  








  range = high - low;
  
    
   
 buy_stop_price = high + (buy_points_buffer * .0001); 
 sell_stop_price = low - (sell_points_buffer * .0001);
     
  if(buy_enable_trade == 1)
   {
   
    ticket = OrderSend(Symbol(),OP_BUYSTOP,lots,buy_stop_price,3,low,buy_stop_price + take_profit_points * .0001,0,0,0);
    if(ticket<0)
     {
      Print("OrderSend failed with error #",GetLastError());
     }
   else
      Print("OrderSend placed successfully"); 
      
      buy_enable_trade = 0;
      set_buy_modify = 1;
     
    }
   
  if(set_buy_modify == 1)
   {
    if(OrderSelect(ticket,SELECT_BY_TICKET))
     {
       res_buy = OrderModify(OrderTicket(),OrderOpenPrice(),low,OrderOpenPrice() + (take_profit_points * .0001),0,0); 
       
            if(!res_buy)
               Print("Error in OrderModify. Error code=",GetLastError());
            else
               Print("Order modified successfully.");
        
      set_buy_modify = 0;
     
     } 
   }
 
 
 if(sell_enable_trade == 1)
   {
    
     ticket = OrderSend(Symbol(),OP_SELLSTOP,lots,sell_stop_price,3,high + .0002,sell_stop_price - take_profit_points * .0001,0,0,0);
     if(ticket<0)
     {
      Print("OrderSend failed with error #",GetLastError());
     }
   else
      Print("OrderSend placed successfully");
      sell_enable_trade = 0;
      set_sell_modify = 1;
      
    }
   
  if(set_sell_modify == 1)
   {
    if(OrderSelect(ticket,SELECT_BY_TICKET))
     {
      res_sell = OrderModify(OrderTicket(),OrderOpenPrice(),high + .0002,OrderOpenPrice() - (take_profit_points * .0001),0,0);  
      
     if(!res_sell)
               Print("Error in OrderModify. Error code=",GetLastError());
            else
               Print("Order modified successfully."); 
       
      set_sell_modify = 0;
       enable_stops = 0;
       
     } 
   }

   
 }
 
  
  
 
 
 
 
   return(0);
  }
 

This program works erratically in setting up the HIGHS and LOWS of the 11th hour candles.   Suppose go active on the 12th candles using the high and low of the 11th candle.  But sometimes it sets up a different candle.   Today it went active on the 13th candle and set up the high and low  of the 12th candle.  The default values were not changed.   Could someone please tell me why this is happening?

 

This part :

extern int lookback_hour = 1;

....

  high = iHigh(Symbol(),PERIOD_H1,lookback_hour);
  low = iLow(Symbol(),PERIOD_H1,lookback_hour); 
is not supposed to get high and low of 11th hour, but of the 1st closed bar in 1 hour time frame. That entirely depends on the time of the day and the 1 hour data
 
Mladen Rakic:

This part :

is not supposed to get high and low of 11th hour, but of the 1st closed bar in 1 hour time frame. That entirely depends on the time of the day and the 1 hour data

if((timedayofweek == setdayofweek) && (timehour == adjusted_hour) && (enable_stops == 1))

 This line in the program activates the program when I want it to check the previous candle.    For example, if I want to activate the program to set the buy and sell stops on Tuesday at 12 london time, using the high and low of the 11th hour candle, I use the following inputs:

 extern int setdayofweek = 2;

extern int sethour = 12;
extern int lookback_hour = 1;
 
Paul:

 This line in the program activates the program when I want it to check the previous candle.    For example, if I want to activate the program to set the buy and sell stops on Tuesday at 12 london time, using the high and low of the 11th hour candle, I use the following inputs:

 extern int setdayofweek = 2;

Check the rest of your code then
Reason: