Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 224

 
Alekseu Fedotov:

The branch is quadruped.
The branch welcomes cross-platform code to ease the transition for newcomers to fives.
 
Help write a function that returns the bar of the last MA crossing, given that there are 10 bars between the last and penultimate crossing and from the point of last crossing to the minimum there is a given number of points. for the third day I'm struggling all is not working out a file with the code attached
Files:
test.mq4  41 kb
 
Artyom Trishkin:
The branch welcomes cross-platform code to ease the transition for newcomers to Five.

Frankly, I have exhausted myself but still do not understand how to reproduce these calculations in Five:

//--- counted in the 1-st buffer
   for(i=0;i<limit;i++)
     {
      int bars=iBarShift(Symbol(),PERIOD_M1,iTime(Symbol(),PERIOD_CURRENT,i),false);
      ExtBuffer[i]=(
                    iMA(NULL,PERIOD_CURRENT,1,0,MODE_SMA,PRICE_HIGH,i)
                    +iMA(NULL,PERIOD_M1,1,1,MODE_SMA,PRICE_OPEN,bars)
                    );
      Print(bars);
     }
 
cripple:

Frankly, I struggled but still don't understand how to reproduce these calculations in Five:

I suggested a universal code

Forum on trading, automated trading systems & strategy testing

Any MQL4 beginners questions, help and discussion on algorithms and codes

Alexey Viktorov, 2017.06.02 14:27

Try

int  Bars(
   string           symbol_name,     // имя символа
   ENUM_TIMEFRAMES  timeframe,       // период
   datetime         start_time,      // с какой даты
   datetime         stop_time        // по какую дату
   );

Time the i-th bar and put the resulting bar number instead of i.


It works in both mql4 and mql5.

Bars - Доступ к таймсериям и индикаторам - Справочник MQL4
Bars - Доступ к таймсериям и индикаторам - Справочник MQL4
  • docs.mql4.com
Bars - Доступ к таймсериям и индикаторам - Справочник MQL4
 
Alexey Viktorov:

I immediately suggested a universal code


it works in mql4 and mql5.

But how in 5 to get

start_time,      // с какой даты

there

iTime()

does not work.

 
cripple:

But how do you get in a fiver

here

does not work.

CopyTime works.

But it is not needed in this case, because time of current period is in time[i], it's an indicator...

iTime(Symbol(),PERIOD_CURRENT,i) == time[i]
CopyTime - Доступ к таймсериям и индикаторам - Справочник MQL4
CopyTime - Доступ к таймсериям и индикаторам - Справочник MQL4
  • docs.mql4.com
CopyTime - Доступ к таймсериям и индикаторам - Справочник MQL4
 

Hi all. Help me with OrderProfit() function. How to make Comment display the current profit of all open orders. I get the same number.

double CalcProfit()

{

double Profit = 0;

for (int i=OrdersTotal() - 1; i>=0; i--)

{

if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))

{

if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic)

{

if (OrderType() == OP_BUY)

{

Profit += (OrderProfit() + OrderSwap() + OrderCommission())

}

}

}

}

return(Profit);

}

 
How to make the value of the profit change accordingly with each tick (price change).
 
AlGuru:

Hi all. Help me with OrderProfit() function. How to make Comment display the current profit of all open orders. I get the same number.

double CalcProfit()

{

double Profit = 0;

for (int i=OrdersTotal() - 1; i>=0; i--)

{

if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))

{

if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic)

{

if (OrderType() == OP_BUY)

{

Profit += (OrderProfit() + OrderSwap() + OrderCommission())

}

}

}

}

return(Profit);

}


That's it. Got it.
 
cripple:

But how do you get in a fiver

here

doesn't work.

for starters

https://www.mql5.com/ru/articles/81

I personally first write in 4-Rock, then I change it to 5-Rock, otherwise it's too much trouble for me, because 5-Rock code is harder to read, functions are too long in number of letters..., so it turns out the text for gum scholars, not for engineers ))))

and behold

https://www.mql5.com/ru/search#!keyword=f%20mql4%20to%20mql5

Переход с MQL4 на MQL5
Переход с MQL4 на MQL5
  • 2010.05.11
  • Sergey Pavlov
  • www.mql5.com
Данная статья, построенная в форме справочника по функциям MQL4, призвана помочь переходу с MQL4 на MQL5. Для каждой функции языка MQL4 приведено описание и представлен способ ее реализации на MQL5, что позволит вам значительно ускорить перевод своих программ с MQL4 на MQL5. Для удобства функции разбиты на группы, как в документации по MQL4.