//------------------------------------------------------------------
#property link      "https://howtofxmarkets.web.app/"
#property copyright "https://howtofxmarkets.web.app/ SingleInsideBar by csj179t"
//   - Forex education, mentorship, trading rooms.
//   - Low cost forex broker, high leverage available. With a lot of FREE additional services.
//   - And a Guide-o-FX is a list of FREE useful forex resources.
//------------------------------------------------------------------
#property copyright "www.forex-station.com"
// Many thanks to forex-station.com, to mrtools, mladen
// and other coder helping for free. Special thanks to Jimmy! 
// I got this code template at forex-station:  bars iterator, mtf feature...
// And making my indicators, by editing modifying it.

#property indicator_chart_window
#property indicator_buffers    2




extern ENUM_TIMEFRAMES    TimeFrame       = PERIOD_CURRENT;
extern color             BullCol = clrGreen;
extern color             BearCol = clrRed;
extern double gap        = 0.5;
extern int upCode        = 164; //241;
extern int dnCode        = 164; //242
extern bool               Interpolate   = true;

extern string             name = "SingleInsideBar";


double buffer1[];
double buffer2[];


string indicatorFileName;
bool   returnBars;

string name2 = name + " " + TimeFrame;



//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int init()
  {

   IndicatorBuffers(2);
   SetIndexBuffer(0,buffer1);
   SetIndexStyle(0,DRAW_ARROW,0,0,BullCol);
   SetIndexArrow(0,upCode);
 SetIndexBuffer(1,buffer2);
   SetIndexStyle(1,DRAW_ARROW,0,0,BearCol);
   SetIndexArrow(1,dnCode);


   indicatorFileName = WindowExpertName();
   returnBars        = TimeFrame==-99;
   TimeFrame         = fmax(TimeFrame,_Period);

   IndicatorShortName(name2);

   return(0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int deinit()
  {



   return(0);

  }

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int start()
  {



              
              
   int counted_bars=IndicatorCounted();
   int i,limit;


   if(counted_bars < 0)
      return(-1);
   if(counted_bars > 0)
      counted_bars--;
   limit = MathMin(Bars-counted_bars,Bars-1);
   if(returnBars)
     {
      buffer1[0] = limit+1;
      return(0);
     }


   if(TimeFrame == Period())
     {

      for(i=limit; i>=0; i--)
        {
      double atr  = iATR(NULL,0,20,i)* 0.5   ;   
 buffer1[i] = Low[i] >= Low[i+1] && High[i] <= High[i+1] && Close[i] > Open[i] && Close[i+1] < Open[i+1]?  Low[i] - gap * atr : EMPTY_VALUE;
 buffer2[i] = Low[i] >= Low[i+1] && High[i] <= High[i+1] && Close[i] < Open[i]  && Close[i+1] > Open[i+1] ? High[i] + gap * atr : EMPTY_VALUE;

 //buffer1[i] = Low[i+1] == Low[i]  && Low[i] >= Low[i+1] && High[i] <= High[i+1] && Close[i] > Open[i] && Close[i+1] < Open[i+1]?  Low[i] - gap * atr : EMPTY_VALUE;
// buffer2[i] = High[i+1] == High[i]&& Low[i] >= Low[i+1] && High[i] <= High[i+1] && Close[i] < Open[i]  && Close[i+1] > Open[i+1] ? High[i] + gap * atr : EMPTY_VALUE;


//bool DOWN  = Close[i+1]< Open[i+1] ;   
 //    bool UP    = Close[i+1]> Open[i+1] ;






 //buffer1[i] = Low[i] >= Low[i+1] && High[i] <= High[i+1] && Close[i] > Open[i] && Close[i+1] < Open[i+1] && Close[i+2] > Open[i+2] && Open[i+2] < Open[i+1]?  Low[i] - gap * atr : EMPTY_VALUE;
 //buffer2[i] = Low[i] >= Low[i+1] && High[i] <= High[i+1] && Close[i] < Open[i]  && Close[i+1] > Open[i+1]&& Close[i+2] < Open[i+2] && Open[i+2] > Open[i+1]? High[i] + gap * atr : EMPTY_VALUE;
        }

      return(0);
     }



   limit = MathMax(limit,MathMin(Bars-1,iCustom(NULL,TimeFrame,indicatorFileName,-99,0,0)*TimeFrame/Period()));
   for(i=limit; i>=0; i--)
     {
      int y = iBarShift(NULL,TimeFrame,Time[i]);

      buffer1[i] = iCustom(NULL,TimeFrame,indicatorFileName,PERIOD_CURRENT,BullCol,BearCol,gap,upCode,dnCode,0,y);
 buffer2[i] = iCustom(NULL,TimeFrame,indicatorFileName,PERIOD_CURRENT,BullCol,BearCol,gap,upCode,dnCode,1,y);
   
     
     }







   return(0);
  }



//+------------------------------------------------------------------+
