How to open trades using Objects (Rectangles) ?

 

Hi All

I would like to open a trade when the lowest/highest rectangle is completed. So if the 2 highest candles on top touches the rectangle open a sell trade, I would like the same with the lowest.

void Buy()
 {
  double Ask=SymbolInfoDouble(Symbol(),SYMBOL_ASK);
  double Bid=SymbolInfoDouble(Symbol(),SYMBOL_BID);
  
  double OneHourTF=iClose(NULL,PERIOD_H1,1);
  double CurrentTFHour=iClose(NULL,0,1);
  
  double Low[];
  ArraySetAsSeries(Low,true);
  int Demand=iLowest(Symbol(),0,MODE_LOW,200,0);
  CopyLow(Symbol(),PERIOD_CURRENT,0,200,Low);
  int Lowest=ArrayMinimum(Low,0,0);
  
  MqlRates Candle[];
  ArraySetAsSeries(Candle,true);
  int rates=CopyRates(Symbol(),Period(),0,Bars(Symbol(),Period()),Candle);
  
  ObjectDelete(0,"Demand");
  ObjectCreate(0,"Demand",OBJ_RECTANGLE,0,Candle[Demand].time,Candle[Demand].close,Candle[0].time,Candle[Demand].low);
  ObjectSetInteger(0,"Demand",OBJPROP_FILL,true);
  ObjectSetInteger(0,"Demand",OBJPROP_BACK,false);
  ObjectSetInteger(0,"Demand",OBJPROP_COLOR,Green);
  
  if(OneHourTF<CurrentTFHour)
  {
   if(Ask>Demand&&Candle[1].close<Demand)
   {
    trade.Buy(0.01,NULL,Ask,0,0,"JackBuda");
   }
  }
  
 }
 
void Sell()
 {
  double Ask=SymbolInfoDouble(Symbol(),SYMBOL_ASK);
  double Bid=SymbolInfoDouble(Symbol(),SYMBOL_BID);
  
  double OneHourTF=iClose(NULL,PERIOD_H1,1);
  double CurrentTFHour=iClose(NULL,0,1);
  
  double High[];
  ArraySetAsSeries(High,true);
  int Supply=iHighest(Symbol(),0,MODE_HIGH,200,0);
  CopyHigh(Symbol(),PERIOD_CURRENT,0,200,High);
  int Highest=ArrayMaximum(High,0,0);
  
  MqlRates Candle[];
  ArraySetAsSeries(Candle,true);
  int rates=CopyRates(Symbol(),Period(),0,Bars(Symbol(),Period()),Candle);
  
  ObjectDelete(0,"Supply");
  ObjectCreate(0,"Supply",OBJ_RECTANGLE,0,Candle[Supply].time,Candle[Supply].close,Candle[0].time,Candle[Supply].high);
  ObjectSetInteger(0,"Supply",OBJPROP_FILL,true);
  ObjectSetInteger(0,"Supply",OBJPROP_BACK,false);
  ObjectSetInteger(0,"Supply",OBJPROP_COLOR,Red);
  
  if(CurrentTFHour>OneHourTF)
  {
   if(Supply<Bid&&Candle[1].close>Supply)
   {
    trade.Sell(0.01,NULL,Bid,0,0,"JackBuda");
   }
  }
  
 } 


I tried using the following:

Ask>Demand//Buy

Supply<Bid//Sell

It will open trades in between the rectangles, that's not what I want.

Reason: