Help me convert this pinescript indicator to mql5 please!

 
var bool gbroken=false
var bool rbroken=false



//-----------------------------------[MARKET STRUCTURE INDICATOR]-----------------------------------{ 
//---------------------------
//market breaking indicator 
//
//-----------------------------------------------------------------------------
//Settings
//-----------------------------------------------------------------------------{
length = input.int(5, 'Swings Period', minval = 2,group = 'Market Structure Settings')
breaks = input.int(1, 'Maximum Breaks', minval = 1,group = 'Market Structure Settings')
maxDuration = input(1000, 'Breaker Maximum Duration',group = 'Market Structure Settings')

//Style
bullCss = input(#089981, 'Bullish MS', inline = 'bull', group = 'Market Structure Settings')
bullBreakCss = input(#f23645, 'Breaker', inline = 'bull', group = 'Market Structure Settings')

bearCss = input(#f23645, 'Bearish MS', inline = 'bear', group = 'Market Structure Settings')
bearBreakCss = input(#089981, 'Breaker', inline = 'bear', group = 'Market Structure Settings')

//-----------------------------------------------------------------------------}
//UDT { /// MSS MSB 
//-----------------------------------------------------------------------------{
type breaker
    line level
    int  breaks = 0

//-----------------------------------------------------------------------------}
//Bullish Breaker
//-----------------------------------------------------------------------------{
var phx = 0  
var phcross = false
var bullms = array.new<breaker>(0)
var os = 0

n = bar_index
ph = fixnan(ta.pivothigh(length, length))

if ph != ph[1]
    phx := n-length
    phcross := false

//Test for bullish market structure
if close > ph and not phcross
    line.new(phx, ph, n, ph, color = bullCss)
    gbroken:=true
    //MS label
    label.new(int(math.avg(phx, n)), ph, os == -1 ? 'MSS' : 'MSB'
      , textcolor = bullCss
      , color = color(na)
      , size = size.small
      , style = label.style_label_down)

    bullms.unshift(breaker.new(line.new(n, ph, n, ph, color = bullBreakCss, style = line.style_dotted)))
    phcross := true

    if bullms.size() > 100
        bullms.pop()
    
    os := 1

//Iterate trough existing bullish structures and test for breaks
break_down = false

if bullms.size() > 0
    for i = bullms.size()-1 to 0
        get = bullms.get(i)
        get.level.set_x2(n)
        
        if close < get.level.get_y2() and open > get.level.get_y2()
            get.breaks += 1

            if get.breaks == breaks
                bullms.remove(i)
                break_down := true

        else if (n - get.level.get_x1()) >= maxDuration
            bullms.remove(i).level.delete()

//Support events
support = false
if bullms.size() > 0
    lvl = bullms.get(0).level.get_y2()

    support := low < lvl and math.min(close, open) > lvl

and this what i did:

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[])
  {
//-----------------------------------------------------------------------------{
   if(bars==time[rates_total-2])return rates_total;
   bars=time[rates_total-2];
   
   ArraySetAsSeries(close,true);
   ArraySetAsSeries(open,true);
   ArraySetAsSeries(high,true);
   ArraySetAsSeries(low,true);

   
   array bullms[100];
   for(int i=0;i<100;i++)
      bullms[i].x1=0;
   int done=false;
   int os = 0;
   double ph[];
   ArrayResize(ph,rates_total);
   double pl[];
   ArrayResize(pl,rates_total);
   int phx = 0;
   int plx = 0;  
   bool phcross = false;
   bool plcross = false;


   array bearms[100];
   for(int i=0;i<100;i++)
      bearms[i].x1=0;


   for(int i=rates_total-2;i>=0;i--)
   {
      bool rbroken=false;
      int n = i;
      ph[i] = pivothigh(length, length, i);
      
      if(ph[i] != ph[i+1])
      {
          phx = n+length;
          phcross = false;
      }

      //Test for bullish market structure
      if(close[i] > ph[i] && !phcross)
      {
          line(phx, ph[i], n, ph[i], bullCss);
          bool gbroken=true;
      
          label((phx+ n)/2, ph[i], os == -1 ? "MSS" : "MSB",  bullCss);
      
          //line(n, ph[i], 0, ph[i], bullBreakCss);
          for(int l=99;l>=1;l--)
            bullms[l]=bullms[l-1];
          bullms[0].x1=n;
          bullms[0].y1=ph[i];
          bullms[0].x2=n;
          bullms[0].y2=ph[i];
          bullms[0].breaks=0;
          phcross = true;
          done=true;
          os = 1;
      }
      //Iterate trough existing bullish structures and test for breaks
      bool break_down = false;
      
      if(bullms[0].x1!=0)
      {
          for(int j = 99; j>=0; j--)
          {
              array get = bullms[j];
              if(!get.x1)continue;
              get.x2=n;
              
              if(close[i] < get.y2 && open[i] > get.y2)
              {
                  get.breaks += 1;
      
                  if(get.breaks == breaks)
                  {
                      for(int l=i;l<99;l++)
                        bullms[l]=bullms[l+1];
                      bullms[99].x1=0;
                      break_down = true;
                  }
      
              }
              else if(n - get.x1 >= maxDuration)
              {
                  bullms[i].x1=0;
                  bullms[i].y1=0;
                  bullms[i].x2=0;
                  bullms[i].y2=0;
              }
          }
      }
      //Support events
      bool support = false;
      if(bullms[0].x1!=0)
      {
          double lvl = bullms[0].y2;
      
          support = low[i] < lvl && MathMin(close[i], open[i]) > lvl;
      }
  }
return rates_total;
}
double pivotlow(int period1, int period2, int i)
{
   if(i<period2)return 0;
   int pos=iLowest(_Symbol,PERIOD_CURRENT,MODE_LOW,period1,i+1);
   return iLow(_Symbol,PERIOD_CURRENT,pos);
}
double pivothigh(int period1, int period2, int i)
{
   if(i<period2)return 0;//Print(i);
   int pos=iHighest(_Symbol,PERIOD_CURRENT,MODE_HIGH,period1+period2+1,i-period2);//Print(pos);
   return iHigh(_Symbol,PERIOD_CURRENT,pos);
}
string prefix="MSI-";
int count=0;
void line(int x1, double y1, int x2, double y2, color couleur)
{
   string name=prefix+IntegerToString(x1);
   if(ObjectFind(0,name)<0)
      ObjectCreate(0,name,OBJ_TREND,0,0,0);
      
   ObjectSetDouble(0,name,OBJPROP_PRICE,0,y1);
   ObjectSetDouble(0,name,OBJPROP_PRICE,1,y2);
   ObjectSetInteger(0,name,OBJPROP_TIME,0,iTime(_Symbol,PERIOD_CURRENT,x1));
   ObjectSetInteger(0,name,OBJPROP_TIME,1,iTime(_Symbol,PERIOD_CURRENT,x2));
   ObjectSetInteger(0,name,OBJPROP_RAY,false);
   ObjectSetInteger(0,name,OBJPROP_COLOR,couleur);
   
   ChartRedraw();
}
void label(int x, double y, string text, color couleur)
{
   string name=prefix+IntegerToString(x);
   if(ObjectFind(0,name)<0)
      ObjectCreate(0,name,OBJ_LABEL,0,0,0);
      
   ObjectSetDouble(0,name,OBJPROP_PRICE,y);
   ObjectSetInteger(0,name,OBJPROP_TIME,iTime(_Symbol,PERIOD_CURRENT,x));
   ObjectSetInteger(0,name,OBJPROP_COLOR,couleur);
   ObjectSetInteger(0,name,OBJPROP_FONTSIZE,10);
   ObjectSetString(0,name,OBJPROP_TEXT,text);
   
   ChartRedraw();
}