Can somebody help

 
Hello. I have a code of Auto Regression Channel in MQL2. Can somebody convert it to MQ4 please. I will be very grateful. Especially you Slawa. The code in MQL2 is;


/*[[
Name := Auto Regression channel
Author := Copyright © 2004, FostarFX
Link := fostar_fx@yahoo.com
Separate Window := No
First Color := silver
First Draw Type := line
First Symbol := 217
Use Second Data := no
Second Color := silver
Second Draw Type := Symbol
Second Symbol := 218
]]*/
Inputs : NumberName(1), iPeriod(21), MAShoot(50), DrawVertical(0), DrawText(0), ShowMA(0), LineWeight(1), BarsCount(1000);

Var : shift(0), n_begin(0), n_end(0), n(0), a_(0), b_(0), a1(0), a2(0), a3(0), b1(0);
var : y1(0), y2(0), price(0), BarBegin(100), BarEnd(1);
var : tmp_div_high(0), tmp_div_low(0), stddiv_low(0), stddiv_high(0), tmp_div(0);
var : x_n_up(0), x_n_down(0), x_1_up(0), x_1_down(0);
var : check_upper_chanel(false), color_1(0), color_2(0), name(""), angle(0), ratio(0), ratio_currency(0);
Var : MA(0), value(0), Bars_(170), check_low(false), check_high(false);
Var : save_low(0), save_high(0), save_shift_low(0), save_shift_high(0), save_shift(0);
Var : MAType(0), MAPrice(0);

SetLoopCount(0);
comment("Auto Regression channel");

if BarsCount < 1 then Bars_ = Bars
else Bars_ = BarsCount;

save_low = -1;
save_high = -1;
save_shift_low = -1;
save_shift_high = -1;

check_low = false;
check_high = false;

MAType = MODE_SMA;
MAPrice = PRICE_CLOSE;

if Close[1] > 80 then ratio_currency = 100
else ratio_currency = 10000;

For shift = Bars_-1 Downto 0 Begin
MA = iMAEx(iPeriod, MAType, 0, MAPrice, shift);

if ShowMA then SetIndexValue(shift, MA);

if MA - MAShoot/ratio_currency > Close[shift] then
{

if Close[Shift] < save_low or save_low = -1 then
{
check_low = true;

save_low = close[Shift];
save_shift_low = shift;
};
};

if MA + MAShoot/ratio_currency< Close[shift] then
{
if save_high < Close[Shift] or save_high = -1 then
{
check_high = true;

save_high = close[Shift];
save_shift_high = shift;
};
};

if check_low then
{
if MA + MAShoot/ratio_currency < Close[shift] then
{
check_low = false;
save_low = -1;
};
};

if check_high then
{
if MA - MAShoot/ratio_currency > Close[shift] then
{
check_high = false;
save_high = -1;
};
};

End;

if save_shift_low > save_shift_high then
{
n_begin = save_shift_low;
n_end = save_shift_high;
}
else
{
n_begin = save_shift_high;
n_end = save_shift_low;
};

if n_end = 0 then n_end = 1;
n = (n_begin - n_end + 1);

a1 = 0;
a2 = 0;
a3 = 0;
b1 = 0;
a_ = 0;
b_ = 0;
y1 = 0;
y2 = 0;
tmp_div_high = 0;
tmp_div_low = 0;
tmp_div = 0;

if close[n_begin] < close[n_end] then check_upper_chanel = true
else check_upper_chanel = false;

For shift = n_begin Downto n_end Begin
if check_upper_chanel then price = low[shift]
else price = high[shift];

a1 = a1 + shift*price;
a2 = a2 + shift;
a3 = a3 + price;
b1 = b1 + shift*shift;
End;

b_ = (n*a1 - a2*a3)/(n*b1 - a2*a2);
a_ = (a3 - b_*a2)/n;
y1 = a_ + b_*n_begin;
y2 = a_ + b_*n_end;

MoveObject( "Regression_middle" + NumberName, OBJ_TRENDLINE, Time[n_begin], y1, Time[n_end], y2, white, LineWeight, STYLE_SOLID);

For shift = n_begin Downto n_end Begin
if check_upper_chanel then price = low[shift]
else price = high[shift];

tmp_div = tmp_div + (price - (a_ + b_*shift))*(price - (a_ + b_*shift));
End;

stddiv_low = sqrt(tmp_div/n);
stddiv_high = sqrt(tmp_div/n);

x_n_up = y1 + 2*stddiv_high;
x_1_up = y2 + 2*stddiv_high;

x_n_down = y1 - 2*stddiv_low;
x_1_down = y2 - 2*stddiv_low;

if check_upper_chanel then {
color_1 = blue;
color_2 = red;
}else{
color_1 = red;
color_2 = blue;
};

//upper
MoveObject( "Regression_upper" + NumberName, OBJ_TRENDLINE, Time[n_begin], x_n_up, Time[n_end], x_1_up, color_1, LineWeight, STYLE_SOLID);
//lower
MoveObject( "Regression_lower" + NumberName, OBJ_TRENDLINE, Time[n_begin], x_n_down, Time[n_end], x_1_down, color_2, LineWeight, STYLE_SOLID);

if DrawText then
{
name = "Regression_bars_begin" + NumberName;
MoveObject(name, OBJ_TEXT, Time[n_begin], x_n_down, Time[n_begin], x_n_down, red, 1, STYLE_SOLID);
SetObjectText(name, NumberToStr(n_begin,0), "System", 10, White);

name = "Regression_bars_end" + NumberName;
MoveObject(name, OBJ_TEXT, Time[n_end], x_1_up, Time[n_end], x_1_up, red, 1, STYLE_SOLID);
SetObjectText(name, NumberToStr(n_end,0), "System", 10, White);
}else{
DelObject("Regression_bars_end" + NumberName, 0, 0, 0, 0);
DelObject("Regression_bars_begin" + NumberName, 0, 0, 0, 0);
}

if DrawVertical then
{
MoveObject( "Regressin_begin" + NumberName, OBJ_VLINE, Time[n_begin], y1, Time[n_begin], y2, silver, 1, STYLE_DOT);
MoveObject( "Regressin_end" + NumberName, OBJ_VLINE, Time[n_end], y1, Time[n_end], y2, silver, 1, STYLE_DOT);
}else{
DelObject("Regressin_begin" + NumberName, 0, 0, 0, 0);
DelObject("Regressin_end" + NumberName, 0, 0, 0, 0);
}


Thank you.
Reason: