How to find a confirming pinbar inside another pinbar... Or What's the logical fallacy here?

 
Hello! :)
I have tried to make some code, and I want to find a pinbar inside another pinbar, how can I do that? I have tried this one:
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 clrRed
#property indicator_width1 2
#property indicator_color2 clrLime
#property indicator_width2 2

input int  CountBars = 0; // CountBars - number of bars to count on. Default 0 = all
input int  DisplayDistance = 5; // DisplayDistance - the higher it is the the distance from faces to candles
sinput ENUM_TIMEFRAMES smalltimeframe=PERIOD_M5;

// Indicator buffers
double Down[];
double Up[];

// Global variables
int LastBars = 0;
double MaxNoseBodySize = 0.5;
double NoseBodyPosition = 0.5;
double LeftEyeDepth = 0.2;

int init()
{
//---- indicator buffers mapping  
   SetIndexBuffer(1, Down);

//---- drawing settings
   SetIndexStyle(1, DRAW_ARROW);
   SetIndexArrow(1, 234); // DOWN ARROW symbol
   SetIndexEmptyValue(1, EMPTY_VALUE);

//---- indicator labels
   SetIndexLabel(1, "Bearish Pinbar");

   return(0);
}

//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
{
   int NeedBarsCounted, ii;
   double NoseLength,  NoseBody,  LeftEyeBody,  LeftEyeLength;
   double iNoseLength, iNoseBody, iLeftEyeBody, iLeftEyeLength;
   int MoveNumber = PERIOD_CURRENT/smalltimeframe;
   if (LastBars == Bars) return(0);
   NeedBarsCounted = Bars - LastBars;
   if ((CountBars > 0) && (NeedBarsCounted > CountBars)) NeedBarsCounted = CountBars;
   LastBars = Bars;
   if (NeedBarsCounted == Bars) NeedBarsCounted--;

   for (int i = NeedBarsCounted; i >= 1; i--)
   {
      // Won't have Left Eye for the left-most bar
      if (i == Bars - 1) continue;

      // Left Eye and Nose bars' paramaters
      NoseLength = High[i] - Low[i];
      if (NoseLength == 0) NoseLength = Point;
      LeftEyeLength = High[i + 1] - Low[i + 1];
      if (LeftEyeLength == 0) LeftEyeLength = Point;
      NoseBody = MathAbs(Open[i] - Close[i]);
      if (NoseBody == 0) NoseBody = Point;
      LeftEyeBody = MathAbs(Open[i + 1] - Close[i + 1]);
      if (LeftEyeBody == 0) LeftEyeBody = Point;

      // Bearish Pinbar
      if (NoseBody / NoseLength <= MaxNoseBodySize)
      {
         if (1 - (High[i] - MathMax(Open[i], Close[i])) / NoseLength < NoseBodyPosition)
         {
            if ((MathMax(Open[i], Close[i]) <= High[i + 1]) && (MathMin(Open[i], Close[i]) >= Low[i + 1]))
            {
               if (Low[i] - Low[i + 1] >= LeftEyeLength * LeftEyeDepth)
               {
                  for(ii=i*MoveNumber;ii<=i*MoveNumber+MoveNumber;ii++)
                  {
                     // insideBarCheck. In insideBarCheck we don't check the left eye bar
                     iNoseLength = iHigh(Symbol(), smalltimeframe, ii) - iLow(Symbol(), smalltimeframe, ii);
                     if (iNoseLength == 0) iNoseLength = Point;
                     iNoseBody = MathAbs(iOpen(Symbol(), smalltimeframe, ii) - iClose(Symbol(), smalltimeframe, ii));
                     if (iNoseBody == 0) iNoseBody = Point;                     
                     if (iNoseBody / iNoseLength <= MaxNoseBodySize)
                     {
                        if (1 - (iHigh(Symbol(), smalltimeframe, ii) - MathMax(iOpen(Symbol(), smalltimeframe, ii), iClose(Symbol(), smalltimeframe, ii))) / iNoseLength < NoseBodyPosition)
                        {
                           if ((MathMax(iOpen(Symbol(), smalltimeframe, ii), iClose(Symbol(), smalltimeframe, ii)) <= iHigh(Symbol(), smalltimeframe, ii + 1)) && (MathMin(iOpen(Symbol(), smalltimeframe, ii), iClose(Symbol(), smalltimeframe, ii)) >= iLow(Symbol(), smalltimeframe, ii + 1)))
                           {
                                                                Down[i] = High[i] + DisplayDistance * Point + NoseLength / 5;
                           }
                        }
                     }
                  }
               }
            }
         }
       }
   }
   return(0);
}


From this code, how can I find a confirming pinbar(PERIOD_M5) inside a big pinbar(PERIOD_M15)? What should I rewrite in this piece of code?


for(ii=i*MoveNumber;ii<=i*MoveNumber+MoveNumber;ii++)
{
   // insideBarCheck. In insideBarCheck we don't check the left eye bar
   iNoseLength = iHigh(Symbol(), smalltimeframe, ii) - iLow(Symbol(), smalltimeframe, ii);
   if (iNoseLength == 0) iNoseLength = Point;
   iNoseBody = MathAbs(iOpen(Symbol(), smalltimeframe, ii) - iClose(Symbol(), smalltimeframe, ii));
   if (iNoseBody == 0) iNoseBody = Point;                     
   if (iNoseBody / iNoseLength <= MaxNoseBodySize)
   {
      if (1 - (iHigh(Symbol(), smalltimeframe, ii) - MathMax(iOpen(Symbol(), smalltimeframe, ii), iClose(Symbol(), smalltimeframe, ii))) / iNoseLength < NoseBodyPosition)
      {
         if ((MathMax(iOpen(Symbol(), smalltimeframe, ii), iClose(Symbol(), smalltimeframe, ii)) <= iHigh(Symbol(), smalltimeframe, ii + 1)) && (MathMin(iOpen(Symbol(), smalltimeframe, ii), iClose(Symbol(), smalltimeframe, ii)) >= iLow(Symbol(), smalltimeframe, ii + 1)))
         {
            Down[i] = High[i] + DisplayDistance * Point + NoseLength / 5; // Draw an ARROW
         }
      }
   }
}
 
I didn't read the whole code but it's probably better to work on a single timeframe, M5 here, and collate the last 3 bars to check for the bigger pinbar. Just an idea.
 
lippmaje:
I didn't read the whole code but it's probably better to work on a single timeframe, M5 here, and collate the last 3 bars to check for the bigger pinbar. Just an idea.
Ow, yeah) That's a point!) Thanks for your answer ^^