Coding Candle Body Smaller than Previous in MQL4

 
Hi Everyone, 

I wonder if I could ask for some guidance please?

I'm trying to build an indicator which relies on identifying pin bars (shooting stars and hammers). 

Part of my coded definition of a pin bar is that its body[0]

should be smaller than the previous candle[-1]. The issue is that its seems to be comparing the candle [0] to the candle in front of it[+1], not behind it. 

Any assistance you could give would be greatly appreciated.

(code attached and a screenshot of chart)

Thanks. 


//+------------------------------------------------------------------+
//|                                                   IN_DEBUG_1.mq4 |
//|                                   Copyright 2021, Chris Bakowski |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2021, Chris Bakowski"
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#include <CustomFunctions.mqh>
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_plots   2
//--- plot Red_Arrow
#property indicator_label1  "Red_Arrow"
#property indicator_type1   DRAW_ARROW
#property indicator_color1  clrRed
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
//--- plot Green_Arrow
#property indicator_label2  "Green_Arrow"
#property indicator_type2   DRAW_ARROW
#property indicator_color2  clrGreen
#property indicator_style2  STYLE_SOLID
#property indicator_width2  1
//--- indicator buffers
double         Red_ArrowBuffer[];
double         Green_ArrowBuffer[];
#define UpArrow   241
#define DownArrow 242
#define Arrowshift 20
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,Red_ArrowBuffer);
   SetIndexLabel(0,"Red Arrow");
   SetIndexArrow(0,DownArrow);
   
   SetIndexBuffer(1,Green_ArrowBuffer);
   SetIndexLabel(1,"Green Arrow");
   SetIndexArrow(1,UpArrow);
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
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[])
   {
   double   Price_Shift = Pixels_To_Price(Arrowshift);
   int uncalculated_bars = rates_total - prev_calculated;

//For Loop------------------------------------------------------------------------------------

   for(int i=uncalculated_bars-1; i>=0; i--)
     {

//DEBUG------------------------------------------------------------------------------------


bool   bodySmaller = (MathAbs(Close[i] - Open[i])) < (MathAbs(Close[i-1] - Open[i-1]));
SetIndexLabel(bodySmaller,"bodySmaller");


/*if (Close[i] > Open[i])*/
if(bodySmaller==true)
{
Red_ArrowBuffer[i] = High[i] + Price_Shift;
}
 
   
   
   //Close For Loop -------------------------------------------------------------------------------------------
     }
//--- return value of prev_calculated for next call
   return(rates_total);
  }
Reason: