#property indicator_chart_window #property indicator_buffers 2 #property indicator_color1 clrAquamarine #property indicator_color2 clrAqua #property indicator_width1 10 #property indicator_width2 10 double bodyHigh[]; double bodyLow[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- SetIndexBuffer(0,bodyHigh); SetIndexBuffer(1,bodyLow); SetIndexStyle(0,DRAW_HISTOGRAM); SetIndexStyle(1,DRAW_HISTOGRAM); //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ bool upEngulfing(){ // Second Candle double bodyBottomOne = MathMin(Open[1], Close[1]); double bodyUpOne = MathMax(Open[1], Close[1]); double bodyOne = bodyUpOne - bodyBottomOne; double lowerWickOne = bodyBottomOne - Low[1]; double upperWickOne = High[1] - bodyUpOne; //First candle double bodyBottomTwo = MathMin(Open[2], Close[2]); double bodyUpTwo = MathMax(Open[2], Close[2]); double bodyTwo = bodyUpTwo - bodyBottomTwo; double lowerWickTwo = bodyBottomTwo - Low[2]; double upperWickTwo = High[2] - bodyUpTwo; bool conditionOne = bodyUpOne >= bodyUpTwo && bodyBottomOne <= bodyBottomTwo; bool conditionTwo = lowerWickOne - lowerWickTwo > 0; bool conditionThree = upperWickOne <= 0.10*lowerWickOne; bool conditionFour = bodyUpOne > upperWickTwo; bool isUpEngulfing = conditionOne && conditionTwo && conditionThree && conditionFour; return isUpEngulfing; } 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[]) { //--- for(int i = Bars-2; i>=0; i--){ double bodyHh = MathMax(Close[i],Open[i]); double bodyLw = MathMin(Close[i],Open[i]); if(upEngulfing()==True){ bodyHigh[i] = bodyHh; bodyLow[i] = bodyLw; } } //--- return value of prev_calculated for next call return(rates_total); } //+------------------------------------------------------------------+