Trying to understand renko chart

 
//+------------------------------------------------------------------+
//|                                                  tester rect.mq4 |
//|                        Copyright 2018, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2018, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict

bool chk;                                    // temporary boolean
string sy = Symbol();                        // Symbol
string pre = "rect";                         // prefix to rename displayed renko box
int pd = Period();                           // Period
int raxi = 0, taxi = 0;                      // rank max index and temp
int raxv = 0, taxv = 0;                      // rank max value and temp
int rini = 0, tini = 0;                      // rank min index and temp
int rinv = 0, tinv = 0;                      // rank min value and temp
int br = 50;                                 // stored renko bars 
int pr = 10;                                 // calculated renko box in pip 
datetime stobar;                             // place to store bar
datetime t1, t2;                             // time for renko box
double d1, d2;                               // displayed price point renko box
double c1, c2;                               // calculated price point renko box
double wpa, wpi;                             // to store window max and min price
double ran;                                  // range of window max-min
double base=SymbolInfoDouble(sy,SYMBOL_BID); // for display
double pt=SymbolInfoDouble(sy,SYMBOL_POINT); // point
double pi = 20 * pt;                         // displayed renko box in price unit
double bs;                                   // calculated renko box in price 
double rl;                                   // lowest point to cross in price unit
double rh;                                   // highest point to cross in price unit
color cllo = clrRed;                         // color to display lower renko
color clup = clrBlue;                        // color to display upper renko

double ren[][3];                             // array to store renko box 
//                                           // (x,0) calculated lower price point, 
//                                           // (x,1) calculated higher price point, 
//                                           // (x,2) color compared to prev 0 lo 1 hi
int rek[];                                   // store renko box rank
bool renbo = ArrayResize(ren,br);            // resize renko points array to stored amount
bool rekbo = ArrayResize(rek,br);            // resize renko rank array to stored amount

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
{
//---
  ran = WindowPriceMax() - WindowPriceMin(); // range window max - min
  pi = ran/br;                               // pip to display in price unit
  bs = pr * pt;                              // box size to calculate renko
  for(int i = br; i > 0; i--)                // looping through amount of renko
  {                                          // from 50 - 1
    t1 = iTime(NULL,0,i-1);                  // time 1 is i - 1
    d1 = 0;                                  // init price 1 to display is 0
    c1 = base - 0.5*bs;                      // init price 1 to store is bid - .5 boxsize
    t2 = iTime(NULL,0,i);                    // time 2 is i
    d2 = 0;                                  // init price 2 to display is 0
    c2 = base + 0.5*bs;                      // init price 2 to store is bid + .5 boxsize
    string x = pre+(string)i;                // naming renko box
    ENUM_OBJECT y = OBJ_RECTANGLE;           // what to create
    if(ObjectCreate(0,x,y,0,t1,d1,t2,d2))    // creating object
    {                                        // and if succeed
      ObjectSetInteger(0,x,6,clrRed);        // setting OBJPROP_COLOR
      ObjectSetInteger(0,x,7,STYLE_DASH);    // setting OBJPROP_STYLE
      ObjectSetInteger(0,x,8,1);             // setting OBJPROP_WIDTH
      ObjectSetInteger(0,x,9,true);          // setting OBJPROP_BACK
      ren[i-1,0] = c1;                       // storing lower price point
      ren[i-1,1] = c2;                       // storing upper price point
      ren[i-1,2] = 0;                        // storing color setting
      rek[i-1] = 0;                          // storing rank
    }                                        // 
  }                                          // 
//---
 return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//---
  bool del;
  for(int i = br; i > 0; i--)                // looping through amount of renko
  {                                          // 
    del = ObjectDelete(0,pre+(string)i);     // deleting all renko box
  }                                          // 
}
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
{
//--- general initialization variable -----------------------------------------
  bool chl = true;                           // initial bool for lower block
  bool chh = true;                           // initial bool for upper block
  int y = 0, w = br - 1;                     // temp var
//--- calculating current time ------------------------------------------------
  long l;                                    // temp long variable
  ENUM_SERIES_INFO_INTEGER sld;              // temp sld variable
  sld = SERIES_LASTBAR_DATE;                 // temp enum variable
  l=SeriesInfoInteger(sy,pd,sld);            // searching last bar time
  datetime btime = (datetime)l;              // convert into datetime
//--- comparing current tick price point with current renko box ---------------
  double da = Bid;                           // current tick
  bs = pr * pt;                              // renko boxsize calc
  rl = ren[0,0] - bs;                        // renko low pr to comp
  rh = ren[0,1] + bs;                        // renko hi pr to comp
  if(da > rl) chl = false;                   // if bid <= rl, new lower block
  if(da < rh) chh = false;                   // if bid >= rh, new upper block
//--- general variable if creating new renko box or bar or max - min ----------
  chk = false;                               // initial bool
  if(chl || chh)              chk = true;    // if there is new renko box
  if(stobar != btime)         chk = true;    // if there is a new bar
  if(wpa != WindowPriceMax()) chk = true;    // if window max price change
  if(wpi != WindowPriceMin()) chk = true;    // if window min price change
  if(chk) wpa = WindowPriceMax();            // temp max
  if(chk) wpi = WindowPriceMin();            // temp win
  if(chk) ran = wpa - wpi;                   // range window max - min
  if(chk) base = wpi + (ran / 2);            // middle price point for renko box
  if(chk) pi = ran / br;                     // pip to display in price unit
  if(chk) raxi = ArrayMaximum(rek);          // rank max index
  if(chk) rini = ArrayMinimum(rek);          // rank min index
  if(chk) raxv = rek[raxi];                  // rank max value
  if(chk) rinv = rek[rini];                  // rank min value
  if(chk) mvrk();                            // move renko to the recent bar
  if(chk && raxi == w) y=ArrayMaximum(rek,w);// rank max index excluding last
  if(chk && raxi == w) taxi=y;               // rank max index excluding last
  if(chk && raxi == w) taxv=rek[taxi];       // rank max value excluding last
  if(chk && rini == w) y=ArrayMinimum(rek,w);// rank max index excluding last
  if(chk && rini == w) tini=y;               // rank max index excluding last
  if(chk && rini == w) tinv=rek[tini];       // rank max value excluding last
//--- calculating new lower renko bar -----------------------------------------
  if(chl) if(rini == 0)    rinv -= 1;        // if min index is 0, subs 1 from value
  if(chl) if(raxi == w)    raxv = taxv;      // if max index is 49, change raxv
  if(chl) c1 = rl;                           // lower calculated price point
  if(chl) c2 = rl + bs;                      // upper calculated price point
  if(chl) nwrk(-1);                          // create new lower renko bar
//--- calculating new upper renko bar -----------------------------------------
  if(chh) if(raxi == 0)    raxv += 1;        // if max index is 0, add 1 to value
  if(chh) if(rini == w)    rinv = tinv;      // if max index is 49, change rinv
  if(chh) c1 = rh - bs;                      // lower calculated price point
  if(chh) c2 = rh;                           // upper calculated price point
  if(chh) nwrk(1);                           // create new upper renko bar
//--- store current bar time --------------------------------------------------
  stobar = btime;                            // 
}
//+------------------------------------------------------------------+

void nwrk(int ranker)                        // creating new renko box
{                                            // 
  int z;                                     // temp anchor rank
  z = (int)floor((raxv + rinv)/2);           // calculate middle box rank for 0
  for(int i = br; i > 0; i--)                // looping through stored renko box
  {                                          // from br - 1
    t1 = iTime(NULL,0,i-1);                  // time 1
    t2 = iTime(NULL,0,i);                    // time 2
    if(i == 1) ren[0,0] = c1;                // lower point renko ind 0
    if(i == 1) ren[0,1] = c2;                // upper point renko ind 0
    if(i == 1) ren[0,2] = 0;                 // default value color
    if(i == 1) if(ranker == 1) ren[0,2] = 1; // upper color change
    if(i == 1) rek[0] = rek[0] + ranker;     // change rank on ind 0
    if(i != 1) ren[i-1,0] = ren[i-2,0];      // copying upper to previous
    if(i != 1) ren[i-1,1] = ren[i-2,1];      // copying lower to previous
    if(i != 1) ren[i-1,2] = ren[i-2,2];      // copying color to previous
    if(i != 1) rek[i-1] = rek[i-2];          // copying rank to previous
    d1 = base + ((rek[i-1]-z) - 0.5) * pi;   // renko box lower price point
    d2 = base + ((rek[i-1]-z) + 0.5) * pi;   // renko box upper price point
    ObjectMove(0,"rect"+(string)i,0,t1,d1);  // move 1st rectangle point
    ObjectMove(0,"rect"+(string)i,1,t2,d2);  // move 2nd rectangle point
    color x = cllo;                          // default color value
    if(ren[i-1,2] == 1) x = clup;            // upper color change
    ObjectSet("rect"+(string)i,6,x);         // setting renko box color
  }
}

void mvrk()                                  // move renko box to current bar
{                                            // or new max - min window price
  int z;                                     // temp anchor rank
  z = (int)floor((raxv + rinv)/2);           // calculate middle box rank for 0
  for(int i = br; i > 0; i--)                // looping through stored renko box
  {                                          // from br - 1
    t1 = iTime(NULL,0,i-1);                  // time 1
    t2 = iTime(NULL,0,i);                    // time 2
    d1 = base + ((rek[i-1]-z) - 0.5) * pi;   // lower display price point
    d2 = base + ((rek[i-1]-z) + 0.5) * pi;   // upper display price point
    ObjectMove(0,"rect"+(string)i,0,t1,d1);  // move 1st rectangle point
    ObjectMove(0,"rect"+(string)i,1,t2,d2);  // move 2nd rectangle point
  }
}

This is my EA according to my current understanding of renko bar. I'm using fixed box size of 10 pip.

Is my understanding correct? Any input would be appreciated, Thank you in advance :)