Cоветник do MQL4

 
Hello,
I found this Sovetnik in Russian forum.
Somebody can help me to translate to MQL4.
Thanks.
B

Define: P(14);
Define: Ter(1);
Var: Alfa(0);
Var: Order(0);
Var: TF(0);
Var: cnt(0);

if Bars < 20 then Exit;

for cnt=1 to TotalTrades
{
if OrderValue(cnt,VAL_SYMBOL) == Symbol then
{
Order = 1;
break;
}
else
{
Order = 0;
}
}


if TotalTrades == 0 then Order = 0;
if TotalTrades < 5 and Order == 0 then
{
if FreeMargin < 100 then Exit;
if iRSI(P,0) > iRSI(P,1) and iRSI(P,0) > Alfa then
{
Alfa = iRSI(P,0);
SetOrder(OP_SELL,Lots,Bid,2,Bid+StopLoss*Point,Ask-TakeProfit*Point,Red);
Exit;
}
if iRSI(P,0) < iRSI(P,1) and iRSI(P,0) < Alfa then
{
Alfa = iRSI(P,0);
SetOrder(OP_BUY,Lots,Ask,2,Bid-StopLoss*Point,Ask+TakeProfit*Point,Blue);
Exit;
}
}

for cnt=1 to TotalTrades
{
if OrderValue(cnt,VAL_TYPE) <= 1 and OrderValue(cnt,VAL_SYMBOL) == Symbol then
{
if OrderValue(cnt,VAL_TYPE) == 0 then
{
if iRSI(P,0) > Alfa then Alfa = iRSI(P,0);
if (Bid - OrderValue(cnt,VAL_OPENPRICE)) > 20 * Point then Ter = 1;
if (Bid - OrderValue(cnt,VAL_OPENPRICE)) > 40 * Point then Ter = 1.5;
if iRSI(P,0) < Alfa and Abs(iRSI(P,0) - Alfa) > Ter then
{
CloseOrder(OrderValue(cnt,VAL_TICKET),OrderValue(cnt,VAL_LOTS),OrderValue(cnt,VAL_CLOSEPRICE),3,Blue);
Exit;
}
if TrailingStop > 0 then
{
if Bid+OrderValue(cnt,VAL_OPENPRICE) > Point*TrailingStop then
{
if OrderValue(cnt,VAL_STOPLOSS) < Bid+Point*TrailingStop then
{
ModifyOrder(OrderValue(cnt,VAL_TICKET),OrderValue(cnt,VAL_OPENPRICE),Bid+Point*TrailingStop,OrderValue(cnt,VAL_TAKEPROFIT),Red);
Exit;
}
}
}
}
else
{
if iRSI(P,0) < Alfa then Alfa = iRSI(P,0);
if (OrderValue(cnt,VAL_OPENPRICE) + Ask) > 20 * Point then Ter = 1;
if (OrderValue(cnt,VAL_OPENPRICE) + Ask) > 40 * Point then Ter = 1.5;
if iRSI(P,0) > Alfa and Abs(iRSI(P,0) - Alfa) > Ter then
{
CloseOrder(OrderValue(cnt,VAL_TICKET),OrderValue(cnt,VAL_LOTS),OrderValue(cnt,VAL_CLOSEPRICE),3,Green);
Exit;
}
if TrailingStop > 0 then
{
if OrderValue(cnt,VAL_OPENPRICE)+Ask > Point*TrailingStop then
{
if OrderValue(cnt,VAL_STOPLOSS) == 0 or OrderValue(cnt,VAL_STOPLOSS) > Ask-Point*TrailingStop then
{
ModifyOrder(OrderValue(cnt,VAL_TICKET),OrderValue(cnt,VAL_OPENPRICE),Ask-Point*TrailingStop,OrderValue(cnt,VAL_TAKEPROFIT),Red);
Exit;
}
}
}
}
}
}