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

 

Good afternoon.

Broke my brain as to why the following algorithm doesn't work. It does not pass an array into the function. At first I was searching for the reason, but I managed to locate it in this test example.

Reports: "Cannot find 'functest' in 'TestLib.ex4' " then "unresolved import function call."

Contents of the Test.mq4 file

#property strict
#include <TestLibx.mqh>

int mass [5];

int OnInit() { return(INIT_SUCCEEDED); }
void OnDeinit(const int reason) { }

void OnTick()
{
(mass);
int c=0;
for (c=0;c<5;c++) Print (" mass[",c,"]=",mass[c]," ");
Sleep(2000);
}

Contents of the TestLibx.mq4 library file

#property library
#property strict
void functest (int &massx[])
{
int c=0;
while (c<5)
{
massx[c]=MathRand();
c++;
}
return;
}
Contents of the TestLibx.mqh library file

#property strict
#import "TestLibx.ex4"
void functest (int &massx[]);
#import

Attach the original files to the archive.

Please help me to understand how to pass arrays in MQL4 to the library function.

Thank you.

Открой новые возможности в MetaTrader 5 с сообществом и сервисами MQL5
Открой новые возможности в MetaTrader 5 с сообществом и сервисами MQL5
  • www.mql5.com
Задавайте вопросы по техническому анализу, обсуждайте торговые системы и улучшайте свои навыки программирования торговых стратегий на языке MQL5. Общайтесь и обменивайтесь опытом на форуме с трейдерами всего мира и помогайте ответами новичкам — наше сообщество развивается вместе с вами. Дифференциальный индикатор Султонова Уважаемые...
Files:
MQL4.zip  11 kb
 
Alexey Viktorov:
The difference in values is greater than 10*Point, but we need to consider whether the difference will be positive or negative.

Thank you. I want to transfer to swap points and commission. What is wrong with that?

double OrderSwap_Commission(int mn=-1)
  {
   int i=0;
   double sum=0,lots=0;
   double pips=0;//своп, комисся в пунктах
   for(i=0; i<OrdersTotal(); i++)
     {
      if(!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) continue;
      if(OrderSymbol()!=Symbol()) continue;
      if(OrderMagicNumber()!=mn) continue;
      if(OrderType()==OP_SELL || OrderType()==OP_BUY)
        {
         lots=lots+OrderLots();
         sum=sum+OrderSwap()+OrderCommission();
        }
     }
   if(lots!=0)
     {
      pips=NormalizeDouble(MathAbs((sum)/(SymbolInfoDouble(_Symbol,SYMBOL_TRADE_TICK_VALUE)/lots))*_Point,_Digits);
      pips=(MathRound(pips*MathPow(10,Digits)))/MathPow(10,Digits);
     }
   return(pips);
  }
//
 
bij:

Thank you. I want to transfer to swap points and commission. What's wrong?

int  pipsProfitOrder = (int)MathFloor( ( OrderProfit() + OrderSwap() + OrderCommission() ) / (SymbolInfoDouble(_Symbol,SYMBOL_TRADE_TICK_VALUE)*OrderLots()) );
 
Konstantin Nikitin:

Thank you.

Op, you changed your answer, I don't need to know the profit. Swap and commission, there can be more than one position.

 
bij:

Thank you.

Op, something you changed your answer to, I don't need to know the profit. Swap and commission.

It's just that you have dividing by lot and you need to multiply.

SymbolInfoDouble(_Symbol,SYMBOL_TRADE_TICK_VALUE)*OrderLots()

The principle itself showed what I use. And applying it to your code is quite simple.

 
Konstantin Nikitin:

It's just that you have division by lot and you need to multiply.

The principle itself showed what I use. And applying it to your code is pretty easy.

I see, thank you.
 

Hello!

Question: The indicator creates graphical objects(OBJ_ARROW), but some of them appear only after compilation or change of timeframe. There are no errors or warnings during compilation. In the tester, Print("Error calling ObjectCreate():",GetLastError());0, Print("Error calling ObjectCreate():",GetLastError());4200.

If you don't mind answering to a dummie!

 
How can the tester programmatically load quotes from a different (smaller) timeframe?
 
Juer:
How can the tester programmatically load quotes for a different (smaller) timeframe?
The high timeframe is based on the data of the low one. So, it is not necessary.
 
bij:
Close the position if the current time = opening time plus 5 minutes or at the opening of a new bar if the chart period is M5.

Thank you. It got better. But now there's another problem. The tester keeps giving me 100% results. But it doesn't work like that. Many trades are opened and normally closed after the specified time according to the log. However, not all deals are profitable according to the results chart where we can see the moments of opening and closing of positions. What can be the reason for such a left 100%?

Thanks to Artem too!