Functions applied to objects on chart

 

Hi Everyone, 

I'm attempting to create an arrow over or under an engulfing pattern. Recognizing the pattern isn't an issue although I want the arrow to be above or below the lowest or highest wick of the pattern.

So if its a buying Engulfing pattern id like the arrow to appear below the lowest wick of the pattern vice versa, returning values either 'HighestHigh' or 'LowestLow' so I can use the relevant price as to where the arrow should be placed.

I appreciate the help in advance, cheers



  int getEngulfingSignal(){
   
   datetime time0 = iTime("EURUSD", PERIOD_CURRENT, 0);
   datetime time1 = iTime("EURUSD", PERIOD_CURRENT, 1);
   datetime time2 = iTime("EURUSD", PERIOD_CURRENT, 2);
     
   double closePrice1 = iClose("EURUSD", PERIOD_CURRENT, 1);
   double openPrice1 = iOpen("EURUSD", PERIOD_CURRENT, 1);
   double highPrice1 = iHigh("EURUSD", PERIOD_CURRENT, 1);
   double lowPrice1 = iLow("EURUSD", PERIOD_CURRENT, 1);
   double bodySize1 = MathAbs(closePrice1 - openPrice1);
   double candleSize1 = MathAbs(highPrice1 - closePrice1);
   
   double closePrice2 = iClose("EURUSD", PERIOD_CURRENT, 2);
   double openPrice2 = iOpen("EURUSD", PERIOD_CURRENT, 2);
   double highPrice2 = iHigh("EURUSD", PERIOD_CURRENT, 2);
   double lowPrice2 = iLow("EURUSD", PERIOD_CURRENT, 2);
   double bodySize2 = MathAbs(closePrice2 - openPrice2);
   double candleSize2 = MathAbs(highPrice2 - closePrice2);

   double HighestHigh = MathMax(highPrice1, highPrice2);
   double LowestLow = MathMin(lowPrice1, lowPrice2);
   
   
   //Buying Engulfing Pattern
     if(openPrice2 > closePrice2 && openPrice1 < closePrice1 && closePrice2 == openPrice1){ 
         if(bodySize2 < bodySize1){
            if(bodySize2 > minBodySize){
               createObject(time1, lowPrice2, 233, 1, clrGreen, " Engulfing");
               return 1;
            }  
         }
     }
     
   //Selling Engulfing Pattern
     if(openPrice2 < closePrice2 && openPrice1 > closePrice1 && closePrice2 == openPrice1){                                         
         if(bodySize2 < bodySize1){
            if(bodySize2 > minBodySize){
               createObject(time1, highPrice2, 234, -1, clrRed, " Engulfing");
               return -1;
            }  
         }
     }
     
     return 0;
   }




//+-------------------------------------------------------------------------------------------------------+
//|  EA Candlestick Displays                                                                              |
//+-------------------------------------------------------------------------------------------------------+




void createObject(datetime time, double price, int arrowcode, int direction, color clr, string txt){

   double highPrice1 = iHigh("EURUSD", PERIOD_CURRENT, 1); 
   double highPrice2 = iHigh("EURUSD", PERIOD_CURRENT, 2);
   double lowPrice1 = iLow("EURUSD", PERIOD_CURRENT, 1);
   double lowPrice2 = iLow("EURUSD", PERIOD_CURRENT, 2);
   double HighestHigh = MathMax(highPrice1, highPrice2);
   double LowestLow = MathMin(lowPrice1, lowPrice2);
   

   string objName = "";
   StringConcatenate(objName, "Signal@", " ", time, " ", "at", " ", DoubleToString(price, _Digits), "(", arrowcode,")");
   if(ObjectCreate(0, objName, OBJ_ARROW, 0, time, price)){
      ObjectSetInteger(0, objName, OBJPROP_ARROWCODE, arrowcode);
      ObjectSetInteger(0, objName, OBJPROP_COLOR, clr);
      ObjectSetInteger(0, objName, OBJPROP_COLOR, clr);
      if(direction > 0) ObjectSetInteger(0, objName, OBJPROP_ANCHOR, ANCHOR_BOTTOM);
      if(direction < 0) ObjectSetInteger(0, objName, OBJPROP_ANCHOR, ANCHOR_TOP);      
   }

string objectNameDesc = objName+txt;
   if(ObjectCreate(0, objectNameDesc, OBJ_TEXT, 0, time, price)){
      ObjectSetString(0, objectNameDesc, OBJPROP_TEXT, " "+txt);
      ObjectSetInteger(0, objectNameDesc, OBJPROP_COLOR, clr);
      if(direction > 0) ObjectSetInteger(0, objectNameDesc, OBJPROP_ANCHOR, ANCHOR_BOTTOM);
      if(direction < 0) ObjectSetInteger(0, objectNameDesc, OBJPROP_ANCHOR, ANCHOR_TOP);
    }
}